Moved savegame name generation into World class and made it automatic, moved folder...
[supertux.git] / src / supertux / menu / contrib_menu.cpp
index 2139e21..e36b1a0 100644 (file)
@@ -1,5 +1,5 @@
 //  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  */
@@ -46,11 +50,15 @@ ContribMenu::ContribMenu() :
   {
     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());
+        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));
       }
     }
@@ -75,15 +83,16 @@ ContribMenu::check_menu()
   if (index != -1)
   {
     World* world = m_contrib_worlds[index].get();
-    
-    if (!world->is_levelset) 
+    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]))));
     }
   }
 }