From: Ingo Ruhnke Date: Thu, 19 Nov 2009 05:18:11 +0000 (+0000) Subject: Moved some more menu stuff out of control/joystickkeyboardcontroller.cpp X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=0c9dd5c18c540fc5f9831da541989b3c66899d44;p=supertux.git Moved some more menu stuff out of control/joystickkeyboardcontroller.cpp SVN-Revision: 6044 --- diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index 53a252d1b..761c6a074 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -23,6 +23,7 @@ #include "gui/menu_manager.hpp" #include "supertux/console.hpp" #include "supertux/gameconfig.hpp" +#include "supertux/menu/menu_storage.hpp" #include "supertux/menu/joystick_menu.hpp" #include "supertux/menu/keyboard_menu.hpp" #include "util/gettext.hpp" @@ -44,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; @@ -109,9 +108,6 @@ JoystickKeyboardController::~JoystickKeyboardController() if(*i != 0) SDL_JoystickClose(*i); } - - delete key_options_menu; - delete joystick_options_menu; } void @@ -357,7 +353,7 @@ JoystickKeyboardController::process_button_event(const SDL_JoyButtonEvent& jbutt if(jbutton.state == SDL_PRESSED) { bind_joybutton(jbutton.button, (Control)wait_for_joystick); - joystick_options_menu->update(); + MenuStorage::get_joystick_options_menu()->update(); reset(); wait_for_joystick = -1; } @@ -384,7 +380,7 @@ JoystickKeyboardController::process_axis_event(const SDL_JoyAxisEvent& jaxis) else bind_joyaxis(jaxis.axis + 1, Control(wait_for_joystick)); - joystick_options_menu->update(); + MenuStorage::get_joystick_options_menu()->update(); wait_for_joystick = -1; } } @@ -440,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); - joystick_options_menu->update(); + MenuStorage::get_joystick_options_menu()->update(); wait_for_joystick = -1; } else @@ -567,14 +563,14 @@ JoystickKeyboardController::process_menu_key_event(const SDL_Event& event) bind_key(event.key.keysym.sym, (Control) wait_for_key); } reset(); - 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(); - joystick_options_menu->update(); + MenuStorage::get_joystick_options_menu()->update(); wait_for_joystick = -1; } return; @@ -758,24 +754,4 @@ JoystickKeyboardController::reversemap_joyhat(Control c) return -1; } -Menu* -JoystickKeyboardController::get_key_options_menu() -{ - if(key_options_menu == 0) { - key_options_menu = new KeyboardMenu(this); - } - - return key_options_menu; -} - -Menu* -JoystickKeyboardController::get_joystick_options_menu() -{ - if(joystick_options_menu == 0) { - joystick_options_menu = new JoystickMenu(this); - } - - return joystick_options_menu; -} - /* EOF */ diff --git a/src/control/joystickkeyboardcontroller.hpp b/src/control/joystickkeyboardcontroller.hpp index 1bcf23b12..33d6020b6 100644 --- a/src/control/joystickkeyboardcontroller.hpp +++ b/src/control/joystickkeyboardcontroller.hpp @@ -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 22a6949f4..a5025037e 100644 --- a/src/supertux/menu/menu_storage.cpp +++ b/src/supertux/menu/menu_storage.cpp @@ -18,9 +18,14 @@ #include "supertux/menu/options_menu.hpp" #include "supertux/menu/profile_menu.hpp" +#include "supertux/menu/joystick_menu.hpp" +#include "supertux/menu/keyboard_menu.hpp" +#include "supertux/globals.hpp" Menu* MenuStorage::options_menu = 0; Menu* MenuStorage::profile_menu = 0; +KeyboardMenu* MenuStorage::key_options_menu = 0; +JoystickMenu* MenuStorage::joystick_options_menu = 0; Menu* MenuStorage::get_options_menu() @@ -50,4 +55,27 @@ MenuStorage::free_profile_menu() profile_menu = 0; } + +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 84ff7c954..dabb47b4a 100644 --- a/src/supertux/menu/menu_storage.hpp +++ b/src/supertux/menu/menu_storage.hpp @@ -18,6 +18,8 @@ #define HEADER_SUPERTUX_SUPERTUX_MENU_MENU_STORAGE_HPP class Menu; +class JoystickMenu; +class KeyboardMenu; class MenuStorage { @@ -25,14 +27,19 @@ public: MenuStorage(); static Menu* get_options_menu(); - static void free_options_menu(); + static void free_options_menu(); static Menu* get_profile_menu(); - static void free_profile_menu(); + static void free_profile_menu(); + + static KeyboardMenu* get_key_options_menu(); + static JoystickMenu* get_joystick_options_menu(); private: static Menu* options_menu; static Menu* 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 9d5b021c2..8d0123d71 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -20,14 +20,16 @@ #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" -#include "gui/menu_manager.hpp" #include "gui/menu_item.hpp" +#include "gui/menu_manager.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" #include "supertux/main.hpp" -#include "supertux/menu/profile_menu.hpp" +#include "supertux/menu/joystick_menu.hpp" +#include "supertux/menu/keyboard_menu.hpp" #include "supertux/menu/language_menu.hpp" #include "supertux/menu/menu_storage.hpp" +#include "supertux/menu/profile_menu.hpp" #include "util/gettext.hpp" #include "video/renderer.hpp" @@ -153,10 +155,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"));