From: Ingo Ruhnke Date: Fri, 15 Aug 2014 08:17:37 +0000 (+0200) Subject: Removed old Menu::check_menu() and replaced it with Menu::menu_action() X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=a8444610fbc11abd2227320cf50fdf1914e5c73f;p=supertux.git Removed old Menu::check_menu() and replaced it with Menu::menu_action() --- diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index d6dff2464..b45ae0623 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -36,7 +36,6 @@ static const float MENU_REPEAT_INITIAL = 0.4f; static const float MENU_REPEAT_RATE = 0.1f; Menu::Menu() : - hit_item(), pos(), menuaction(), delete_character(), @@ -46,7 +45,6 @@ Menu::Menu() : arrange_left(), active_item() { - hit_item = -1; menuaction = MENU_ACTION_NONE; delete_character = 0; mn_input_char = '\0'; @@ -234,7 +232,6 @@ Menu::process_input() menuaction = MENU_ACTION_BACK; } - hit_item = -1; if(items.size() == 0) return; @@ -289,7 +286,6 @@ Menu::process_input() break; case MENU_ACTION_HIT: { - hit_item = active_item; switch (items[active_item]->kind) { case MN_GOTO: assert(items[active_item]->target_menu != 0); @@ -372,20 +368,6 @@ Menu::process_input() assert(active_item < int(items.size())); } -int -Menu::check() -{ - if (hit_item != -1) - { - int id = items[hit_item]->id; - // Clear event when checked out.. (we would end up in a loop when we try to leave "fake" submenu like Addons or Contrib) - hit_item = -1; - return id; - } - else - return -1; -} - void Menu::menu_action(MenuItem* ) {} diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index 6ff1ed736..11bd45aec 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -67,7 +67,7 @@ public: const std::string& mapping = ""); MenuItem* add_string_select(int id, const std::string& text); - virtual void menu_action(MenuItem* item); + virtual void menu_action(MenuItem* item) = 0; void process_input(); @@ -77,8 +77,6 @@ public: /** Remove all entries from the menu */ void clear(); - virtual void check_menu() =0; - MenuItem& get_item(int index) { return *(items[index]); @@ -105,10 +103,6 @@ public: virtual void on_window_resize(); protected: - /** Return the index of the menu item that was 'hit' (ie. the user - clicked on it) in the last event() call */ - int check (); - MenuItem* add_item(std::unique_ptr menu_item); private: @@ -116,10 +110,6 @@ private: void draw_item(DrawingContext& context, int index); private: - /** Number of the item that got 'hit' (ie. pressed) in the last - event()/update() call, -1 if none */ - int hit_item; - // position of the menu (ie. center of the menu, not top/left) Vector pos; diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index 3f9ff8e17..aae71e927 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -201,20 +201,6 @@ MenuManager::draw(DrawingContext& context) } } -bool -MenuManager::check_menu() -{ - if (current()) - { - current()->check_menu(); - return true; - } - else - { - return false; - } -} - void MenuManager::push_menu(int id) { diff --git a/src/gui/menu_manager.hpp b/src/gui/menu_manager.hpp index af862977c..643841bac 100644 --- a/src/gui/menu_manager.hpp +++ b/src/gui/menu_manager.hpp @@ -49,7 +49,6 @@ public: void refresh(); void draw(DrawingContext& context); - bool check_menu(); void set_menu(int id); void set_menu(std::unique_ptr menu); diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 3ddedfcf7..0a5195f7c 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -428,7 +428,6 @@ GameSession::update(float elapsed_time) } process_events(); - MenuManager::instance().check_menu(); // Unpause the game if the menu has been closed if (game_pause && !MenuManager::instance().is_active()) { diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index 3494062d8..a32d78311 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -22,6 +22,8 @@ #include "addon/addon.hpp" #include "addon/addon_manager.hpp" +#include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "util/gettext.hpp" namespace { @@ -120,9 +122,9 @@ AddonMenu::refresh() } void -AddonMenu::check_menu() +AddonMenu::menu_action(MenuItem* item) { - int index = check(); + int index = item->id; if (index == -1) { diff --git a/src/supertux/menu/addon_menu.hpp b/src/supertux/menu/addon_menu.hpp index a3b62a702..640c5bc3f 100644 --- a/src/supertux/menu/addon_menu.hpp +++ b/src/supertux/menu/addon_menu.hpp @@ -34,7 +34,7 @@ public: AddonMenu(); void refresh(); - void check_menu(); + void menu_action(MenuItem* item) override; private: AddonMenu(const AddonMenu&); diff --git a/src/supertux/menu/cheat_menu.hpp b/src/supertux/menu/cheat_menu.hpp index 708b2d838..55a147f32 100644 --- a/src/supertux/menu/cheat_menu.hpp +++ b/src/supertux/menu/cheat_menu.hpp @@ -36,7 +36,6 @@ public: CheatMenu(); void menu_action(MenuItem* item) override; - void check_menu() override {} private: CheatMenu(const CheatMenu&) = delete; diff --git a/src/supertux/menu/contrib_levelset_menu.cpp b/src/supertux/menu/contrib_levelset_menu.cpp index 3ef0b3b44..b0197d401 100644 --- a/src/supertux/menu/contrib_levelset_menu.cpp +++ b/src/supertux/menu/contrib_levelset_menu.cpp @@ -69,20 +69,16 @@ ContribLevelsetMenu::ContribLevelsetMenu(std::unique_ptr world) : } void -ContribLevelsetMenu::check_menu() +ContribLevelsetMenu::menu_action(MenuItem* item) { - int index = check(); - if (index != -1) + if (item->kind == MN_ACTION) { - if (get_item_by_id(index).kind == MN_ACTION) - { - sound_manager->stop_music(); + sound_manager->stop_music(); - // reload the World so that we have something that we can safely - // std::move() around without wreaking the ContribMenu - std::unique_ptr world = World::load(m_world->get_basedir()); - GameManager::current()->start_level(std::move(world), m_levelset->get_level_filename(index)); - } + // reload the World so that we have something that we can safely + // std::move() around without wreaking the ContribMenu + std::unique_ptr world = World::load(m_world->get_basedir()); + GameManager::current()->start_level(std::move(world), m_levelset->get_level_filename(item->id)); } } diff --git a/src/supertux/menu/contrib_levelset_menu.hpp b/src/supertux/menu/contrib_levelset_menu.hpp index 0374e92ac..7e1eae552 100644 --- a/src/supertux/menu/contrib_levelset_menu.hpp +++ b/src/supertux/menu/contrib_levelset_menu.hpp @@ -31,7 +31,7 @@ private: public: ContribLevelsetMenu(std::unique_ptr current_world); - void check_menu(); + void menu_action(MenuItem* item) override; private: ContribLevelsetMenu(const ContribLevelsetMenu&); diff --git a/src/supertux/menu/contrib_menu.cpp b/src/supertux/menu/contrib_menu.cpp index d4ae7673f..802c0eac2 100644 --- a/src/supertux/menu/contrib_menu.cpp +++ b/src/supertux/menu/contrib_menu.cpp @@ -19,6 +19,7 @@ #include #include +#include "gui/menu_item.hpp" #include "gui/menu_manager.hpp" #include "supertux/game_manager.hpp" #include "supertux/gameconfig.hpp" @@ -134,9 +135,9 @@ ContribMenu::~ContribMenu() } void -ContribMenu::check_menu() +ContribMenu::menu_action(MenuItem* item) { - int index = check(); + int index = item->id; if (index != -1) { // reload the World so that we have something that we can safely diff --git a/src/supertux/menu/contrib_menu.hpp b/src/supertux/menu/contrib_menu.hpp index d83f8c231..f655c8802 100644 --- a/src/supertux/menu/contrib_menu.hpp +++ b/src/supertux/menu/contrib_menu.hpp @@ -31,7 +31,7 @@ public: ContribMenu(); ~ContribMenu(); - void check_menu(); + void menu_action(MenuItem* item) override; private: ContribMenu(const ContribMenu&); diff --git a/src/supertux/menu/game_menu.cpp b/src/supertux/menu/game_menu.cpp index 239833847..b73f249e2 100644 --- a/src/supertux/menu/game_menu.cpp +++ b/src/supertux/menu/game_menu.cpp @@ -16,12 +16,14 @@ #include "supertux/menu/game_menu.hpp" +#include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "gui/menu_manager.hpp" #include "supertux/game_session.hpp" -#include "supertux/screen_manager.hpp" #include "supertux/level.hpp" #include "supertux/menu/menu_storage.hpp" #include "supertux/menu/options_menu.hpp" +#include "supertux/screen_manager.hpp" #include "util/gettext.hpp" GameMenu::GameMenu() @@ -37,9 +39,9 @@ GameMenu::GameMenu() } void -GameMenu::check_menu() +GameMenu::menu_action(MenuItem* item) { - switch (check()) + switch (item->id) { case MNID_CONTINUE: MenuManager::instance().clear_menu_stack(); diff --git a/src/supertux/menu/game_menu.hpp b/src/supertux/menu/game_menu.hpp index 5b34851ac..4ffaac99b 100644 --- a/src/supertux/menu/game_menu.hpp +++ b/src/supertux/menu/game_menu.hpp @@ -32,7 +32,7 @@ private: public: GameMenu(); - void check_menu() override; + void menu_action(MenuItem* item) override; private: GameMenu(const GameMenu&); diff --git a/src/supertux/menu/joystick_menu.hpp b/src/supertux/menu/joystick_menu.hpp index dd4ba1422..469ed0da1 100644 --- a/src/supertux/menu/joystick_menu.hpp +++ b/src/supertux/menu/joystick_menu.hpp @@ -31,8 +31,7 @@ public: void refresh_menu_item(Controller::Control id); std::string get_button_name(int button); - virtual void menu_action(MenuItem* item); - void check_menu() {} + void menu_action(MenuItem* item) override; private: void recreate_menu(); diff --git a/src/supertux/menu/keyboard_menu.hpp b/src/supertux/menu/keyboard_menu.hpp index 054a9edeb..83f8f5900 100644 --- a/src/supertux/menu/keyboard_menu.hpp +++ b/src/supertux/menu/keyboard_menu.hpp @@ -29,9 +29,9 @@ public: void refresh(); std::string get_key_name(SDL_Keycode key); - virtual void menu_action(MenuItem* item); + void menu_action(MenuItem* item) override; InputManager* controller; - void check_menu() {} + private: KeyboardMenu(const KeyboardMenu&); KeyboardMenu& operator=(const KeyboardMenu&); diff --git a/src/supertux/menu/language_menu.hpp b/src/supertux/menu/language_menu.hpp index 0c4fade6d..991ce4501 100644 --- a/src/supertux/menu/language_menu.hpp +++ b/src/supertux/menu/language_menu.hpp @@ -26,8 +26,7 @@ class LanguageMenu : public Menu public: LanguageMenu(); - void menu_action(MenuItem* item); - void check_menu() {} + void menu_action(MenuItem* item) override; }; #endif diff --git a/src/supertux/menu/main_menu.cpp b/src/supertux/menu/main_menu.cpp index a93ff541a..acd9b2991 100644 --- a/src/supertux/menu/main_menu.cpp +++ b/src/supertux/menu/main_menu.cpp @@ -17,6 +17,7 @@ #include "supertux/menu/main_menu.hpp" #include "audio/sound_manager.hpp" +#include "gui/menu_item.hpp" #include "gui/menu_manager.hpp" #include "supertux/fadeout.hpp" #include "supertux/game_manager.hpp" @@ -51,9 +52,9 @@ MainMenu::on_window_resize() } void -MainMenu::check_menu() +MainMenu::menu_action(MenuItem* item) { - switch (check()) + switch (item->id) { case MNID_STARTGAME: { diff --git a/src/supertux/menu/main_menu.hpp b/src/supertux/menu/main_menu.hpp index 3f0f7780c..54f81875f 100644 --- a/src/supertux/menu/main_menu.hpp +++ b/src/supertux/menu/main_menu.hpp @@ -39,7 +39,7 @@ public: MainMenu(); void on_window_resize() override; - void check_menu(); + void menu_action(MenuItem* item) override; private: MainMenu(const MainMenu&); diff --git a/src/supertux/menu/options_menu.hpp b/src/supertux/menu/options_menu.hpp index 9980e06f0..84ee8aefd 100644 --- a/src/supertux/menu/options_menu.hpp +++ b/src/supertux/menu/options_menu.hpp @@ -26,7 +26,7 @@ public: OptionsMenu(bool complete); virtual ~OptionsMenu(); - void menu_action(MenuItem* item); + void menu_action(MenuItem* item) override; void check_menu(); }; diff --git a/src/supertux/menu/profile_menu.hpp b/src/supertux/menu/profile_menu.hpp index 5ed4648ab..1e8954554 100644 --- a/src/supertux/menu/profile_menu.hpp +++ b/src/supertux/menu/profile_menu.hpp @@ -24,7 +24,7 @@ class ProfileMenu : public Menu public: ProfileMenu(); - void menu_action(MenuItem* item); + void menu_action(MenuItem* item) override; void check_menu() {} }; diff --git a/src/supertux/menu/worldmap_menu.cpp b/src/supertux/menu/worldmap_menu.cpp index 68a7ab29c..f25232542 100644 --- a/src/supertux/menu/worldmap_menu.cpp +++ b/src/supertux/menu/worldmap_menu.cpp @@ -16,6 +16,7 @@ #include "supertux/menu/worldmap_menu.hpp" +#include "gui/menu_item.hpp" #include "gui/menu_manager.hpp" #include "supertux/menu/menu_storage.hpp" #include "supertux/menu/options_menu.hpp" @@ -34,9 +35,9 @@ WorldmapMenu::WorldmapMenu() } void -WorldmapMenu::check_menu() +WorldmapMenu::menu_action(MenuItem* item) { - switch (check()) + switch (item->id) { case MNID_RETURNWORLDMAP: MenuManager::instance().clear_menu_stack(); diff --git a/src/supertux/menu/worldmap_menu.hpp b/src/supertux/menu/worldmap_menu.hpp index 2ddfd2b7d..358dabb1e 100644 --- a/src/supertux/menu/worldmap_menu.hpp +++ b/src/supertux/menu/worldmap_menu.hpp @@ -30,7 +30,7 @@ private: public: WorldmapMenu(); - void check_menu() override; + void menu_action(MenuItem* item) override; private: WorldmapMenu(const WorldmapMenu&); diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index ec22c8bf6..3f7f84534 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -137,8 +137,6 @@ TitleScreen::update(float elapsed_time) make_tux_jump(); - MenuManager::instance().check_menu(); - // reopen menu if user closed it (so that the app doesn't close when user // accidently hit ESC) if(!MenuManager::instance().is_active() && !g_screen_manager->has_pending_fadeout()) diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index ca70b832d..5b69ad238 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -568,12 +568,8 @@ WorldMap::clamp_camera_position(Vector& c) { void WorldMap::update(float delta) { - if(!in_level) { - if (MenuManager::instance().check_menu()) - { - return; - } - + if (!in_level && !MenuManager::instance().is_active()) + { // update GameObjects for(size_t i = 0; i < game_objects.size(); ++i) { GameObject* object = game_objects[i];