2 // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "supertux/menu/contrib_levelset_menu.hpp"
21 #include "audio/sound_manager.hpp"
22 #include "gui/menu_item.hpp"
23 #include "supertux/game_manager.hpp"
24 #include "supertux/globals.hpp"
25 #include "supertux/levelset.hpp"
26 #include "supertux/screen_fade.hpp"
27 #include "supertux/screen_manager.hpp"
28 #include "supertux/title_screen.hpp"
29 #include "supertux/world.hpp"
30 #include "util/file_system.hpp"
31 #include "util/gettext.hpp"
33 ContribLevelsetMenu::ContribLevelsetMenu(std::unique_ptr<World> world) :
34 m_world(std::move(world)),
37 assert(m_world->is_levelset());
39 m_levelset = std::unique_ptr<Levelset>(new Levelset(m_world->get_basedir()));
41 Savegame savegame(m_world->get_savegame_filename());
43 LevelsetState state = savegame.get_levelset_state(m_world->get_basedir());
45 add_label(m_world->get_title());
48 for (int i = 0; i < m_levelset->get_num_levels(); ++i)
50 std::string filename = FileSystem::join(m_world->get_basedir(), m_levelset->get_level_filename(i));
51 std::string title = GameManager::current()->get_level_name(filename);
52 LevelState level_state = state.get_level_state(filename);
54 std::ostringstream out;
55 if (level_state.solved)
57 out << title << " [*]";
61 out << title << " [ ]";
63 add_entry(i, out.str());
71 ContribLevelsetMenu::check_menu()
76 if (get_item_by_id(index).kind == MN_ACTION)
78 sound_manager->stop_music();
80 // reload the World so that we have something that we can safely
81 // std::move() around without wreaking the ContribMenu
82 std::unique_ptr<World> world = World::load(m_world->get_basedir());
83 GameManager::current()->start_level(std::move(world), m_levelset->get_level_filename(index));