From: Ingo Ruhnke Date: Sat, 9 Aug 2014 19:57:51 +0000 (+0200) Subject: Implemented MenuManager::refresh() so that joystick/keyboard_manager have something... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3748bffb2a3704568af701c788fa7000583338ee;p=supertux.git Implemented MenuManager::refresh() so that joystick/keyboard_manager have something to call when key bindings change --- diff --git a/src/control/joystick_manager.cpp b/src/control/joystick_manager.cpp index b4a82eb73..c9402fdf8 100644 --- a/src/control/joystick_manager.cpp +++ b/src/control/joystick_manager.cpp @@ -19,10 +19,10 @@ #include #include +#include "gui/menu_manager.hpp" #include "control/input_manager.hpp" #include "lisp/list_iterator.hpp" #include "supertux/menu/joystick_menu.hpp" -#include "supertux/menu/menu_storage.hpp" #include "util/gettext.hpp" #include "util/log.hpp" #include "util/writer.hpp" @@ -143,7 +143,7 @@ JoystickManager::process_hat_event(const SDL_JoyHatEvent& jhat) if (changed & SDL_HAT_RIGHT && jhat.value & SDL_HAT_RIGHT) bind_joyhat(jhat.which, SDL_HAT_RIGHT, Controller::Control(wait_for_joystick)); - MenuStorage::instance().get_joystick_options_menu()->update(); + MenuManager::instance().refresh(); wait_for_joystick = -1; } else @@ -191,7 +191,7 @@ JoystickManager::process_axis_event(const SDL_JoyAxisEvent& jaxis) else bind_joyaxis(jaxis.which, jaxis.axis + 1, Controller::Control(wait_for_joystick)); - MenuStorage::instance().get_joystick_options_menu()->update(); + MenuManager::instance().refresh(); wait_for_joystick = -1; } } @@ -232,7 +232,7 @@ JoystickManager::process_button_event(const SDL_JoyButtonEvent& jbutton) if(jbutton.state == SDL_PRESSED) { bind_joybutton(jbutton.which, jbutton.button, (Controller::Control)wait_for_joystick); - MenuStorage::instance().get_joystick_options_menu()->update(); + MenuManager::instance().refresh(); parent->reset(); wait_for_joystick = -1; } diff --git a/src/control/keyboard_manager.cpp b/src/control/keyboard_manager.cpp index c6b3b1bec..64d94d292 100644 --- a/src/control/keyboard_manager.cpp +++ b/src/control/keyboard_manager.cpp @@ -168,7 +168,7 @@ KeyboardManager::process_menu_key_event(const SDL_KeyboardEvent& event) bind_key(event.keysym.sym, static_cast(wait_for_key)); } m_parent->reset(); - MenuStorage::instance().get_key_options_menu()->update(); + MenuManager::instance().refresh(); wait_for_key = -1; return; } @@ -178,7 +178,7 @@ KeyboardManager::process_menu_key_event(const SDL_KeyboardEvent& event) if (event.keysym.sym == SDLK_ESCAPE) { m_parent->reset(); - MenuStorage::instance().get_joystick_options_menu()->update(); + MenuManager::instance().refresh(); m_parent->joystick_manager->wait_for_joystick = -1; } return; diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index 97849289d..d5feba29d 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -71,6 +71,9 @@ public: void update(); + /** Perform actions to bring the menu up to date with configuration changes */ + virtual void refresh() {} + /** Remove all entries from the menu */ void clear(); diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index c531c2e24..48cbebccb 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -141,6 +141,15 @@ MenuManager::~MenuManager() } void +MenuManager::refresh() +{ + for(auto i = m_menu_stack.begin(); i != m_menu_stack.end(); ++i) + { + (*i)->refresh(); + } +} + +void MenuManager::update() { if (current()) diff --git a/src/gui/menu_manager.hpp b/src/gui/menu_manager.hpp index 1b564270b..6b2d39c60 100644 --- a/src/gui/menu_manager.hpp +++ b/src/gui/menu_manager.hpp @@ -46,6 +46,8 @@ public: void event(const SDL_Event& event); void update(); + void refresh(); + void draw(DrawingContext& context); bool check_menu(); diff --git a/src/supertux/menu/joystick_menu.cpp b/src/supertux/menu/joystick_menu.cpp index ecb0de133..7a8f7ccf4 100644 --- a/src/supertux/menu/joystick_menu.cpp +++ b/src/supertux/menu/joystick_menu.cpp @@ -87,7 +87,7 @@ JoystickMenu::recreate_menu() add_hl(); add_back(_("Back")); - update(); + refresh(); } std::string @@ -131,7 +131,7 @@ JoystickMenu::menu_action(MenuItem* item) } void -JoystickMenu::update_menu_item(Controller::Control id) +JoystickMenu::refresh_menu_item(Controller::Control id) { int button = m_input_manager->joystick_manager->reversemap_joybutton(id); int axis = m_input_manager->joystick_manager->reversemap_joyaxis(id); @@ -201,22 +201,22 @@ JoystickMenu::update_menu_item(Controller::Control id) } void -JoystickMenu::update() +JoystickMenu::refresh() { if (m_joysticks_available) { - update_menu_item(Controller::UP); - update_menu_item(Controller::DOWN); - update_menu_item(Controller::LEFT); - update_menu_item(Controller::RIGHT); - - update_menu_item(Controller::JUMP); - update_menu_item(Controller::ACTION); - update_menu_item(Controller::PAUSE_MENU); - update_menu_item(Controller::PEEK_LEFT); - update_menu_item(Controller::PEEK_RIGHT); - update_menu_item(Controller::PEEK_UP); - update_menu_item(Controller::PEEK_DOWN); + refresh_menu_item(Controller::UP); + refresh_menu_item(Controller::DOWN); + refresh_menu_item(Controller::LEFT); + refresh_menu_item(Controller::RIGHT); + + refresh_menu_item(Controller::JUMP); + refresh_menu_item(Controller::ACTION); + refresh_menu_item(Controller::PAUSE_MENU); + refresh_menu_item(Controller::PEEK_LEFT); + refresh_menu_item(Controller::PEEK_RIGHT); + refresh_menu_item(Controller::PEEK_UP); + refresh_menu_item(Controller::PEEK_DOWN); } } diff --git a/src/supertux/menu/joystick_menu.hpp b/src/supertux/menu/joystick_menu.hpp index b4e7fd043..63151928f 100644 --- a/src/supertux/menu/joystick_menu.hpp +++ b/src/supertux/menu/joystick_menu.hpp @@ -27,9 +27,10 @@ public: JoystickMenu(InputManager* input_manager); virtual ~JoystickMenu(); - void update(); + void refresh(); + void refresh_menu_item(Controller::Control id); + std::string get_button_name(int button); - void update_menu_item(Controller::Control id); virtual void menu_action(MenuItem* item); void check_menu() {} diff --git a/src/supertux/menu/keyboard_menu.cpp b/src/supertux/menu/keyboard_menu.cpp index 2b90ae8bd..33d79b3aa 100644 --- a/src/supertux/menu/keyboard_menu.cpp +++ b/src/supertux/menu/keyboard_menu.cpp @@ -43,7 +43,7 @@ KeyboardMenu::KeyboardMenu(InputManager* _controller) : add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->keyboard_manager->jump_with_up_kbd); add_hl(); add_back(_("Back")); - update(); + refresh(); } KeyboardMenu::~KeyboardMenu() @@ -96,10 +96,8 @@ KeyboardMenu::menu_action(MenuItem* item) } void -KeyboardMenu::update() +KeyboardMenu::refresh() { - // update menu - auto& kbd_mgr = controller->keyboard_manager; get_item_by_id((int) Controller::UP).change_input(get_key_name( diff --git a/src/supertux/menu/keyboard_menu.hpp b/src/supertux/menu/keyboard_menu.hpp index 805b6c1f8..3ac2156c6 100644 --- a/src/supertux/menu/keyboard_menu.hpp +++ b/src/supertux/menu/keyboard_menu.hpp @@ -27,7 +27,7 @@ public: KeyboardMenu(InputManager* controller); ~KeyboardMenu(); - void update(); + void refresh(); std::string get_key_name(SDL_Keycode key); virtual void menu_action(MenuItem* item); InputManager* controller; diff --git a/src/supertux/menu/menu_storage.cpp b/src/supertux/menu/menu_storage.cpp index 2b5e04d74..5a1786e3f 100644 --- a/src/supertux/menu/menu_storage.cpp +++ b/src/supertux/menu/menu_storage.cpp @@ -98,18 +98,4 @@ MenuStorage::create(MenuId menu_id) } } -KeyboardMenu* -MenuStorage::get_key_options_menu() -{ - assert(!"broken"); - return new KeyboardMenu(g_input_manager); -} - -JoystickMenu* -MenuStorage::get_joystick_options_menu() -{ - assert(!"broken"); - return new JoystickMenu(g_input_manager); -} - /* EOF */ diff --git a/src/supertux/menu/menu_storage.hpp b/src/supertux/menu/menu_storage.hpp index 49508a4f6..f2b8e1a98 100644 --- a/src/supertux/menu/menu_storage.hpp +++ b/src/supertux/menu/menu_storage.hpp @@ -55,12 +55,6 @@ public: std::unique_ptr create(MenuId menu_id); - // FIXME -#ifdef GRUMBEL -#endif - JoystickMenu* get_joystick_options_menu(); - KeyboardMenu* get_key_options_menu(); - private: MenuStorage(const MenuStorage&); MenuStorage& operator=(const MenuStorage&);