Implemented MenuManager::refresh() so that joystick/keyboard_manager have something...
authorIngo Ruhnke <grumbel@gmail.com>
Sat, 9 Aug 2014 19:57:51 +0000 (21:57 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Sat, 9 Aug 2014 20:52:29 +0000 (22:52 +0200)
src/control/joystick_manager.cpp
src/control/keyboard_manager.cpp
src/gui/menu.hpp
src/gui/menu_manager.cpp
src/gui/menu_manager.hpp
src/supertux/menu/joystick_menu.cpp
src/supertux/menu/joystick_menu.hpp
src/supertux/menu/keyboard_menu.cpp
src/supertux/menu/keyboard_menu.hpp
src/supertux/menu/menu_storage.cpp
src/supertux/menu/menu_storage.hpp

index b4a82eb..c9402fd 100644 (file)
 #include <iostream>
 #include <algorithm>
 
+#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;
     }
index c6b3b1b..64d94d2 100644 (file)
@@ -168,7 +168,7 @@ KeyboardManager::process_menu_key_event(const SDL_KeyboardEvent& event)
       bind_key(event.keysym.sym, static_cast<Controller::Control>(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;
index 9784928..d5feba2 100644 (file)
@@ -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();
 
index c531c2e..48cbebc 100644 (file)
@@ -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())
index 1b56427..6b2d39c 100644 (file)
@@ -46,6 +46,8 @@ public:
 
   void event(const SDL_Event& event);
   void update();
+  void refresh();
+
   void draw(DrawingContext& context);
   bool check_menu();
 
index ecb0de1..7a8f7cc 100644 (file)
@@ -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);
   }
 }
 
index b4e7fd0..6315192 100644 (file)
@@ -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() {}
 
index 2b90ae8..33d79b3 100644 (file)
@@ -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(
index 805b6c1..3ac2156 100644 (file)
@@ -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;
index 2b5e04d..5a1786e 100644 (file)
@@ -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 */
index 49508a4..f2b8e1a 100644 (file)
@@ -55,12 +55,6 @@ public:
   
   std::unique_ptr<Menu> 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&);