// if console is open: send key there
process_console_key_event(event);
}
- else if (MenuManager::instance().current())
+ else if (MenuManager::instance().is_active())
{
// if menu mode: send key there
process_menu_key_event(event);
{
MenuManager::instance().m_all_menus.remove(this);
- if (MenuManager::instance().current() == this)
+ if (MenuManager::instance().m_current == this)
MenuManager::instance().m_current = nullptr;
- if (MenuManager::instance().get_previous() == this)
+ if (MenuManager::instance().m_previous == this)
MenuManager::instance().m_previous = nullptr;
}
{
if (close)
{
- menu_width = (MenuManager::instance().current()->get_width() * (1.0f - effect_progress));
- menu_height = (MenuManager::instance().current()->get_height() * (1.0f - effect_progress));
+ menu_width *= 1.0f - effect_progress;
+ menu_height *= 1.0f - effect_progress;
}
- else if (MenuManager::instance().get_previous())
+ else if (MenuManager::instance().m_previous)
{
- menu_width = (menu_width * effect_progress) + (MenuManager::instance().get_previous()->get_width() * (1.0f - effect_progress));
- menu_height = (menu_height * effect_progress) + (MenuManager::instance().get_previous()->get_height() * (1.0f - effect_progress));
+ menu_width = (menu_width * effect_progress) + (MenuManager::instance().m_previous->get_width() * (1.0f - effect_progress));
+ menu_height = (menu_height * effect_progress) + (MenuManager::instance().m_previous->get_height() * (1.0f - effect_progress));
//std::cout << effect_progress << " " << this << " " << last_menus.back() << std::endl;
}
else
void recalc_pos();
- Menu* get_previous()
+ /** Return the current active menu or NULL if none is active */
+ Menu* current() const
{
- return m_previous;
+ return m_current;
}
- /** Return the current active menu or NULL if none is active */
- Menu* current()
+ bool is_active() const
{
- return m_current;
+ return m_current != nullptr;
}
private:
}
// Unpause the game if the menu has been closed
- if (game_pause && !MenuManager::instance().current()) {
+ if (game_pause && !MenuManager::instance().is_active()) {
g_screen_manager->set_speed(speed_before_pause);
game_pause = false;
}
static int frame_count = 0;
current_screen->draw(context);
- if(MenuManager::instance().current() != NULL)
- MenuManager::instance().current()->draw(context);
+ if(m_menu_manager->current() != NULL)
+ m_menu_manager->current()->draw(context);
if(screen_fade.get() != NULL)
screen_fade->draw(context);
Console::instance->draw(context);
scripting::update_debugger();
scripting::TimeScheduler::instance->update(game_time);
current_screen->update(elapsed_time);
- if (MenuManager::instance().current() != NULL)
- MenuManager::instance().current()->update();
+ if (m_menu_manager->current() != NULL)
+ m_menu_manager->current()->update();
if(screen_fade.get() != NULL)
screen_fade->update(elapsed_time);
Console::instance->update(elapsed_time);
{
g_input_manager->process_event(event);
- if(MenuManager::instance().current() != NULL)
- MenuManager::instance().current()->event(event);
+ if(m_menu_manager->current() != NULL)
+ m_menu_manager->current()->event(event);
switch(event.type)
{
case SDL_WINDOWEVENT_RESIZED:
Renderer::instance()->resize(event.window.data1,
event.window.data2);
- MenuManager::instance().recalc_pos();
+ m_menu_manager->recalc_pos();
break;
}
break;
{
g_config->use_fullscreen = !g_config->use_fullscreen;
Renderer::instance()->apply_config();
- MenuManager::instance().recalc_pos();
+ m_menu_manager->recalc_pos();
}
else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||
event.key.keysym.sym == SDLK_F12)
// reopen menu if user closed it (so that the app doesn't close when user
// accidently hit ESC)
- if(MenuManager::instance().current() == 0 && g_screen_manager->has_no_pending_fadeout())
+ if(!MenuManager::instance().is_active() && g_screen_manager->has_no_pending_fadeout())
{
MenuManager::instance().set_current(main_menu.get());
}
WorldMap::on_escape_press()
{
// Show or hide the menu
- if(!MenuManager::instance().current()) {
+ if(!MenuManager::instance().is_active()) {
MenuManager::instance().set_current(worldmap_menu.get());
tux->set_direction(D_NONE); // stop tux movement when menu is called
} else {