#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"
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
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;
}
}
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;
}
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;
}
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;
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();
}
void
+MenuManager::refresh()
+{
+ for(auto i = m_menu_stack.begin(); i != m_menu_stack.end(); ++i)
+ {
+ (*i)->refresh();
+ }
+}
+
+void
MenuManager::update()
{
if (current())
void event(const SDL_Event& event);
void update();
+ void refresh();
+
void draw(DrawingContext& context);
bool check_menu();
add_hl();
add_back(_("Back"));
- update();
+ refresh();
}
std::string
}
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);
}
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);
}
}
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() {}
add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->keyboard_manager->jump_with_up_kbd);
add_hl();
add_back(_("Back"));
- update();
+ refresh();
}
KeyboardMenu::~KeyboardMenu()
}
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(
KeyboardMenu(InputManager* controller);
~KeyboardMenu();
- void update();
+ void refresh();
std::string get_key_name(SDL_Keycode key);
virtual void menu_action(MenuItem* item);
InputManager* controller;
}
}
-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 */
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&);