// SuperTux
-// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include "supertux/menu/contrib_menu.hpp"
#include <physfs.h>
+#include <sstream>
#include "gui/menu_manager.hpp"
+#include "supertux/game_manager.hpp"
+#include "supertux/gameconfig.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/file_system.hpp"
#include "util/gettext.hpp"
ContribMenu::ContribMenu() :
- m_contrib_world_menu(),
m_contrib_worlds()
{
/** Generating contrib levels list by making use of Level Subset */
{
try
{
- std::unique_ptr<World> world (new World());
- world->load(*it + "/info");
- if (!world->hide_from_contribs)
+ std::unique_ptr<World> world = World::load(*it);
+
+ if (!world->hide_from_contribs())
{
- add_entry(i++, world->get_title());
- m_contrib_worlds.push_back(world.release());
+ world->load_state();
+
+ std::ostringstream title;
+ title << world->get_title() << " (" << world->get_num_solved_levels() << "/" << world->get_num_levels() << ")";
+ add_entry(i++, title.str());
+ m_contrib_worlds.push_back(std::move(world));
}
}
catch(std::exception& e)
ContribMenu::~ContribMenu()
{
- for(std::vector<World*>::iterator i = m_contrib_worlds.begin(); i != m_contrib_worlds.end(); ++i)
- {
- delete *i;
- }
- m_contrib_worlds.clear();
}
void
int index = check();
if (index != -1)
{
- World* world = m_contrib_worlds[index];
-
- if (!world->is_levelset)
+ World* world = m_contrib_worlds[index].get();
+ if (!world->is_levelset())
{
- TitleScreen::start_game(world);
+ // FIXME: not the most elegant of solutions to std::move() the
+ // World, but the ContribMenu should get destructed after this,
+ // so it might be ok
+ GameManager::current()->start_game(std::move(m_contrib_worlds[index]));
}
- else
+ else
{
- m_contrib_world_menu.reset(new ContribWorldMenu(*world));
- MenuManager::instance().push_current(m_contrib_world_menu.get());
+ MenuManager::instance().push_menu(std::unique_ptr<Menu>(new ContribWorldMenu(std::move(m_contrib_worlds[index]))));
}
}
}