From b67e5bba94e18a1091c886142b91ae9a6da75c8f Mon Sep 17 00:00:00 2001 From: grumbel Date: Mon, 8 Mar 2010 07:20:55 +0000 Subject: [PATCH] Reverted r6576, Menus don't belong into JoystickKeyboardController git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6577 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/control/joystickkeyboardcontroller.cpp | 32 ++++++------------------------ src/control/joystickkeyboardcontroller.hpp | 7 ++----- src/supertux/menu/menu_storage.cpp | 24 ++++++++++++++++++++++ src/supertux/menu/menu_storage.hpp | 4 ++++ src/supertux/menu/options_menu.cpp | 4 ++-- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index d007cc1cc..761c6a074 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -45,9 +45,7 @@ JoystickKeyboardController::JoystickKeyboardController() : jump_with_up_joy(), jump_with_up_kbd(), wait_for_key(-1), - wait_for_joystick(-1), - key_options_menu(0), - joystick_options_menu(0) + wait_for_joystick(-1) { // initialize default keyboard map keymap[SDLK_LEFT] = LEFT; @@ -110,8 +108,6 @@ JoystickKeyboardController::~JoystickKeyboardController() if(*i != 0) SDL_JoystickClose(*i); } - delete key_options_menu; - delete joystick_options_menu; } void @@ -175,22 +171,6 @@ JoystickKeyboardController::updateAvailableJoysticks() } } -KeyboardMenu* -JoystickKeyboardController::get_key_options_menu() -{ - if (!key_options_menu) - key_options_menu = new KeyboardMenu(this); - return key_options_menu; -} - -JoystickMenu* -JoystickKeyboardController::get_joystick_options_menu() -{ - if (!joystick_options_menu) - joystick_options_menu = new JoystickMenu(this); - return joystick_options_menu; -} - void JoystickKeyboardController::read(const Reader& lisp) { @@ -373,7 +353,7 @@ JoystickKeyboardController::process_button_event(const SDL_JoyButtonEvent& jbutt if(jbutton.state == SDL_PRESSED) { bind_joybutton(jbutton.button, (Control)wait_for_joystick); - get_joystick_options_menu()->update(); + MenuStorage::get_joystick_options_menu()->update(); reset(); wait_for_joystick = -1; } @@ -400,7 +380,7 @@ JoystickKeyboardController::process_axis_event(const SDL_JoyAxisEvent& jaxis) else bind_joyaxis(jaxis.axis + 1, Control(wait_for_joystick)); - get_joystick_options_menu()->update(); + MenuStorage::get_joystick_options_menu()->update(); wait_for_joystick = -1; } } @@ -456,7 +436,7 @@ JoystickKeyboardController::process_hat_event(const SDL_JoyHatEvent& jhat) if (changed & SDL_HAT_RIGHT && jhat.value & SDL_HAT_RIGHT) bind_joyhat(SDL_HAT_RIGHT, (Control)wait_for_joystick); - get_joystick_options_menu()->update(); + MenuStorage::get_joystick_options_menu()->update(); wait_for_joystick = -1; } else @@ -583,14 +563,14 @@ JoystickKeyboardController::process_menu_key_event(const SDL_Event& event) bind_key(event.key.keysym.sym, (Control) wait_for_key); } reset(); - get_key_options_menu()->update(); + MenuStorage::get_key_options_menu()->update(); wait_for_key = -1; return; } if(wait_for_joystick >= 0) { if(event.key.keysym.sym == SDLK_ESCAPE) { reset(); - get_joystick_options_menu()->update(); + MenuStorage::get_joystick_options_menu()->update(); wait_for_joystick = -1; } return; diff --git a/src/control/joystickkeyboardcontroller.hpp b/src/control/joystickkeyboardcontroller.hpp index 7ef688222..33d6020b6 100644 --- a/src/control/joystickkeyboardcontroller.hpp +++ b/src/control/joystickkeyboardcontroller.hpp @@ -46,8 +46,8 @@ public: void read(const Reader& lisp); void reset(); - KeyboardMenu* get_key_options_menu(); - JoystickMenu* get_joystick_options_menu(); + Menu* get_key_options_menu(); + Menu* get_joystick_options_menu(); void updateAvailableJoysticks(); private: @@ -114,9 +114,6 @@ private: int wait_for_key; int wait_for_joystick; - KeyboardMenu* key_options_menu; - JoystickMenu* joystick_options_menu; - private: JoystickKeyboardController(const JoystickKeyboardController&); JoystickKeyboardController& operator=(const JoystickKeyboardController&); diff --git a/src/supertux/menu/menu_storage.cpp b/src/supertux/menu/menu_storage.cpp index e2b5a2f3f..ea1ae467c 100644 --- a/src/supertux/menu/menu_storage.cpp +++ b/src/supertux/menu/menu_storage.cpp @@ -24,6 +24,8 @@ OptionsMenu* MenuStorage::options_menu = 0; ProfileMenu* MenuStorage::profile_menu = 0; +KeyboardMenu* MenuStorage::key_options_menu = 0; +JoystickMenu* MenuStorage::joystick_options_menu = 0; OptionsMenu* MenuStorage::get_options_menu() @@ -39,4 +41,26 @@ MenuStorage::get_profile_menu() return profile_menu; } +KeyboardMenu* +MenuStorage::get_key_options_menu() +{ + if (!key_options_menu) + { // FIXME: this in never freed + key_options_menu = new KeyboardMenu(g_main_controller); + } + + return key_options_menu; +} + +JoystickMenu* +MenuStorage::get_joystick_options_menu() +{ + if (!joystick_options_menu) + { // FIXME: this in never freed + joystick_options_menu = new JoystickMenu(g_main_controller); + } + + return joystick_options_menu; +} + /* EOF */ diff --git a/src/supertux/menu/menu_storage.hpp b/src/supertux/menu/menu_storage.hpp index 9fb5a3da7..8ac6bf2a3 100644 --- a/src/supertux/menu/menu_storage.hpp +++ b/src/supertux/menu/menu_storage.hpp @@ -30,10 +30,14 @@ public: static OptionsMenu* get_options_menu(); static ProfileMenu* get_profile_menu(); + static KeyboardMenu* get_key_options_menu(); + static JoystickMenu* get_joystick_options_menu(); private: static OptionsMenu* options_menu; static ProfileMenu* profile_menu; + static KeyboardMenu* key_options_menu; + static JoystickMenu* joystick_options_menu; private: MenuStorage(const MenuStorage&); diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index 913da5e43..f01b40264 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -157,10 +157,10 @@ OptionsMenu::OptionsMenu() : add_inactive(MNID_MUSIC, _("Music (disabled)")); } - add_submenu(_("Setup Keyboard"), g_main_controller->get_key_options_menu()) + add_submenu(_("Setup Keyboard"), MenuStorage::get_key_options_menu()) ->set_help(_("Configure key-action mappings")); - add_submenu(_("Setup Joystick"), g_main_controller->get_joystick_options_menu()) + add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu()) ->set_help(_("Configure joystick control-action mappings")); add_hl(); add_back(_("Back")); -- 2.11.0