From: grumbel Date: Thu, 19 Nov 2009 04:07:08 +0000 (+0000) Subject: Trying to separate Menu and Menu management stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=faf2bfee74def7a7abcc460262920fb4a037fbdb;p=supertux.git Trying to separate Menu and Menu management stuff git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6039 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index 1e1b01cff..6511a91b0 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -20,6 +20,7 @@ #include #include "lisp/list_iterator.hpp" +#include "gui/menu_manager.hpp" #include "supertux/console.hpp" #include "supertux/gameconfig.hpp" #include "supertux/menu/joystick_menu.hpp" @@ -489,7 +490,7 @@ JoystickKeyboardController::process_key_event(const SDL_Event& event) if (Console::instance->hasFocus()) { // if console is open: send key there process_console_key_event(event); - } else if (Menu::current()) { + } else if (MenuManager2::current()) { // if menu mode: send key there process_menu_key_event(event); } else if(key_mapping == keymap.end()) { diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 77fa40300..a78d9b784 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -20,6 +20,7 @@ #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu_item.hpp" +#include "gui/menu_manager.hpp" #include "gui/mousecursor.hpp" #include "supertux/globals.hpp" #include "supertux/mainloop.hpp" @@ -34,152 +35,6 @@ static const float MENU_REPEAT_RATE = 0.1f; extern SDL_Surface* g_screen; -std::vector Menu::last_menus; -std::list Menu::all_menus; -Menu* Menu::current_ = 0; -Menu* Menu::previous = 0; - -/* just displays a Yes/No text that can be used to confirm stuff */ -bool confirm_dialog(Surface *background, std::string text) -{ - //Surface* cap_screen = Surface::CaptureScreen(); - Menu* dialog = new Menu; - dialog->add_inactive(-1, text); - dialog->add_hl(); - dialog->add_entry(true, _("Yes")); - dialog->add_entry(false, _("No")); - dialog->add_hl(); - - Menu::set_current(dialog); - - DrawingContext context; - - // TODO make this a screen and not another mainloop... - while(true) - { - SDL_Event event; - while (SDL_PollEvent(&event)) { - if(event.type == SDL_QUIT) - g_main_loop->quit(); - g_main_controller->process_event(event); - dialog->event(event); - } - - if(background == NULL) - context.draw_gradient(Color(0.8f, 0.95f, 0.85f), Color(0.8f, 0.8f, 0.8f), - LAYER_BACKGROUND0); - else - context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0); - - dialog->draw(context); - dialog->update(); - - switch (dialog->check()) - { - case true: - //delete cap_screen; - Menu::set_current(0); - delete dialog; - return true; - break; - case false: - //delete cap_screen; - Menu::set_current(0); - delete dialog; - return false; - break; - default: - break; - } - - mouse_cursor->draw(context); - context.do_drawing(); - SDL_Delay(25); - } - - return false; -} - -void -Menu::push_current(Menu* pmenu) -{ - previous = current_; - - if (current_) - last_menus.push_back(current_); - - current_ = pmenu; - current_->effect_start_time = real_time; - current_->effect_progress = 0.0f; -} - -void -Menu::pop_current() -{ - previous = current_; - - if (last_menus.size() >= 1) { - current_ = last_menus.back(); - current_->effect_start_time = real_time; - current_->effect_progress = 0.0f; - last_menus.pop_back(); - } else { - set_current(NULL); - } -} - -void -Menu::set_current(Menu* menu) -{ - if (current_ && current_->close == true) - return; - - previous = current_; - - if (menu) { - menu->effect_start_time = real_time; - menu->effect_progress = 0.0f; - current_ = menu; - } - else if (current_) { - last_menus.clear(); //NULL new menu pointer => close all menus - current_->effect_start_time = real_time; - current_->effect_progress = 0.0f; - current_->close = true; - } - - // just to be sure... - g_main_controller->reset(); -} - -void -Menu::recalc_pos() -{ - if (current_) - current_->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); - - for(std::list::iterator i = all_menus.begin(); i != all_menus.end(); ++i) - { - // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls - (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); - } -} - -Menu::~Menu() -{ - all_menus.remove(this); - - for(std::vector::iterator i = items.begin(); - i != items.end(); ++i) - delete *i; - - if(current_ == this) - current_ = NULL; - - if (previous == this) - previous = NULL; -} - Menu::Menu() : hit_item(), pos_x(), @@ -200,7 +55,7 @@ Menu::Menu() : arrow_left(), arrow_right() { - all_menus.push_back(this); + MenuManager2::all_menus.push_back(this); hit_item = -1; menuaction = MENU_ACTION_NONE; @@ -222,6 +77,23 @@ Menu::Menu() : arrow_right.reset(new Surface("images/engine/menu/arrow-right.png")); } +Menu::~Menu() +{ + MenuManager2::all_menus.remove(this); + + for(std::vector::iterator i = items.begin(); + i != items.end(); ++i) + { + delete *i; + } + + if (MenuManager2::current_ == this) + MenuManager2::current_ = NULL; + + if (MenuManager2::previous == this) + MenuManager2::previous = NULL; +} + void Menu::set_pos(float x, float y, float rw, float rh) { @@ -359,7 +231,7 @@ Menu::update() effect_progress = 1.0f; if (close) { - current_ = 0; + MenuManager2::current_ = 0; close = false; } } @@ -475,7 +347,7 @@ Menu::update() switch (items[active_item]->kind) { case MN_GOTO: assert(items[active_item]->target_menu != 0); - Menu::push_current(items[active_item]->target_menu); + MenuManager2::push_current(items[active_item]->target_menu); break; case MN_TOGGLE: @@ -507,7 +379,7 @@ Menu::update() break; case MN_BACK: - Menu::pop_current(); + MenuManager2::pop_current(); break; default: break; @@ -542,7 +414,7 @@ Menu::update() break; case MENU_ACTION_BACK: - Menu::pop_current(); + MenuManager2::pop_current(); break; case MENU_ACTION_NONE: @@ -780,13 +652,13 @@ Menu::draw(DrawingContext& context) { if (close) { - menu_width = (current_->get_width() * (1.0f - effect_progress)); - menu_height = (current_->get_height() * (1.0f - effect_progress)); + menu_width = (MenuManager2::current_->get_width() * (1.0f - effect_progress)); + menu_height = (MenuManager2::current_->get_height() * (1.0f - effect_progress)); } - else if (Menu::previous) + else if (MenuManager2::previous) { - menu_width = (menu_width * effect_progress) + (Menu::previous->get_width() * (1.0f - effect_progress)); - menu_height = (menu_height * effect_progress) + (Menu::previous->get_height() * (1.0f - effect_progress)); + menu_width = (menu_width * effect_progress) + (MenuManager2::previous->get_width() * (1.0f - effect_progress)); + menu_height = (menu_height * effect_progress) + (MenuManager2::previous->get_height() * (1.0f - effect_progress)); //std::cout << effect_progress << " " << this << " " << last_menus.back() << std::endl; } else @@ -890,10 +762,10 @@ Menu::set_toggled(int id, bool toggled) Menu* Menu::get_parent() const { - if (last_menus.empty()) + if (MenuManager2::last_menus.empty()) return 0; else - return last_menus.back(); + return MenuManager2::last_menus.back(); } /* Check for menu event */ diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index b74e931ad..7aae4f781 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -37,30 +37,6 @@ class Menu static Color label_color; static Color field_color; private: - static std::vector last_menus; - - /** Pointers to all currently available menus, used to handle repositioning on window resize */ - static std::list all_menus; - - static Menu* previous; - static Menu* current_; - -public: - /** Set the current menu, if pmenu is NULL, hide the current menu */ - static void set_current(Menu* pmenu); - - static void push_current(Menu* pmenu); - static void pop_current(); - - static void recalc_pos(); - - /** Return the current active menu or NULL if none is active */ - static Menu* current() - { - return current_; - } - -private: /* Action done on the menu */ enum MenuAction { MENU_ACTION_NONE = -1, @@ -147,14 +123,16 @@ private: char mn_input_char; float menu_repeat_time; +public: bool close; -public: std::vector items; -private: +public: float effect_progress; float effect_start_time; + +private: int arrange_left; int active_item; diff --git a/src/gui/menu_item.hpp b/src/gui/menu_item.hpp index aab6e7e6b..35fbc37f1 100644 --- a/src/gui/menu_item.hpp +++ b/src/gui/menu_item.hpp @@ -41,6 +41,10 @@ enum MenuItemKind { class MenuItem { public: + static MenuItem* create(MenuItemKind kind, const std::string& text, + int init_toggle, Menu* target_menu, int id, int key); + +public: MenuItem(MenuItemKind kind, int id = -1); void set_help(const std::string& help_text); @@ -48,9 +52,6 @@ public: void change_text (const std::string& text); void change_input(const std::string& text); - static MenuItem* create(MenuItemKind kind, const std::string& text, - int init_toggle, Menu* target_menu, int id, int key); - std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol public: diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp new file mode 100644 index 000000000..51326362d --- /dev/null +++ b/src/gui/menu_manager.cpp @@ -0,0 +1,94 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "gui/menu_manager.hpp" + +#include "control/joystickkeyboardcontroller.hpp" +#include "gui/menu.hpp" +#include "supertux/globals.hpp" +#include "supertux/timer.hpp" + +std::vector MenuManager2::last_menus; +std::list MenuManager2::all_menus; +Menu* MenuManager2::current_ = 0; +Menu* MenuManager2::previous = 0; + +void +MenuManager2::push_current(Menu* pmenu) +{ + previous = current_; + + if (current_) + last_menus.push_back(current_); + + current_ = pmenu; + current_->effect_start_time = real_time; + current_->effect_progress = 0.0f; +} + +void +MenuManager2::pop_current() +{ + previous = current_; + + if (last_menus.size() >= 1) { + current_ = last_menus.back(); + current_->effect_start_time = real_time; + current_->effect_progress = 0.0f; + last_menus.pop_back(); + } else { + set_current(NULL); + } +} + +void +MenuManager2::set_current(Menu* menu) +{ + if (current_ && current_->close == true) + return; + + previous = current_; + + if (menu) { + menu->effect_start_time = real_time; + menu->effect_progress = 0.0f; + current_ = menu; + } + else if (current_) { + last_menus.clear(); //NULL new menu pointer => close all menus + current_->effect_start_time = real_time; + current_->effect_progress = 0.0f; + current_->close = true; + } + + // just to be sure... + g_main_controller->reset(); +} + +void +MenuManager2::recalc_pos() +{ + if (current_) + current_->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); + + for(std::list::iterator i = all_menus.begin(); i != all_menus.end(); ++i) + { + // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls + (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); + } +} + +/* EOF */ diff --git a/src/gui/menu_manager.hpp b/src/gui/menu_manager.hpp new file mode 100644 index 000000000..639f0fc78 --- /dev/null +++ b/src/gui/menu_manager.hpp @@ -0,0 +1,58 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_GUI_MENU_MANAGER_HPP +#define HEADER_SUPERTUX_GUI_MENU_MANAGER_HPP + +#include +#include + +class Menu; + +class MenuManager2 // FIXME: temporary name +{ +public: + static std::vector last_menus; + static Menu* previous; + static Menu* current_; + +public: + /** Pointers to all currently available menus, used to handle repositioning on window resize */ + static std::list all_menus; + +public: + /** Set the current menu, if pmenu is NULL, hide the current menu */ + static void set_current(Menu* pmenu); + + static void push_current(Menu* pmenu); + static void pop_current(); + + static void recalc_pos(); + + /** Return the current active menu or NULL if none is active */ + static Menu* current() + { + return current_; + } + +private: + MenuManager2(const MenuManager2&); + MenuManager2& operator=(const MenuManager2&); +}; + +#endif + +/* EOF */ diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 79b5aca17..811b0406a 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -22,6 +22,7 @@ #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" +#include "gui/menu_manager.hpp" #include "math/random_generator.hpp" #include "object/camera.hpp" #include "object/endsequence_fireworks.hpp" @@ -247,7 +248,7 @@ GameSession::toggle_pause() if(!game_pause) { speed_before_pause = g_main_loop->get_speed(); g_main_loop->set_speed(0); - Menu::set_current(game_menu.get()); + MenuManager2::set_current(game_menu.get()); game_menu->set_active_item(MNID_CONTINUE); game_pause = true; } @@ -392,16 +393,16 @@ GameSession::draw_pause(DrawingContext& context) void GameSession::process_menu() { - Menu* menu = Menu::current(); + Menu* menu = MenuManager2::current(); if(menu) { if(menu == game_menu.get()) { switch (game_menu->check()) { case MNID_CONTINUE: - Menu::set_current(0); + MenuManager2::set_current(0); toggle_pause(); break; case MNID_ABORTLEVEL: - Menu::set_current(0); + MenuManager2::set_current(0); g_main_loop->exit_screen(); break; } @@ -439,7 +440,7 @@ GameSession::update(float elapsed_time) process_menu(); // Unpause the game if the menu has been closed - if (game_pause && !Menu::current()) { + if (game_pause && !MenuManager2::current()) { g_main_loop->set_speed(speed_before_pause); game_pause = false; } diff --git a/src/supertux/mainloop.cpp b/src/supertux/mainloop.cpp index 7fe5d5c87..fe498700c 100644 --- a/src/supertux/mainloop.cpp +++ b/src/supertux/mainloop.cpp @@ -19,6 +19,7 @@ #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" +#include "gui/menu_manager.hpp" #include "scripting/squirrel_util.hpp" #include "scripting/time_scheduler.hpp" #include "supertux/constants.hpp" @@ -144,8 +145,8 @@ MainLoop::draw(DrawingContext& context) static int frame_count = 0; current_screen->draw(context); - if(Menu::current() != NULL) - Menu::current()->draw(context); + if(MenuManager2::current() != NULL) + MenuManager2::current()->draw(context); if(screen_fade.get() != NULL) screen_fade->draw(context); Console::instance->draw(context); @@ -180,8 +181,8 @@ MainLoop::update_gamelogic(float elapsed_time) Scripting::update_debugger(); Scripting::TimeScheduler::instance->update(game_time); current_screen->update(elapsed_time); - if (Menu::current() != NULL) - Menu::current()->update(); + if (MenuManager2::current() != NULL) + MenuManager2::current()->update(); if(screen_fade.get() != NULL) screen_fade->update(elapsed_time); Console::instance->update(elapsed_time); @@ -197,8 +198,8 @@ MainLoop::process_events() { g_main_controller->process_event(event); - if(Menu::current() != NULL) - Menu::current()->event(event); + if(MenuManager2::current() != NULL) + MenuManager2::current()->event(event); switch(event.type) { @@ -208,7 +209,7 @@ MainLoop::process_events() case SDL_VIDEORESIZE: Renderer::instance()->resize(event.resize.w, event.resize.h); - Menu::recalc_pos(); + MenuManager2::recalc_pos(); break; case SDL_KEYDOWN: @@ -220,7 +221,7 @@ MainLoop::process_events() { g_config->use_fullscreen = !g_config->use_fullscreen; init_video(); - Menu::recalc_pos(); + MenuManager2::recalc_pos(); } else if (event.key.keysym.sym == SDLK_PRINT || event.key.keysym.sym == SDLK_F12) diff --git a/src/supertux/menu/joystick_menu.cpp b/src/supertux/menu/joystick_menu.cpp index 9a81e3746..5d9fa8301 100644 --- a/src/supertux/menu/joystick_menu.cpp +++ b/src/supertux/menu/joystick_menu.cpp @@ -1,5 +1,6 @@ // SuperTux -// Copyright (C) 2009 Ingo Ruhnke +// Copyright (C) 2006 Matthias Braun , +// 2007 Ingo Ruhnke // // 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 diff --git a/src/supertux/menu/language_menu.cpp b/src/supertux/menu/language_menu.cpp index 444821639..a8a316c3d 100644 --- a/src/supertux/menu/language_menu.cpp +++ b/src/supertux/menu/language_menu.cpp @@ -21,6 +21,7 @@ extern "C" { #include "findlocale.h" } #include "gui/menu_item.hpp" +#include "gui/menu_manager.hpp" #include "supertux/gameconfig.hpp" enum { @@ -60,14 +61,14 @@ LanguageMenu::menu_action(MenuItem* item) dictionary_manager.set_language(language); g_config->locale = language.str(); g_config->save(); - Menu::pop_current(); + MenuManager2::pop_current(); } else if (item->id == MNID_LANGUAGE_ENGLISH) // english { g_config->locale = "en"; dictionary_manager.set_language(tinygettext::Language::from_name(g_config->locale)); g_config->save(); - Menu::pop_current(); + MenuManager2::pop_current(); } else { @@ -81,7 +82,7 @@ LanguageMenu::menu_action(MenuItem* item) g_config->locale = i->str(); dictionary_manager.set_language(*i); g_config->save(); - Menu::pop_current(); + MenuManager2::pop_current(); break; } } diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index 1bebe5938..0bceec86d 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -20,6 +20,7 @@ #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" +#include "gui/menu_manager.hpp" #include "gui/menu_item.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" @@ -176,12 +177,12 @@ OptionsMenu::menu_action(MenuItem* item) g_config->aspect_width = 0; // Magic values g_config->aspect_height = 0; Renderer::instance()->apply_config(); - Menu::recalc_pos(); + MenuManager2::recalc_pos(); } else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &g_config->aspect_width, &g_config->aspect_height) == 2) { Renderer::instance()->apply_config(); - Menu::recalc_pos(); + MenuManager2::recalc_pos(); } else { @@ -200,7 +201,7 @@ OptionsMenu::menu_action(MenuItem* item) g_config->magnification /= 100.0f; } Renderer::instance()->apply_config(); - Menu::recalc_pos(); + MenuManager2::recalc_pos(); break; case MNID_FULLSCREEN_RESOLUTION: @@ -214,7 +215,7 @@ OptionsMenu::menu_action(MenuItem* item) if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) { g_config->use_fullscreen = !g_config->use_fullscreen; init_video(); // FIXME: Should call apply_config instead - Menu::recalc_pos(); + MenuManager2::recalc_pos(); g_config->save(); } break; diff --git a/src/supertux/menu/profile_menu.cpp b/src/supertux/menu/profile_menu.cpp index 39b0d954d..e25f80fa9 100644 --- a/src/supertux/menu/profile_menu.cpp +++ b/src/supertux/menu/profile_menu.cpp @@ -19,6 +19,7 @@ #include #include "gui/menu.hpp" +#include "gui/menu_manager.hpp" #include "gui/menu_item.hpp" #include "supertux/gameconfig.hpp" #include "util/gettext.hpp" @@ -42,7 +43,7 @@ void ProfileMenu::menu_action(MenuItem* item) { g_config->profile = item->id; - Menu::set_current(0); + MenuManager2::set_current(0); } /* diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index 5da0446ed..2e2d84c38 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -25,6 +25,7 @@ #include "addon/addon_manager.hpp" #include "audio/sound_manager.hpp" #include "gui/menu.hpp" +#include "gui/menu_manager.hpp" #include "gui/menu_item.hpp" #include "lisp/parser.hpp" #include "object/camera.hpp" @@ -182,7 +183,7 @@ TitleScreen::check_levels_contrib_menu() contrib_world_menu->add_hl(); contrib_world_menu->add_back(_("Back")); - Menu::push_current(contrib_world_menu.get()); + MenuManager2::push_current(contrib_world_menu.get()); } } @@ -259,7 +260,7 @@ TitleScreen::check_addons_menu() try { AddonManager::get_instance().check_online(); generate_addons_menu(); - Menu::set_current(addons_menu.get()); + MenuManager2::set_current(addons_menu.get()); addons_menu->set_active_item(index); } catch (std::runtime_error e) { @@ -360,7 +361,7 @@ TitleScreen::setup() sector->activate(sector->player->get_pos()); } - Menu::set_current(main_menu.get()); + MenuManager2::set_current(main_menu.get()); } void @@ -368,7 +369,7 @@ TitleScreen::leave() { Sector* sector = titlesession->get_current_sector(); sector->deactivate(); - Menu::set_current(NULL); + MenuManager2::set_current(NULL); } void @@ -401,7 +402,7 @@ TitleScreen::update(float elapsed_time) make_tux_jump(); - Menu* menu = Menu::current(); + Menu* menu = MenuManager2::current(); if(menu) { if(menu == main_menu.get()) { switch (main_menu->check()) { @@ -418,17 +419,17 @@ TitleScreen::update(float elapsed_time) case MNID_LEVELS_CONTRIB: // Contrib Menu generate_contrib_menu(); - Menu::push_current(contrib_menu.get()); + MenuManager2::push_current(contrib_menu.get()); break; case MNID_ADDONS: // Add-ons Menu generate_addons_menu(); - Menu::push_current(addons_menu.get()); + MenuManager2::push_current(addons_menu.get()); break; case MNID_CREDITS: - Menu::set_current(NULL); + MenuManager2::set_current(NULL); g_main_loop->push_screen(new TextScroller("credits.txt"), new FadeOut(0.5)); break; @@ -449,16 +450,16 @@ TitleScreen::update(float elapsed_time) // reopen menu if user closed it (so that the app doesn't close when user // accidently hit ESC) - if(Menu::current() == 0 && g_main_loop->has_no_pending_fadeout()) { + if(MenuManager2::current() == 0 && g_main_loop->has_no_pending_fadeout()) { generate_main_menu(); - Menu::set_current(main_menu.get()); + MenuManager2::set_current(main_menu.get()); } } void TitleScreen::start_game() { - Menu::set_current(NULL); + MenuManager2::set_current(NULL); std::string basename = current_world->get_basedir(); basename = basename.substr(0, basename.length()-1); std::string worlddirname = FileSystem::basename(basename); diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index b56c9f393..7842676c6 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -31,6 +31,7 @@ #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" +#include "gui/menu_manager.hpp" #include "gui/mousecursor.hpp" #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" @@ -440,11 +441,11 @@ void WorldMap::on_escape_press() { // Show or hide the menu - if(!Menu::current()) { - Menu::set_current(worldmap_menu.get()); + if(!MenuManager2::current()) { + MenuManager2::set_current(worldmap_menu.get()); tux->set_direction(D_NONE); // stop tux movement when menu is called } else { - Menu::set_current(NULL); + MenuManager2::set_current(NULL); } } @@ -597,13 +598,13 @@ void WorldMap::update(float delta) { if(!in_level) { - Menu* menu = Menu::current(); + Menu* menu = MenuManager2::current(); if(menu != NULL) { if(menu == worldmap_menu.get()) { switch (worldmap_menu->check()) { case MNID_RETURNWORLDMAP: // Return to game - Menu::set_current(0); + MenuManager2::set_current(0); break; case MNID_QUITWORLDMAP: // Quit Worldmap g_main_loop->exit_screen(); @@ -937,7 +938,7 @@ void WorldMap::setup() { sound_manager->play_music(music); - Menu::set_current(NULL); + MenuManager2::set_current(NULL); current_ = this; load_state();