// SuperTux
-// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include <assert.h>
#include "control/input_manager.hpp"
+#include "gui/dialog.hpp"
#include "gui/menu.hpp"
#include "gui/mousecursor.hpp"
#include "math/sizef.hpp"
#include "supertux/globals.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/timer.hpp"
+#include "util/gettext.hpp"
#include "util/log.hpp"
#include "video/drawing_context.hpp"
};
MenuManager::MenuManager() :
+ m_dialog(),
+ m_has_next_dialog(false),
+ m_next_dialog(),
m_menu_stack(),
m_transition(new MenuTransition)
{
void
MenuManager::process_input()
{
- if (current())
+ if (m_dialog)
{
- current()->process_input();
+ m_dialog->process_input(*InputManager::current()->get_controller());
+ }
+ else if (current_menu())
+ {
+ current_menu()->process_input();
}
}
void
-MenuManager::event(const SDL_Event& event)
+MenuManager::event(const SDL_Event& ev)
{
- if (current() && !m_transition->is_active())
+ if (!m_transition->is_active())
{
- // only pass events when the menu is fully visible and not in a
- // transition animation
- current()->event(event);
+ if (m_dialog)
+ {
+ m_dialog->event(ev);
+ }
+ else if (current_menu())
+ {
+ // only pass events when the menu is fully visible and not in a
+ // transition animation
+ current_menu()->event(ev);
+ }
}
}
void
MenuManager::draw(DrawingContext& context)
{
+ if (m_has_next_dialog)
+ {
+ m_dialog = std::move(m_next_dialog);
+ m_has_next_dialog = false;
+ }
+
if (m_transition->is_active())
{
m_transition->update();
m_transition->draw(context);
}
- else
+ else
{
- if (current())
+ if (m_dialog)
+ {
+ m_dialog->update();
+ m_dialog->draw(context);
+ }
+ else if (current_menu())
{
// brute force the transition into the right shape in case the
// menu has changed sizes
- m_transition->set(menu2rect(*current()));
+ m_transition->set(menu2rect(*current_menu()));
m_transition->draw(context);
- current()->draw(context);
+ current_menu()->draw(context);
}
}
- if (current() && MouseCursor::current())
+ if (current_menu() && MouseCursor::current())
{
MouseCursor::current()->draw(context);
}
}
-bool
-MenuManager::check_menu()
+void
+MenuManager::set_dialog(std::unique_ptr<Dialog> dialog)
{
- if (current())
- {
- current()->check_menu();
- return true;
- }
- else
- {
- return false;
- }
+ // delay reseting m_dialog to a later point, as otherwise the Dialog
+ // can't unset itself without ending up with "delete this" problems
+ m_next_dialog = std::move(dialog);
+ m_has_next_dialog = true;
}
void
{
transition(m_menu_stack.empty() ? nullptr : m_menu_stack.back().get(),
menu.get());
+ m_menu_stack.clear();
m_menu_stack.push_back(std::move(menu));
}
else
}
// just to be sure...
- g_input_manager->reset();
+ InputManager::current()->reset();
}
void
}
Menu*
-MenuManager::current() const
+MenuManager::current_menu() const
{
if (m_menu_stack.empty())
{