levelset_screen.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "supertux/levelset_screen.hpp"
  17. #include "editor/editor.hpp"
  18. #include "sdk/integration.hpp"
  19. #include "supertux/game_session.hpp"
  20. #include "supertux/level.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"
  26. #include "util/log.hpp"
  27. LevelsetScreen::LevelsetScreen(const std::string& basedir, const std::string& level_filename,
  28. Savegame& savegame,
  29. const std::optional<std::pair<std::string, Vector>>& start_pos) :
  30. m_basedir(basedir),
  31. m_level_filename(level_filename),
  32. m_savegame(savegame),
  33. m_level_started(false),
  34. m_solved(false),
  35. m_start_pos(start_pos)
  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. LevelsetState state = m_savegame.get_levelset_state(basedir);
  44. LevelState level_state = state.get_level_state(level_filename);
  45. m_solved = level_state.solved;
  46. }
  47. void
  48. LevelsetScreen::draw(Compositor& compositor)
  49. {
  50. }
  51. void
  52. LevelsetScreen::update(float dt_sec, const Controller& controller)
  53. {
  54. }
  55. void
  56. LevelsetScreen::finished_level(bool win)
  57. {
  58. m_solved = m_solved || win;
  59. }
  60. void
  61. LevelsetScreen::setup()
  62. {
  63. if (m_level_started)
  64. {
  65. log_info << "Saving Levelset state" << std::endl;
  66. // this gets called when the GameSession is done and we return back to the
  67. m_savegame.set_levelset_state(m_basedir, m_level_filename, m_solved);
  68. m_savegame.save();
  69. ScreenManager::current()->pop_screen();
  70. }
  71. else
  72. {
  73. m_level_started = true;
  74. if (Editor::is_active()) {
  75. log_warning << "Editor is still active, quitting Levelset screen" << std::endl;
  76. ScreenManager::current()->pop_screen();
  77. } else {
  78. auto screen = std::make_unique<GameSession>(FileSystem::join(m_basedir, m_level_filename),
  79. m_savegame);
  80. if (m_start_pos) {
  81. screen->set_start_pos(m_start_pos->first, m_start_pos->second);
  82. screen->restart_level();
  83. }
  84. ScreenManager::current()->push_screen(std::move(screen));
  85. }
  86. }
  87. }
  88. void
  89. LevelsetScreen::leave()
  90. {
  91. }
  92. IntegrationStatus
  93. LevelsetScreen::get_status() const
  94. {
  95. IntegrationStatus status;
  96. status.m_details.push_back("In Editor");
  97. return status;
  98. }
  99. /* EOF */