1 | // SuperTux |
2 | // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com> |
3 | // |
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. |
8 | // |
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. |
13 | // |
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/>. |
16 | |
17 | #include "supertux/levelset_screen.hpp" |
18 | |
19 | #include "editor/editor.hpp" |
20 | #include "supertux/game_session.hpp" |
21 | #include "supertux/level.hpp" |
22 | #include "supertux/levelset.hpp" |
23 | #include "supertux/savegame.hpp" |
24 | #include "supertux/screen_fade.hpp" |
25 | #include "supertux/screen_manager.hpp" |
26 | #include "util/file_system.hpp" |
27 | #include "util/log.hpp" |
28 | |
29 | LevelsetScreen::LevelsetScreen(const std::string& basedir, const std::string& level_filename, |
30 | Savegame& savegame) : |
31 | m_basedir(basedir), |
32 | m_level_filename(level_filename), |
33 | m_savegame(savegame), |
34 | m_level_started(false), |
35 | m_solved(false) |
36 | { |
37 | Levelset levelset(basedir); |
38 | for (int i = 0; i < levelset.get_num_levels(); ++i) |
39 | { |
40 | std::string lev = levelset.get_level_filename(i); |
41 | m_savegame.set_levelset_state(m_basedir, lev, false); |
42 | } |
43 | |
44 | LevelsetState state = m_savegame.get_levelset_state(basedir); |
45 | LevelState level_state = state.get_level_state(level_filename); |
46 | m_solved = level_state.solved; |
47 | } |
48 | |
49 | void |
50 | LevelsetScreen::draw(Compositor& compositor) |
51 | { |
52 | } |
53 | |
54 | void |
55 | LevelsetScreen::update(float dt_sec, const Controller& controller) |
56 | { |
57 | } |
58 | |
59 | void |
60 | LevelsetScreen::finished_level(bool win) |
61 | { |
62 | m_solved = m_solved || win; |
63 | } |
64 | |
65 | void |
66 | LevelsetScreen::setup() |
67 | { |
68 | if (m_level_started) |
69 | { |
70 | log_info << "Saving Levelset state" << std::endl; |
71 | // this gets called when the GameSession is done and we return back to the |
72 | m_savegame.set_levelset_state(m_basedir, m_level_filename, m_solved); |
73 | m_savegame.save(); |
74 | ScreenManager::current()->pop_screen(); |
75 | } |
76 | else |
77 | { |
78 | m_level_started = true; |
79 | |
80 | if (Editor::is_active()) { |
81 | log_warning << "Editor is still active, quiting Levelset screen" << std::endl; |
82 | ScreenManager::current()->pop_screen(); |
83 | } else { |
84 | auto screen = std::make_unique<GameSession>(FileSystem::join(m_basedir, m_level_filename), |
85 | m_savegame); |
86 | ScreenManager::current()->push_screen(std::move(screen)); |
87 | } |
88 | } |
89 | } |
90 | |
91 | void |
92 | LevelsetScreen::leave() |
93 | { |
94 | } |
95 | |
96 | /* EOF */ |
97 | |