}
MenuItem*
-Menu::add_submenu(const std::string& text, Menu* submenu, int id)
+Menu::add_submenu(const std::string& text, int submenu, int id)
{
std::unique_ptr<MenuItem> item(new MenuItem(MN_GOTO, id));
item->text = text;
MenuItem* add_toggle(int id, const std::string& text, bool toggled = false);
MenuItem* add_inactive(int id, const std::string& text);
MenuItem* add_back(const std::string& text);
- MenuItem* add_submenu(const std::string& text, Menu* submenu, int id = -1);
+ MenuItem* add_submenu(const std::string& text, int submenu, int id = -1);
MenuItem* add_controlfield(int id, const std::string& text,
const std::string& mapping = "");
MenuItem* add_string_select(int id, const std::string& text);
#include "gui/menu_item.hpp"
+#include <stdio.h>
+
+#include "supertux/menu/menu_storage.hpp"
#include "supertux/resources.hpp"
#include "supertux/timer.hpp"
#include "video/font.hpp"
-#include <stdio.h>
-static const float FLICK_CURSOR_TIME = 0.5f;
+static const float FLICK_CURSOR_TIME = 0.5f;
MenuItem::MenuItem(MenuItemKind _kind, int _id) :
kind(_kind),
{
toggled = false;
selected = false;
- target_menu = 0;
+ target_menu = MenuStorage::NO_MENU;
}
void
{
public:
static MenuItem* create(MenuItemKind kind, const std::string& text,
- int init_toggle, Menu* target_menu, int id, int key);
+ int init_toggle, int target_menu, int id, int key);
public:
MenuItem(MenuItemKind kind, int id = -1);
std::vector<std::string> list; // list of values for a STRINGSELECT item
size_t selected; // currently selected item
- Menu* target_menu;
+ int target_menu;
private:
/// keyboard key or joystick button
#include "control/input_manager.hpp"
#include "gui/menu.hpp"
#include "supertux/globals.hpp"
+#include "supertux/menu/menu_storage.hpp"
#include "supertux/timer.hpp"
MenuManager* MenuManager::s_instance = 0;
}
}
+bool
+MenuManager::check_menu()
+{
+ if (m_current)
+ {
+ m_current->check_menu();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
void
-MenuManager::push_current(Menu* menu)
+MenuManager::push_current(int id)
+{
+ Menu* menu = MenuStorage::instance().create(static_cast<MenuStorage::MenuId>(id));
+ push_current_(menu);
+}
+
+void
+MenuManager::push_current_(Menu* menu)
{
m_previous = m_current;
}
else
{
- set_current(nullptr);
+ set_current(MenuStorage::NO_MENU);
}
}
void
-MenuManager::set_current(Menu* menu)
+MenuManager::set_current(int id)
+{
+ Menu* menu = MenuStorage::instance().create(static_cast<MenuStorage::MenuId>(id));
+ set_current_ptr(menu);
+}
+
+void
+MenuManager::set_current_ptr(Menu* menu)
{
if (m_current && m_current->close == true)
{
~MenuManager();
void draw(DrawingContext& context);
+ bool check_menu();
/** Set the current menu, if pmenu is NULL, hide the current menu */
- void set_current(Menu* pmenu);
+ void set_current_ptr(Menu* menu);
+ void set_current(int id);
- void push_current(Menu* pmenu);
+ void push_current(int id);
+ void push_current_(Menu* menu);
void pop_current();
void recalc_pos();
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/levelintro.hpp"
-#include "supertux/menu/game_menu.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/menu/options_menu.hpp"
#include "supertux/player_status.hpp"
capture_file(),
playback_demo_stream(0),
demo_controller(0),
- game_menu(),
play_time(0),
edit_mode(false),
levelintro_shown(false)
if (restart_level() != 0)
throw std::runtime_error ("Initializing the level failed.");
-
- game_menu.reset(new GameMenu(*level));
}
int
if(!game_pause) {
speed_before_pause = g_screen_manager->get_speed();
g_screen_manager->set_speed(0);
- MenuManager::instance().set_current(game_menu.get());
- game_menu->set_active_item(MNID_CONTINUE);
+ MenuManager::instance().set_current(MenuStorage::GAME_MENU);
game_pause = true;
}
void
GameSession::abort_level()
{
- MenuManager::instance().set_current(0);
+ MenuManager::instance().set_current(MenuStorage::NO_MENU);
g_screen_manager->exit_screen();
currentsector->player->set_bonus(bonus_at_start);
PlayerStatus *currentStatus = get_player_status();
on_escape_press();
process_events();
- Menu* menu = MenuManager::instance().current();
- if (menu && menu == game_menu.get())
- {
- menu->check_menu();
- }
+ MenuManager::instance().check_menu();
// Unpause the game if the menu has been closed
if (game_pause && !MenuManager::instance().is_active()) {
std::istream* playback_demo_stream;
CodeController* demo_controller;
- std::unique_ptr<Menu> game_menu;
-
float play_time; /**< total time in seconds that this session ran interactively */
bool edit_mode; /**< true if GameSession runs in level editor mode */
#include <physfs.h>
#include "gui/menu_manager.hpp"
-#include "supertux/menu/contrib_world_menu.hpp"
+#include "supertux/menu/menu_storage.hpp"
#include "supertux/title_screen.hpp"
#include "supertux/world.hpp"
#include "util/gettext.hpp"
ContribMenu::ContribMenu() :
- m_contrib_world_menu(),
m_contrib_worlds()
{
/** Generating contrib levels list by making use of Level Subset */
}
else
{
+#ifdef GRUMBEL
m_contrib_world_menu.reset(new ContribWorldMenu(*world));
- MenuManager::instance().push_current(m_contrib_world_menu.get());
+ MenuManager::instance().push_current(MenuStorage::CONTRIB_WORLD_MENU);
+#endif
}
}
}
class ContribMenu : public Menu
{
private:
- std::unique_ptr<ContribWorldMenu> m_contrib_world_menu;
std::vector<std::unique_ptr<World> > m_contrib_worlds;
public:
#include "supertux/menu/options_menu.hpp"
#include "util/gettext.hpp"
-GameMenu::GameMenu(const Level& level)
+GameMenu::GameMenu()
{
- add_label(level.name);
+ Level* level = GameSession::current()->get_current_level();
+
+ add_label(level->name);
add_hl();
add_entry(MNID_CONTINUE, _("Continue"));
- add_submenu(_("Options"), MenuStorage::instance().get_options_menu());
+ add_submenu(_("Options"), MenuStorage::OPTIONS_MENU);
add_hl();
add_entry(MNID_ABORTLEVEL, _("Abort Level"));
}
{
private:
public:
- GameMenu(const Level& level);
+ GameMenu();
void check_menu() override;
add_entry(MNID_STARTGAME, _("Start Game"));
add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
add_entry(MNID_ADDONS, _("Add-ons"));
- add_submenu(_("Options"), MenuStorage::instance().get_options_menu());
+ add_submenu(_("Options"), MenuStorage::OPTIONS_MENU);
add_entry(MNID_CREDITS, _("Credits"));
add_entry(MNID_QUITMAINMENU, _("Quit"));
}
case MNID_LEVELS_CONTRIB:
// Contrib Menu
m_contrib_menu.reset(new ContribMenu());
- MenuManager::instance().push_current(m_contrib_menu.get());
+ MenuManager::instance().push_current(MenuStorage::CONTRIB_MENU);
break;
case MNID_ADDONS:
// Add-ons Menu
m_addon_menu.reset(new AddonMenu());
- MenuManager::instance().push_current(m_addon_menu.get());
+ MenuManager::instance().push_current(MenuStorage::ADDON_MENU);
break;
case MNID_CREDITS:
- MenuManager::instance().set_current(NULL);
+ MenuManager::instance().set_current(MenuStorage::NO_MENU);
g_screen_manager->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
break;
#include "supertux/menu/menu_storage.hpp"
-#include "supertux/menu/options_menu.hpp"
-#include "supertux/menu/profile_menu.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/menu/addon_menu.hpp"
+#include "supertux/menu/contrib_menu.hpp"
+#include "supertux/menu/contrib_world_menu.hpp"
+#include "supertux/menu/game_menu.hpp"
#include "supertux/menu/joystick_menu.hpp"
#include "supertux/menu/keyboard_menu.hpp"
-#include "supertux/globals.hpp"
+#include "supertux/menu/language_menu.hpp"
+#include "supertux/menu/main_menu.hpp"
+#include "supertux/menu/options_menu.hpp"
+#include "supertux/menu/profile_menu.hpp"
+#include "supertux/menu/worldmap_menu.hpp"
MenuStorage* MenuStorage::s_instance = 0;
s_instance = nullptr;
}
-OptionsMenu*
-MenuStorage::get_options_menu()
+Menu*
+MenuStorage::create(MenuId menu_id)
{
- if (!m_options_menu)
+ switch(menu_id)
{
- m_options_menu.reset(new OptionsMenu);
- }
+ case MAIN_MENU:
+ return new MainMenu;
- return m_options_menu.get();
-}
+ case LANGUAGE_MENU:
+ return new LanguageMenu;
-ProfileMenu*
-MenuStorage::get_profile_menu()
-{
- if (!m_profile_menu)
- {
- m_profile_menu.reset(new ProfileMenu);
- }
+ case OPTIONS_MENU:
+ return new OptionsMenu;
+
+ case PROFILE_MENU:
+ return new ProfileMenu;
+
+ case KEYBOARD_MENU:
+ return new KeyboardMenu(g_input_manager);
- return m_profile_menu.get();
+ case JOYSTICK_MENU:
+ return new JoystickMenu(g_input_manager);
+
+ case WORLDMAP_MENU:
+ return new WorldmapMenu;
+
+ case GAME_MENU:
+ return new GameMenu;
+
+ case CONTRIB_MENU:
+ return new ContribMenu;
+
+ case CONTRIB_WORLD_MENU:
+ return 0; //return new ContribWorldMenu();
+
+ case ADDON_MENU:
+ return new AddonMenu;
+
+ default:
+ assert(!"unknown MenuId provided");
+ }
}
KeyboardMenu*
MenuStorage::get_key_options_menu()
{
- if (!m_key_options_menu)
- {
- m_key_options_menu.reset(new KeyboardMenu(g_input_manager));
- }
-
- return m_key_options_menu.get();
+ return new KeyboardMenu(g_input_manager);
}
JoystickMenu*
MenuStorage::get_joystick_options_menu()
{
- if (!m_joystick_options_menu)
- {
- m_joystick_options_menu.reset(new JoystickMenu(g_input_manager));
- }
-
- return m_joystick_options_menu.get();
+ return new JoystickMenu(g_input_manager);
}
/* EOF */
static MenuStorage& instance();
public:
+ enum MenuId {
+ NO_MENU,
+ MAIN_MENU,
+ OPTIONS_MENU,
+ PROFILE_MENU,
+ CONTRIB_MENU,
+ CONTRIB_WORLD_MENU,
+ ADDON_MENU,
+ LANGUAGE_MENU,
+ KEYBOARD_MENU,
+ JOYSTICK_MENU,
+ WORLDMAP_MENU,
+ GAME_MENU
+ };
+
+public:
MenuStorage();
~MenuStorage();
-
- OptionsMenu* get_options_menu();
- ProfileMenu* get_profile_menu();
- KeyboardMenu* get_key_options_menu();
+
+ Menu* create(MenuId menu_id);
+
+ // FIXME
JoystickMenu* get_joystick_options_menu();
-
-private:
- 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;
+ KeyboardMenu* get_key_options_menu();
private:
MenuStorage(const MenuStorage&);
MNID_MUSIC
};
-OptionsMenu::OptionsMenu() :
- language_menu()
+OptionsMenu::OptionsMenu()
{
- language_menu.reset(new LanguageMenu());
-
add_label(_("Options"));
add_hl();
// Language change should only be possible in the main menu, since elsewhere it might not always work fully
// FIXME: Implement me: if (get_parent() == main_menu)
- add_submenu(_("Select Language"), language_menu.get())
+ add_submenu(_("Select Language"), MenuStorage::LANGUAGE_MENU)
->set_help(_("Select a different language to display text in"));
- add_submenu(_("Select Profile"), MenuStorage::instance().get_profile_menu())
+ add_submenu(_("Select Profile"), MenuStorage::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::instance().get_key_options_menu())
+ add_submenu(_("Setup Keyboard"), MenuStorage::KEYBOARD_MENU)
->set_help(_("Configure key-action mappings"));
- add_submenu(_("Setup Joystick"), MenuStorage::instance().get_joystick_options_menu())
+ add_submenu(_("Setup Joystick"), MenuStorage::JOYSTICK_MENU)
->set_help(_("Configure joystick control-action mappings"));
add_hl();
add_back(_("Back"));
#ifndef HEADER_SUPERTUX_SUPERTUX_OPTIONS_MENU_HPP
#define HEADER_SUPERTUX_SUPERTUX_OPTIONS_MENU_HPP
-
#include "gui/menu.hpp"
-class LanguageMenu;
-
class OptionsMenu : public Menu
{
public:
void menu_action(MenuItem* item);
void check_menu();
-
-protected:
- std::unique_ptr<LanguageMenu> language_menu;
};
#endif
add_label(_("Pause"));
add_hl();
add_entry(MNID_RETURNWORLDMAP, _("Continue"));
- add_submenu(_("Options"), MenuStorage::instance().get_options_menu());
+ add_submenu(_("Options"), MenuStorage::OPTIONS_MENU);
add_hl();
add_entry(MNID_QUITWORLDMAP, _("Quit World"));
}
#include "supertux/title_screen.hpp"
#include "audio/sound_manager.hpp"
+#include "gui/menu.hpp"
#include "gui/menu_manager.hpp"
#include "lisp/parser.hpp"
#include "object/camera.hpp"
#include "supertux/fadeout.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
-#include "supertux/screen_manager.hpp"
-#include "supertux/menu/addon_menu.hpp"
-#include "supertux/menu/contrib_world_menu.hpp"
-#include "supertux/menu/contrib_menu.hpp"
-#include "supertux/menu/main_menu.hpp"
+#include "supertux/menu/menu_storage.hpp"
#include "supertux/resources.hpp"
+#include "supertux/screen_manager.hpp"
#include "supertux/sector.hpp"
#include "supertux/textscroller.hpp"
#include "supertux/world.hpp"
#include <version.h>
TitleScreen::TitleScreen(PlayerStatus* player_status) :
- main_menu(new MainMenu()),
frame(),
controller(),
titlesession()
sector->activate(sector->player->get_pos());
}
- MenuManager::instance().set_current(main_menu.get());
+ MenuManager::instance().set_current(MenuStorage::MAIN_MENU);
}
void
{
Sector* sector = titlesession->get_current_sector();
sector->deactivate();
- MenuManager::instance().set_current(nullptr);
+ MenuManager::instance().set_current(MenuStorage::NO_MENU);
}
void
// accidently hit ESC)
if(!MenuManager::instance().is_active() && g_screen_manager->has_no_pending_fadeout())
{
- MenuManager::instance().set_current(main_menu.get());
+ MenuManager::instance().set_current(MenuStorage::MAIN_MENU);
}
}
void
TitleScreen::start_game(World* world)
{
- MenuManager::instance().set_current(NULL);
+ MenuManager::instance().set_current(MenuStorage::NO_MENU);
std::string basename = world->get_basedir();
basename = basename.substr(0, basename.length()-1);
class CodeController;
class ContribMenu;
class ContribWorldMenu;
-class MainMenu;
class Menu;
class PlayerStatus;
class World;
private:
void make_tux_jump();
- void generate_main_menu();
private:
- std::unique_ptr<MainMenu> main_menu;
SurfacePtr frame;
std::unique_ptr<CodeController> controller;
std::unique_ptr<GameSession> titlesession;
player_status(player_status),
tileset(NULL),
free_tileset(false),
- worldmap_menu(),
camera_offset(),
name(),
music(),
total_stats.reset();
- worldmap_menu.reset(new WorldmapMenu());
-
// create a new squirrel table for the worldmap
using namespace scripting;
{
// Show or hide the menu
if(!MenuManager::instance().is_active()) {
- MenuManager::instance().set_current(worldmap_menu.get());
+ MenuManager::instance().set_current(MenuStorage::WORLDMAP_MENU);
tux->set_direction(D_NONE); // stop tux movement when menu is called
} else {
- MenuManager::instance().set_current(NULL);
+ MenuManager::instance().set_current(MenuStorage::NO_MENU);
}
}
WorldMap::update(float delta)
{
if(!in_level) {
- Menu* menu = MenuManager::instance().current();
- if (menu && menu == worldmap_menu.get())
+ if (MenuManager::instance().check_menu())
{
- menu->check_menu();
return;
}
WorldMap::setup()
{
sound_manager->play_music(music);
- MenuManager::instance().set_current(NULL);
+ MenuManager::instance().set_current(MenuStorage::NO_MENU);
current_ = this;
load_state();
#include "worldmap/teleporter.hpp"
class Sprite;
-class Menu;
class GameObject;
class TileMap;
class PlayerStatus;
static WorldMap* current_;
- std::unique_ptr<Menu> worldmap_menu;
-
Vector camera_offset;
std::string name;