1 #ifndef BTANKS_EDITOR_H__ 2 #define BTANKS_EDITOR_H__ 3 4 /* Battle Tanks Game 5 * Copyright (C) 2006-2009 Battle Tanks team 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 /* 23 * Additional rights can be granted beyond the GNU General Public License 24 * on the terms provided in the Exception. If you modify this file, 25 * you may extend this exception to your version of the file, 26 * but you are not obligated to do so. If you do not wish to provide this 27 * exception without modification, you must delete this exception statement 28 * from your version and license this file solely under the GPL without exception. 29 */ 30 31 #include "sl08/sl08.h" 32 #include "sdlx/sdlx.h" 33 #include "sdlx/rect.h" 34 #include "menu/container.h" 35 #include "alarm.h" 36 #include <string> 37 #include <deque> 38 #include "command.h" 39 40 class OpenMapDialog; 41 class TilesetDialog; 42 class Hud; 43 class LayerListDialog; 44 class BaseBrush; 45 class AddObjectDialog; 46 class ObjectPropertiesDialog; 47 class ScrollList; 48 class MorphDialog; 49 class ResizeDialog; 50 51 namespace sdlx { 52 class Font; 53 class Surface; 54 } 55 class Object; 56 57 class Editor : public Container { 58 public: 59 Editor(); 60 void init(int argc, char **argv); 61 void run(); 62 void deinit(); 63 64 void loadMap(const std::string &map); 65 66 void addCommand(Command &cmd); 67 Command ¤tCommand(); 68 void undo(); 69 void redo(); 70 71 void moveObjectHack(Object *object, const v2<int>& screen_pos); 72 73 private: 74 virtual bool onKey(const SDL_keysym sym); //from ::Control 75 virtual bool onMouse(const int button, const bool pressed, const int x, const int y); 76 virtual bool onMouseMotion(const int state, const int x, const int y, const int xrel, const int yrel); 77 78 void render(sdlx::Surface &surface, const float dt); 79 80 //slots: 81 sl08::slot1<bool, float, Editor> on_tick_slot; 82 bool onTick(float dt); 83 84 sl08::slot2<bool, const SDL_keysym, const bool, Editor> on_key_slot; 85 bool onKeySignal(const SDL_keysym sym, const bool pressed); 86 87 sl08::slot4<bool, const int, const bool, const int, const int, Editor> on_mouse_slot; 88 bool onMouseSignal(const int button, const bool pressed, const int x, const int y); 89 90 sl08::slot5<bool, const int, const int, const int, const int, const int, Editor> on_mouse_motion_slot; 91 bool onMouseMotionSignal(const int state, const int x, const int y, const int xrel, const int yrel); 92 93 sl08::slot1<void, const SDL_Event &, Editor> on_event_slot; 94 void onEvent(const SDL_Event &event); 95 96 void displayStatusMessage(const Object *o); 97 void updateLayers(); 98 99 OpenMapDialog *_map_picker; 100 Hud *_hud; 101 TilesetDialog *_tileset_dialog; 102 LayerListDialog * _layers_dialog; 103 AddObjectDialog * _add_object; 104 ResizeDialog *_resize_map; 105 106 std::deque<std::pair<std::string, std::string> > _morph_boxes; 107 MorphDialog *_morph_dialog; 108 109 sdlx::Rect map_pos; 110 v2<float> map_dir; 111 v2<int> _tile_size; 112 std::string _map_base, _map_file; 113 114 int _loading_bar_total, _loading_bar_now; 115 116 //slots: 117 sl08::slot1<void, const int, Editor> reset_slot; 118 void resetLoadingBar(const int total); 119 sl08::slot2<void, const int, const char *, Editor> notify_slot; 120 void notifyLoadingBar(const int progress, const char *what); 121 122 int _current_layer_z; 123 BaseBrush *_brush; 124 v2<int> _last_tile_painted; 125 126 std::string _layer_name; 127 Alarm _layer_name_invisible, _layer_invisible; 128 const sdlx::Font *_small_font; 129 130 std::deque<Command> undo_queue, redo_queue; 131 132 bool _render_objects; 133 const Object *_highlight_object; 134 bool _dragging, _selecting; 135 v2<int> _selection1, _selection2; 136 137 v2<int> mouse_pos; 138 139 ObjectPropertiesDialog *_object_properties; 140 }; 141 142 #endif 143 144