int
Menu::check()
{
- if (hit_item != -1) {
+ if (hit_item != -1)
+ {
int id = items[hit_item]->id;
- hit_item = -1; //Clear event when checked out.. (we would end up in a loop when we try to leave "fake" submenu like Addons or Contrib)
+ // Clear event when checked out.. (we would end up in a loop when we try to leave "fake" submenu like Addons or Contrib)
+ hit_item = -1;
return id;
}
else
#include "supertux/menu/contrib_menu.hpp"
+#include <physfs.h>
+
#include "supertux/world.hpp"
#include "util/gettext.hpp"
-ContribMenu::ContribMenu(const std::vector<std::string>& level_worlds,
- std::vector<World*>& contrib_worlds)
+ContribMenu::ContribMenu()
{
+ /** Generating contrib levels list by making use of Level Subset */
+ std::vector<std::string> level_worlds;
+ char** files = PHYSFS_enumerateFiles("levels/");
+ for(const char* const* filename = files; *filename != 0; ++filename) {
+ std::string filepath = std::string("levels/") + *filename;
+ if(PHYSFS_isDirectory(filepath.c_str()))
+ level_worlds.push_back(filepath);
+ }
+ PHYSFS_freeList(files);
+
+
add_label(_("Contrib Levels"));
add_hl();
if (!world->hide_from_contribs)
{
add_entry(i++, world->title);
- contrib_worlds.push_back(world.release());
+ m_contrib_worlds.push_back(world.release());
}
}
catch(std::exception& e)
add_back(_("Back"));
}
+ContribMenu::~ContribMenu()
+{
+ for(std::vector<World*>::iterator i = m_contrib_worlds.begin(); i != m_contrib_worlds.end(); ++i)
+ {
+ delete *i;
+ }
+ m_contrib_worlds.clear();
+}
+
+World*
+ContribMenu::get_current_world()
+{
+ int index = check();
+ if (index == -1)
+ {
+ return 0;
+ }
+ else
+ {
+ return m_contrib_worlds[index];
+ }
+}
+
/* EOF */
class ContribMenu : public Menu
{
private:
+ std::vector<World*> m_contrib_worlds;
+
public:
- ContribMenu(const std::vector<std::string>& level_worlds,
- std::vector<World*>& contrib_worlds);
+ ContribMenu();
+ ~ContribMenu();
+ /** FIXME: the method returns the current world only once, as it uses Menu::check() */
+ World* get_current_world();
+
private:
ContribMenu(const ContribMenu&);
ContribMenu& operator=(const ContribMenu&);
frame = std::auto_ptr<Surface>(new Surface("images/engine/menu/frame.png"));
}
-void
-TitleScreen::update_load_game_menu()
-{
-}
-
-void
-TitleScreen::free_contrib_menu()
-{
- for(std::vector<World*>::iterator i = contrib_worlds.begin();
- i != contrib_worlds.end(); ++i)
- delete *i;
-
- contrib_worlds.clear();
-}
-
-void
-TitleScreen::generate_contrib_menu()
-{
- /** Generating contrib levels list by making use of Level Subset */
- std::vector<std::string> level_worlds;
- char** files = PHYSFS_enumerateFiles("levels/");
- for(const char* const* filename = files; *filename != 0; ++filename) {
- std::string filepath = std::string("levels/") + *filename;
- if(PHYSFS_isDirectory(filepath.c_str()))
- level_worlds.push_back(filepath);
- }
- PHYSFS_freeList(files);
-
- free_contrib_menu();
- contrib_menu.reset(new ContribMenu(level_worlds,
- contrib_worlds));
-}
-
std::string
TitleScreen::get_level_name(const std::string& filename)
{
void
TitleScreen::check_levels_contrib_menu()
{
- int index = contrib_menu->check();
- if (index == -1)
- return;
-
- current_world = contrib_worlds[index];
-
- if(!current_world->is_levelset) {
- start_game();
- } else {
- contrib_world_menu.reset(new ContribWorldMenu(*current_world));
- MenuManager::push_current(contrib_world_menu.get());
+ 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());
+ }
}
}
std::sort(addons.begin(), addons.end(), generate_addons_menu_sorter);
// (re)generate menu
- free_addons_menu();
addons_menu.reset(new AddonMenu(addons));
}
}
void
-TitleScreen::free_addons_menu()
-{
-}
-
-void
TitleScreen::make_tux_jump()
{
static bool jumpWasReleased = true;
case MNID_LEVELS_CONTRIB:
// Contrib Menu
- generate_contrib_menu();
+ contrib_menu.reset(new ContribMenu());
MenuManager::push_current(contrib_menu.get());
break;
#include "addon/addon.hpp"
#include "supertux/game_session.hpp"
-class Menu;
+class CodeController;
+class ContribMenu;
class ContribWorldMenu;
+class MainMenu;
+class Menu;
class World;
-class CodeController;
/**
* Screen that displays the SuperTux logo, lets players start a new game, etc.
private:
void start_game();
void make_tux_jump();
- void update_load_game_menu();
void generate_main_menu();
- void generate_contrib_menu();
void check_levels_contrib_menu();
- void free_contrib_menu();
void generate_addons_menu();
void check_addons_menu();
- void free_addons_menu();
private:
- std::auto_ptr<Menu> main_menu;
- std::auto_ptr<Menu> contrib_menu;
+ std::auto_ptr<MainMenu> main_menu;
+ std::auto_ptr<ContribMenu> contrib_menu;
std::auto_ptr<ContribWorldMenu> contrib_world_menu;
+
std::auto_ptr<World> main_world;
std::vector<World*> contrib_worlds;
std::auto_ptr<Menu> addons_menu;