2 // Copyright (C) 2014 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/levelset_screen.hpp"
19 #include "supertux/game_session.hpp"
20 #include "supertux/globals.hpp"
21 #include "supertux/levelset.hpp"
22 #include "supertux/savegame.hpp"
23 #include "supertux/screen_fade.hpp"
24 #include "supertux/screen_manager.hpp"
25 #include "util/file_system.hpp"
27 LevelsetScreen::LevelsetScreen(const std::string& basedir, const std::string& level_filename,
30 m_level_filename(level_filename),
32 m_level_started(false),
35 Levelset levelset(basedir);
36 for(int i = 0; i < levelset.get_num_levels(); ++i)
38 std::string lev = levelset.get_level_filename(i);
39 m_savegame.set_levelset_state(m_basedir, lev, false);
42 LevelsetState state = m_savegame.get_levelset_state(basedir);
43 LevelState level_state = state.get_level_state(level_filename);
44 m_solved = level_state.solved;
47 LevelsetScreen::~LevelsetScreen()
52 LevelsetScreen::draw(DrawingContext&)
57 LevelsetScreen::update(float elapsed_time)
62 LevelsetScreen::finished_level(bool win)
64 m_solved = m_solved || win;
68 LevelsetScreen::setup()
72 log_info << "Saving Levelset state" << std::endl;
73 // this gets called when the GameSession is done and we return back to the
74 m_savegame.set_levelset_state(m_basedir, m_level_filename, m_solved);
76 g_screen_manager->pop_screen();
80 m_level_started = true;
82 std::unique_ptr<Screen> screen(new GameSession(FileSystem::join(m_basedir, m_level_filename),
84 g_screen_manager->push_screen(std::move(screen));
89 LevelsetScreen::leave()