supertux
worldmap.hpp
1 // SuperTux
2 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmail.com>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // 2023 Vankata453
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef HEADER_SUPERTUX_WORLDMAP_WORLDMAP_HPP
20 #define HEADER_SUPERTUX_WORLDMAP_WORLDMAP_HPP
21 
22 #include "util/currenton.hpp"
23 
24 #include "control/controller.hpp"
25 #include "supertux/savegame.hpp"
26 #include "supertux/timer.hpp"
27 #include "worldmap/worldmap_sector.hpp"
28 
29 class TileSet;
30 
31 namespace worldmap {
32 
33 class WorldMap final : public Currenton<WorldMap>
34 {
35  friend class WorldMapSector;
36  friend class WorldMapState;
37 
38 public:
39  static Color s_level_title_color;
40  static Color s_message_color;
41  static Color s_teleporter_message_color;
42 
43 public:
44  WorldMap(const std::string& filename, Savegame& savegame,
45  const std::string& force_sector = "", const std::string& force_spawnpoint = "");
46 
47  void setup();
48  void leave();
49 
50  void draw(DrawingContext& context);
51  void update(float dt_sec);
52  void process_input(const Controller& controller);
53 
54  size_t level_count() const;
55  size_t solved_level_count() const;
56 
58  void load_state();
59 
61  void save_state();
62 
65  void change(const std::string& filename, const std::string& force_sector = "",
66  const std::string& force_spawnpoint = "");
67 
69  void set_levels_solved(bool solved, bool perfect);
70 
72  void set_passive_message(const std::string& message, float time);
73 
75  void set_initial_spawnpoint(const std::string& spawnpoint);
76 
77  const std::string& get_title() const { return m_name; }
78  Savegame& get_savegame() const { return m_savegame; }
79  const std::string& get_levels_path() const { return m_levels_path; }
80 
81  WorldMapSector* get_sector(const std::string& name) const;
82  WorldMapSector* get_sector(int index) const;
83 
84  void add_sector(std::unique_ptr<WorldMapSector> sector);
85  WorldMapSector& get_sector() const { return *m_sector; }
86  void set_sector(const std::string& name, const std::string& spawnpoint = "",
87  bool perform_full_setup = true);
88 
89  const std::string& get_filename() const;
90 
91 private:
92  void on_escape_press();
93 
94 private:
95  WorldMapSector* m_sector; /* The currently active sector. */
96  std::vector<std::unique_ptr<WorldMapSector> > m_sectors;
97 
98  std::string m_force_spawnpoint;
99 
100  Savegame& m_savegame;
101  TileSet* m_tileset;
102 
103  std::string m_name;
104  std::string m_map_filename;
105  std::string m_levels_path;
106 
107  /* A worldmap, scheduled to change to next frame. */
108  std::unique_ptr<WorldMap> m_next_worldmap;
109 
111  std::string m_passive_message;
112  Timer m_passive_message_timer;
113 
114  bool m_enter_level;
115  bool m_in_level;
116  bool m_in_world_select;
117 
118 private:
119  WorldMap(const WorldMap&) = delete;
120  WorldMap& operator=(const WorldMap&) = delete;
121 };
122 
123 } // namespace worldmap
124 
125 #endif
126 
127 /* EOF */
void set_initial_spawnpoint(const std::string &spawnpoint)
Sets the initial spawnpoint to be forced on next setup.
Definition: worldmap.cpp:273
Definition: controller.hpp:57
Definition: worldmap_state.hpp:30
WorldMap(const std::string &filename, Savegame &savegame, const std::string &force_sector="", const std::string &force_spawnpoint="")
Definition: worldmap.cpp:49
Represents one of (potentially) multiple, separate parts of a WorldMap.
Definition: worldmap_sector.hpp:39
Definition: object_settings.hpp:32
A &#39;Currenton&#39; allows access to the currently active instance of a class via the static current() func...
Definition: currenton.hpp:30
void save_state()
Save worldmap state to squirrel state table.
Definition: worldmap.cpp:239
void set_passive_message(const std::string &message, float time)
Sets the passive message with specific time.
Definition: worldmap.cpp:266
void load_state()
Load worldmap state from squirrel state table.
Definition: worldmap.cpp:232
void change(const std::string &filename, const std::string &force_sector="", const std::string &force_spawnpoint="")
switch to another worldmap.
Definition: worldmap.cpp:247
Definition: savegame.hpp:69
Definition: color.hpp:26
void set_levels_solved(bool solved, bool perfect)
Mark all levels as solved or unsolved.
Definition: worldmap.cpp:256
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: tile_set.hpp:44
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void setup()
Definition: worldmap.cpp:98
Definition: worldmap.hpp:33