| 1 | // SuperTux |
|---|---|
| 2 | // Copyright (C) 2015 Hume2 <teratux.mail@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 | #ifndef HEADER_SUPERTUX_EDITOR_EDITOR_HPP |
| 18 | #define HEADER_SUPERTUX_EDITOR_EDITOR_HPP |
| 19 | |
| 20 | #include <functional> |
| 21 | #include <vector> |
| 22 | #include <string> |
| 23 | |
| 24 | #include "editor/overlay_widget.hpp" |
| 25 | #include "editor/toolbox_widget.hpp" |
| 26 | #include "editor/layers_widget.hpp" |
| 27 | #include "editor/scroller_widget.hpp" |
| 28 | #include "supertux/screen.hpp" |
| 29 | #include "supertux/world.hpp" |
| 30 | #include "util/currenton.hpp" |
| 31 | #include "util/file_system.hpp" |
| 32 | #include "util/log.hpp" |
| 33 | #include "video/surface_ptr.hpp" |
| 34 | |
| 35 | class GameObject; |
| 36 | class Level; |
| 37 | class ObjectGroup; |
| 38 | class Path; |
| 39 | class Savegame; |
| 40 | class Sector; |
| 41 | class TileSet; |
| 42 | class UndoManager; |
| 43 | class World; |
| 44 | |
| 45 | class Editor final : public Screen, |
| 46 | public Currenton<Editor> |
| 47 | { |
| 48 | public: |
| 49 | static bool is_active(); |
| 50 | |
| 51 | public: |
| 52 | static bool s_resaving_in_progress; |
| 53 | |
| 54 | public: |
| 55 | Editor(); |
| 56 | ~Editor(); |
| 57 | |
| 58 | virtual void draw(Compositor&) override; |
| 59 | virtual void update(float dt_sec, const Controller& controller) override; |
| 60 | |
| 61 | virtual void setup() override; |
| 62 | virtual void leave() override; |
| 63 | |
| 64 | void event(const SDL_Event& ev); |
| 65 | void resize(); |
| 66 | |
| 67 | void disable_keyboard() { m_enabled = false; } |
| 68 | |
| 69 | Level* get_level() const { return m_level.get(); } |
| 70 | |
| 71 | void set_world(std::unique_ptr<World> w); |
| 72 | World* get_world() const { return m_world.get(); } |
| 73 | |
| 74 | TileSet* get_tileset() const { return m_tileset; } |
| 75 | TileSelection* get_tiles() const { return m_toolbox_widget->get_tiles(); } |
| 76 | std::string get_tileselect_object() const { return m_toolbox_widget->get_object(); } |
| 77 | |
| 78 | EditorToolboxWidget::InputType get_tileselect_input_type() const { return m_toolbox_widget->get_input_type(); } |
| 79 | |
| 80 | int get_tileselect_select_mode() const; |
| 81 | int get_tileselect_move_mode() const; |
| 82 | |
| 83 | std::string get_levelfile() const { return m_levelfile; } |
| 84 | |
| 85 | void set_level(const std::string& levelfile_) { |
| 86 | m_levelfile = levelfile_; |
| 87 | m_reload_request = true; |
| 88 | } |
| 89 | |
| 90 | std::string get_level_directory() const; |
| 91 | |
| 92 | void open_level_directory(); |
| 93 | |
| 94 | bool is_testing_level() const { return m_leveltested; } |
| 95 | |
| 96 | /** Checks whether the level can be saved and does not contain |
| 97 | obvious issues (currently: check if main sector and a spawn point |
| 98 | named "main" is present) */ |
| 99 | void check_save_prerequisites(const std::function<void ()>& callback) const; |
| 100 | void check_unsaved_changes(const std::function<void ()>& action); |
| 101 | |
| 102 | void load_sector(const std::string& name); |
| 103 | void delete_current_sector(); |
| 104 | |
| 105 | void update_node_iterators(); |
| 106 | void esc_press(); |
| 107 | void delete_markers(); |
| 108 | void sort_layers(); |
| 109 | |
| 110 | void select_tilegroup(int id); |
| 111 | const std::vector<Tilegroup>& get_tilegroups() const; |
| 112 | void change_tileset(); |
| 113 | |
| 114 | void select_objectgroup(int id); |
| 115 | const std::vector<ObjectGroup>& get_objectgroups() const; |
| 116 | |
| 117 | void scroll(const Vector& velocity); |
| 118 | |
| 119 | bool is_level_loaded() const { return m_levelloaded; } |
| 120 | |
| 121 | void edit_path(Path* path, GameObject* new_marked_object) { |
| 122 | m_overlay_widget->edit_path(path, new_marked_object); |
| 123 | } |
| 124 | |
| 125 | void add_layer(GameObject* layer) { m_layers_widget->add_layer(layer); } |
| 126 | |
| 127 | GameObject* get_selected_tilemap() const { return m_layers_widget->get_selected_tilemap(); } |
| 128 | |
| 129 | Sector* get_sector() { return m_sector; } |
| 130 | |
| 131 | void undo(); |
| 132 | void redo(); |
| 133 | |
| 134 | private: |
| 135 | void set_sector(Sector* sector); |
| 136 | void set_level(std::unique_ptr<Level> level, bool reset = true); |
| 137 | void reload_level(); |
| 138 | void quit_editor(); |
| 139 | void save_level(); |
| 140 | void test_level(); |
| 141 | void update_keyboard(const Controller& controller); |
| 142 | |
| 143 | protected: |
| 144 | std::unique_ptr<Level> m_level; |
| 145 | std::unique_ptr<World> m_world; |
| 146 | |
| 147 | std::string m_levelfile; |
| 148 | std::string m_test_levelfile; |
| 149 | |
| 150 | public: |
| 151 | bool m_quit_request; |
| 152 | bool m_newlevel_request; |
| 153 | bool m_reload_request; |
| 154 | bool m_reactivate_request; |
| 155 | bool m_deactivate_request; |
| 156 | bool m_save_request; |
| 157 | bool m_test_request; |
| 158 | |
| 159 | std::unique_ptr<Savegame> m_savegame; |
| 160 | |
| 161 | private: |
| 162 | Sector* m_sector; |
| 163 | |
| 164 | bool m_levelloaded; |
| 165 | bool m_leveltested; |
| 166 | |
| 167 | TileSet* m_tileset; |
| 168 | |
| 169 | std::vector<std::unique_ptr<Widget> > m_widgets; |
| 170 | EditorOverlayWidget* m_overlay_widget; |
| 171 | EditorToolboxWidget* m_toolbox_widget; |
| 172 | EditorLayersWidget* m_layers_widget; |
| 173 | |
| 174 | bool m_enabled; |
| 175 | SurfacePtr m_bgr_surface; |
| 176 | |
| 177 | std::unique_ptr<UndoManager> m_undo_manager; |
| 178 | bool m_ignore_sector_change; |
| 179 | |
| 180 | private: |
| 181 | Editor(const Editor&) = delete; |
| 182 | Editor& operator=(const Editor&) = delete; |
| 183 | }; |
| 184 | |
| 185 | #endif |
| 186 | |
| 187 | /* EOF */ |
| 188 |