if (changed & SDL_HAT_RIGHT && jhat.value & SDL_HAT_RIGHT)
bind_joyhat(jhat.which, SDL_HAT_RIGHT, Controller::Control(wait_for_joystick));
- MenuStorage::get_joystick_options_menu()->update();
+ MenuStorage::instance().get_joystick_options_menu()->update();
wait_for_joystick = -1;
}
else
else
bind_joyaxis(jaxis.which, jaxis.axis + 1, Controller::Control(wait_for_joystick));
- MenuStorage::get_joystick_options_menu()->update();
+ MenuStorage::instance().get_joystick_options_menu()->update();
wait_for_joystick = -1;
}
}
if(jbutton.state == SDL_PRESSED)
{
bind_joybutton(jbutton.which, jbutton.button, (Controller::Control)wait_for_joystick);
- MenuStorage::get_joystick_options_menu()->update();
+ MenuStorage::instance().get_joystick_options_menu()->update();
parent->reset();
wait_for_joystick = -1;
}
bind_key(event.keysym.sym, static_cast<Controller::Control>(wait_for_key));
}
m_parent->reset();
- MenuStorage::get_key_options_menu()->update();
+ MenuStorage::instance().get_key_options_menu()->update();
wait_for_key = -1;
return;
}
if (event.keysym.sym == SDLK_ESCAPE)
{
m_parent->reset();
- MenuStorage::get_joystick_options_menu()->update();
+ MenuStorage::instance().get_joystick_options_menu()->update();
m_parent->joystick_manager->wait_for_joystick = -1;
}
return;
add_label(level.name);
add_hl();
add_entry(MNID_CONTINUE, _("Continue"));
- add_submenu(_("Options"), MenuStorage::get_options_menu());
+ add_submenu(_("Options"), MenuStorage::instance().get_options_menu());
add_hl();
add_entry(MNID_ABORTLEVEL, _("Abort Level"));
}
add_entry(MNID_STARTGAME, _("Start Game"));
add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
add_entry(MNID_ADDONS, _("Add-ons"));
- add_submenu(_("Options"), MenuStorage::get_options_menu());
+ add_submenu(_("Options"), MenuStorage::instance().get_options_menu());
add_entry(MNID_CREDITS, _("Credits"));
add_entry(MNID_QUITMAINMENU, _("Quit"));
}
#include "supertux/menu/keyboard_menu.hpp"
#include "supertux/globals.hpp"
-OptionsMenu* MenuStorage::options_menu = 0;
-ProfileMenu* MenuStorage::profile_menu = 0;
-KeyboardMenu* MenuStorage::key_options_menu = 0;
-JoystickMenu* MenuStorage::joystick_options_menu = 0;
+MenuStorage* MenuStorage::s_instance = 0;
+
+MenuStorage&
+MenuStorage::instance()
+{
+ assert(s_instance);
+ return *s_instance;
+}
+
+MenuStorage::MenuStorage()
+{
+ assert(!s_instance);
+ s_instance = this;
+}
+
+MenuStorage::~MenuStorage()
+{
+ s_instance = nullptr;
+}
OptionsMenu*
MenuStorage::get_options_menu()
{
- options_menu = new OptionsMenu();
- return options_menu;
+ if (!m_options_menu)
+ {
+ m_options_menu.reset(new OptionsMenu());
+ }
+
+ return m_options_menu.get();
}
ProfileMenu*
MenuStorage::get_profile_menu()
{
- profile_menu = new ProfileMenu();
- return profile_menu;
+ if (!m_profile_menu)
+ {
+ m_profile_menu.reset(new ProfileMenu());
+ }
+
+ return m_profile_menu.get();
}
KeyboardMenu*
MenuStorage::get_key_options_menu()
{
- if (!key_options_menu)
- { // FIXME: this in never freed
- key_options_menu = new KeyboardMenu(g_input_manager);
+ if (!m_key_options_menu)
+ {
+ m_key_options_menu.reset(new KeyboardMenu(g_input_manager));
}
- return key_options_menu;
+ return m_key_options_menu.get();
}
JoystickMenu*
MenuStorage::get_joystick_options_menu()
{
- if (!joystick_options_menu)
- { // FIXME: this in never freed
- joystick_options_menu = new JoystickMenu(g_input_manager);
+ if (!m_joystick_options_menu)
+ {
+ m_joystick_options_menu.reset(new JoystickMenu(g_input_manager));
}
- return joystick_options_menu;
+ return m_joystick_options_menu.get();
}
/* EOF */
#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_MENU_STORAGE_HPP
#define HEADER_SUPERTUX_SUPERTUX_MENU_MENU_STORAGE_HPP
+#include <memory>
+
class JoystickMenu;
class KeyboardMenu;
class Menu;
class MenuStorage
{
+private:
+ static MenuStorage* s_instance;
+public:
+ static MenuStorage& instance();
+
public:
MenuStorage();
+ ~MenuStorage();
- static OptionsMenu* get_options_menu();
- static ProfileMenu* get_profile_menu();
- static KeyboardMenu* get_key_options_menu();
- static JoystickMenu* get_joystick_options_menu();
+ OptionsMenu* get_options_menu();
+ ProfileMenu* get_profile_menu();
+ KeyboardMenu* get_key_options_menu();
+ JoystickMenu* get_joystick_options_menu();
private:
- static OptionsMenu* options_menu;
- static ProfileMenu* profile_menu;
- static KeyboardMenu* key_options_menu;
- static JoystickMenu* joystick_options_menu;
+ std::unique_ptr<OptionsMenu> m_options_menu;
+ std::unique_ptr<ProfileMenu> m_profile_menu;
+ std::unique_ptr<KeyboardMenu> m_key_options_menu;
+ std::unique_ptr<JoystickMenu> m_joystick_options_menu;
private:
MenuStorage(const MenuStorage&);
add_submenu(_("Select Language"), language_menu.get())
->set_help(_("Select a different language to display text in"));
- add_submenu(_("Select Profile"), MenuStorage::get_profile_menu())
+ add_submenu(_("Select Profile"), MenuStorage::instance().get_profile_menu())
->set_help(_("Select a profile to play with"));
add_toggle(MNID_PROFILES, _("Profile on Startup"), g_config->sound_enabled)
add_inactive(MNID_MUSIC, _("Music (disabled)"));
}
- add_submenu(_("Setup Keyboard"), MenuStorage::get_key_options_menu())
+ add_submenu(_("Setup Keyboard"), MenuStorage::instance().get_key_options_menu())
->set_help(_("Configure key-action mappings"));
- add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu())
+ add_submenu(_("Setup Joystick"), MenuStorage::instance().get_joystick_options_menu())
->set_help(_("Configure joystick control-action mappings"));
add_hl();
add_back(_("Back"));
add_label(_("Pause"));
add_hl();
add_entry(MNID_RETURNWORLDMAP, _("Continue"));
- add_submenu(_("Options"), MenuStorage::get_options_menu());
+ add_submenu(_("Options"), MenuStorage::instance().get_options_menu());
add_hl();
add_entry(MNID_QUITWORLDMAP, _("Quit World"));
}
#include "gui/menu_manager.hpp"
#include "scripting/squirrel_util.hpp"
#include "scripting/time_scheduler.hpp"
-#include "supertux/constants.hpp"
#include "supertux/console.hpp"
+#include "supertux/constants.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/main.hpp"
+#include "supertux/menu/menu_storage.hpp"
#include "supertux/player_status.hpp"
#include "supertux/resources.hpp"
-#include "supertux/screen_fade.hpp"
#include "supertux/screen.hpp"
+#include "supertux/screen_fade.hpp"
#include "supertux/timer.hpp"
#include "video/drawing_context.hpp"
#include "video/renderer.hpp"
ScreenManager::ScreenManager() :
waiting_threads(),
+ m_menu_storage(new MenuStorage),
m_menu_manager(new MenuManager),
running(),
speed(1.0),
class Console;
class DrawingContext;
class MenuManager;
+class MenuStorage;
class Screen;
class ScreenFade;
void handle_screen_switch();
private:
+ std::unique_ptr<MenuStorage> m_menu_storage;
std::unique_ptr<MenuManager> m_menu_manager;
bool running;
float speed;