clicked on it) in the last event() call */
int check ();
+ virtual void check_menu() =0;
+
MenuItem& get_item(int index)
{
return *(items[index]);
delete capture_demo_stream;
delete playback_demo_stream;
delete demo_controller;
- MenuStorage::free_options_menu();
}
void
#include <physfs.h>
+#include "gui/menu_manager.hpp"
+#include "supertux/menu/contrib_world_menu.hpp"
+#include "supertux/title_screen.hpp"
#include "supertux/world.hpp"
#include "util/gettext.hpp"
m_contrib_worlds.clear();
}
-World*
-ContribMenu::get_current_world()
+void
+ContribMenu::check_menu()
{
int index = check();
- if (index == -1)
+ if (index != -1)
{
- return 0;
- }
- else
- {
- return m_contrib_worlds[index];
+ World* world = m_contrib_worlds[index];
+
+ if (!world->is_levelset)
+ {
+ TitleScreen::start_game(world);
+ }
+ else
+ {
+ m_contrib_world_menu.reset(new ContribWorldMenu(*world));
+ MenuManager::push_current(m_contrib_world_menu.get());
+ }
}
}
#include "gui/menu.hpp"
-
+class ContribWorldMenu;
class World;
class ContribMenu : public Menu
{
private:
+ std::auto_ptr<ContribWorldMenu> m_contrib_world_menu;
std::vector<World*> m_contrib_worlds;
public:
ContribMenu();
~ContribMenu();
- /** FIXME: the method returns the current world only once, as it uses Menu::check() */
- World* get_current_world();
+ void check_menu();
private:
ContribMenu(const ContribMenu&);
#include "supertux/level.hpp"
#include "supertux/menu/menu_storage.hpp"
+#include "supertux/menu/options_menu.hpp"
#include "util/gettext.hpp"
GameMenu::GameMenu(const Level& level)
add_entry(MNID_ABORTLEVEL, _("Abort Level"));
}
+void
+GameMenu::check_menu()
+{
+}
+
/* EOF */
public:
GameMenu(const Level& level);
+ void check_menu();
+
private:
GameMenu(const GameMenu&);
GameMenu& operator=(const GameMenu&);
void update_menu_item(Controller::Control id);
virtual void menu_action(MenuItem* item);
JoystickKeyboardController* controller;
+ void check_menu() {}
private:
void recreateMenu();
std::string get_key_name(SDLKey key);
virtual void menu_action(MenuItem* item);
JoystickKeyboardController* controller;
-
+ void check_menu() {}
private:
KeyboardMenu(const KeyboardMenu&);
KeyboardMenu& operator=(const KeyboardMenu&);
#ifndef HEADER_SUPERTUX_SUPERTUX_LANGUAGE_MENU_HPP
#define HEADER_SUPERTUX_SUPERTUX_LANGUAGE_MENU_HPP
-
#include "util/gettext.hpp"
#include "gui/menu.hpp"
public:
LanguageMenu();
- virtual void menu_action(MenuItem* item);
+ void menu_action(MenuItem* item);
+ void check_menu() {}
};
#endif
#include "supertux/menu/main_menu.hpp"
+#include "audio/sound_manager.hpp"
+#include "gui/menu_manager.hpp"
+#include "supertux/fadeout.hpp"
#include "supertux/globals.hpp"
#include "supertux/menu/menu_storage.hpp"
+#include "supertux/menu/addon_menu.hpp"
+#include "supertux/menu/options_menu.hpp"
+#include "supertux/menu/contrib_menu.hpp"
+#include "supertux/screen_manager.hpp"
+#include "supertux/textscroller.hpp"
+#include "supertux/title_screen.hpp"
+#include "supertux/world.hpp"
#include "util/gettext.hpp"
-MainMenu::MainMenu()
+MainMenu::MainMenu() :
+ m_addon_menu(),
+ m_contrib_menu()
{
set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
add_entry(MNID_STARTGAME, _("Start Game"));
add_entry(MNID_QUITMAINMENU, _("Quit"));
}
+void
+MainMenu::check_menu()
+{
+ switch (check())
+ {
+ case MNID_STARTGAME:
+ if (m_main_world.get() == NULL)
+ {
+ m_main_world.reset(new World());
+ m_main_world->load("levels/world1/info");
+ }
+ TitleScreen::start_game(m_main_world.get());
+ break;
+
+ case MNID_LEVELS_CONTRIB:
+ // Contrib Menu
+ m_contrib_menu.reset(new ContribMenu());
+ MenuManager::push_current(m_contrib_menu.get());
+ break;
+
+ case MNID_ADDONS:
+ // Add-ons Menu
+ m_addon_menu.reset(new AddonMenu());
+ MenuManager::push_current(m_addon_menu.get());
+ break;
+
+ case MNID_CREDITS:
+ MenuManager::set_current(NULL);
+ g_screen_manager->push_screen(new TextScroller("credits.txt"),
+ new FadeOut(0.5));
+ break;
+
+ case MNID_QUITMAINMENU:
+ g_screen_manager->quit(new FadeOut(0.25));
+ sound_manager->stop_music(0.25);
+ break;
+ }
+}
+
/* EOF */
#include "gui/menu.hpp"
+class AddonMenu;
+class ContribMenu;
+class World;
+
enum MainMenuIDs {
MNID_STARTGAME,
MNID_LEVELS_CONTRIB,
class MainMenu : public Menu
{
private:
+ std::auto_ptr<AddonMenu> m_addon_menu;
+ std::auto_ptr<ContribMenu> m_contrib_menu;
+ std::auto_ptr<World> m_main_world;
+
public:
MainMenu();
+ void check_menu();
+
private:
MainMenu(const MainMenu&);
MainMenu& operator=(const MainMenu&);
#include "supertux/menu/keyboard_menu.hpp"
#include "supertux/globals.hpp"
-Menu* MenuStorage::options_menu = 0;
-Menu* MenuStorage::profile_menu = 0;
+OptionsMenu* MenuStorage::options_menu = 0;
+ProfileMenu* MenuStorage::profile_menu = 0;
KeyboardMenu* MenuStorage::key_options_menu = 0;
JoystickMenu* MenuStorage::joystick_options_menu = 0;
-Menu*
+OptionsMenu*
MenuStorage::get_options_menu()
{
options_menu = new OptionsMenu();
return options_menu;
}
-void
-MenuStorage::free_options_menu()
-{
- delete options_menu;
- options_menu = 0;
-}
-
-Menu*
+ProfileMenu*
MenuStorage::get_profile_menu()
{
profile_menu = new ProfileMenu();
return profile_menu;
}
-void
-MenuStorage::free_profile_menu()
-{
- delete profile_menu;
- profile_menu = 0;
-}
-
-
KeyboardMenu*
MenuStorage::get_key_options_menu()
{
#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_MENU_STORAGE_HPP
#define HEADER_SUPERTUX_SUPERTUX_MENU_MENU_STORAGE_HPP
-class Menu;
class JoystickMenu;
class KeyboardMenu;
+class Menu;
+class OptionsMenu;
+class ProfileMenu;
class MenuStorage
{
public:
MenuStorage();
- static Menu* get_options_menu();
- static void free_options_menu();
-
- static Menu* get_profile_menu();
- static void free_profile_menu();
-
+ static OptionsMenu* get_options_menu();
+ static ProfileMenu* get_profile_menu();
static KeyboardMenu* get_key_options_menu();
static JoystickMenu* get_joystick_options_menu();
private:
- static Menu* options_menu;
- static Menu* profile_menu;
+ static OptionsMenu* options_menu;
+ static ProfileMenu* profile_menu;
static KeyboardMenu* key_options_menu;
static JoystickMenu* joystick_options_menu;
#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 "video/renderer.hpp"
enum OptionsMenuIDs {
}
}
+void
+OptionsMenu::check_menu()
+{
+}
+
/* EOF */
OptionsMenu();
virtual ~OptionsMenu();
- virtual void menu_action(MenuItem* item);
+ void menu_action(MenuItem* item);
+ void check_menu();
protected:
std::auto_ptr<LanguageMenu> language_menu;
ProfileMenu();
void menu_action(MenuItem* item);
+
+ void check_menu() {}
};
#endif
#include "supertux/menu/worldmap_menu.hpp"
#include "supertux/menu/menu_storage.hpp"
+#include "supertux/menu/options_menu.hpp"
#include "util/gettext.hpp"
WorldmapMenu::WorldmapMenu()
add_entry(MNID_QUITWORLDMAP, _("Quit World"));
}
+void
+WorldmapMenu::check_menu()
+{
+}
+
/* EOF */
public:
WorldmapMenu();
+ void check_menu();
+
private:
WorldmapMenu(const WorldmapMenu&);
WorldmapMenu& operator=(const WorldmapMenu&);
#include <version.h>
TitleScreen::TitleScreen() :
- main_menu(),
- contrib_menu(),
- contrib_world_menu(),
- addons_menu(),
- main_world(),
- contrib_worlds(),
- current_world(),
+ main_menu(new MainMenu()),
frame(),
controller(),
titlesession()
player->set_controller(controller.get());
player->set_speedlimit(230); //MAX_WALK_XM
- generate_main_menu();
-
frame = std::auto_ptr<Surface>(new Surface("images/engine/menu/frame.png"));
}
}
void
-TitleScreen::check_levels_contrib_menu()
-{
- current_world = contrib_menu->get_current_world();
-
- if (current_world)
- {
- if (!current_world->is_levelset)
- {
- start_game();
- }
- else
- {
- contrib_world_menu.reset(new ContribWorldMenu(*current_world));
- MenuManager::push_current(contrib_world_menu.get());
- }
- }
-}
-
-void
TitleScreen::make_tux_jump()
{
static bool jumpWasReleased = true;
}
}
-void
-TitleScreen::generate_main_menu()
-{
- main_menu.reset(new MainMenu());
-}
-
TitleScreen::~TitleScreen()
{
}
make_tux_jump();
- Menu* menu = MenuManager::current();
- if(menu) {
- if(menu == main_menu.get()) {
- switch (main_menu->check()) {
- case MNID_STARTGAME:
- // Start Game, ie. goto the slots menu
- if(main_world.get() == NULL) {
- main_world.reset(new World());
- main_world->load("levels/world1/info");
- }
- current_world = main_world.get();
- start_game();
- break;
-
- case MNID_LEVELS_CONTRIB:
- // Contrib Menu
- contrib_menu.reset(new ContribMenu());
- MenuManager::push_current(contrib_menu.get());
- break;
-
- case MNID_ADDONS:
- // Add-ons Menu
- addons_menu.reset(new AddonMenu());
- MenuManager::push_current(addons_menu.get());
- break;
-
- case MNID_CREDITS:
- MenuManager::set_current(NULL);
- g_screen_manager->push_screen(new TextScroller("credits.txt"),
- new FadeOut(0.5));
- break;
-
- case MNID_QUITMAINMENU:
- g_screen_manager->quit(new FadeOut(0.25));
- sound_manager->stop_music(0.25);
- break;
- }
- } else if(menu == contrib_menu.get()) {
- check_levels_contrib_menu();
- } else if(menu == addons_menu.get()) {
- addons_menu->check_menu();
- } else if (menu == contrib_world_menu.get()) {
- contrib_world_menu->check_menu();
- }
+ if (Menu* menu = MenuManager::current())
+ {
+ menu->check_menu();
}
// reopen menu if user closed it (so that the app doesn't close when user
// accidently hit ESC)
- if(MenuManager::current() == 0 && g_screen_manager->has_no_pending_fadeout()) {
- generate_main_menu();
+ if(MenuManager::current() == 0 && g_screen_manager->has_no_pending_fadeout())
+ {
MenuManager::set_current(main_menu.get());
}
}
void
-TitleScreen::start_game()
+TitleScreen::start_game(World* world)
{
MenuManager::set_current(NULL);
- std::string basename = current_world->get_basedir();
+
+ std::string basename = world->get_basedir();
basename = basename.substr(0, basename.length()-1);
std::string worlddirname = FileSystem::basename(basename);
std::ostringstream stream;
stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
std::string slotfile = stream.str();
- try {
- current_world->set_savegame_filename(slotfile);
- current_world->run();
- } catch(std::exception& e) {
+ try
+ {
+ world->set_savegame_filename(slotfile);
+ world->run();
+ }
+ catch(std::exception& e)
+ {
log_fatal << "Couldn't start world: " << e.what() << std::endl;
}
}
virtual void update(float elapsed_time);
+public:
+ static void start_game(World* world);
+
private:
- void start_game();
void make_tux_jump();
void generate_main_menu();
- void check_levels_contrib_menu();
-
+
private:
std::auto_ptr<MainMenu> main_menu;
- std::auto_ptr<ContribMenu> contrib_menu;
- std::auto_ptr<ContribWorldMenu> contrib_world_menu;
- std::auto_ptr<AddonMenu> addons_menu;
-
- std::auto_ptr<World> main_world;
- std::vector<World*> contrib_worlds;
- World* current_world;
-
std::auto_ptr<Surface> frame;
std::auto_ptr<CodeController> controller;
std::auto_ptr<GameSession> titlesession;