00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EDITOR_H_INCLUDED
00019 #define EDITOR_H_INCLUDED
00020
00021 #include "global.hpp"
00022
00023 #include "SDL.h"
00024
00025 #include "editor_palettes.hpp"
00026 #include "editor_layout.hpp"
00027 #include "editor_undo.hpp"
00028 #include "map_manip.hpp"
00029
00030 #include "../display.hpp"
00031 #include "../events.hpp"
00032 #include "../font.hpp"
00033 #include "../hotkeys.hpp"
00034 #include "../preferences_display.hpp"
00035 #include "../theme.hpp"
00036 #include "../tooltips.hpp"
00037
00038
00039
00040 #include <map>
00041 #include <queue>
00042 #include <set>
00043 #include <vector>
00044
00045 namespace map_editor {
00046
00047 bool check_data(std::string &data, std::string &filename, bool &from_scenario, config &game_cfg);
00048
00049
00050 class map_editor : public events::handler,
00051 public hotkey::command_executor {
00052 public:
00053 map_editor(editor_display &gui, editormap &map, config &theme, config &game_config);
00054 virtual ~map_editor();
00055
00056
00057
00058 void main_loop();
00059
00060
00061 void set_file_to_save_as(const std::string, bool from_scenario);
00062
00063
00064
00065
00066
00067
00068
00069 enum ABORT_MODE {DONT_ABORT, ABORT_NORMALLY, ABORT_HARD};
00070
00071
00072
00073 void set_abort(const ABORT_MODE abort=ABORT_NORMALLY);
00074
00075
00076
00077
00078
00079 bool save_map(const std::string filename="",
00080 const bool display_confirmation=true);
00081
00082
00083 struct load_map_exception {};
00084
00085 virtual void handle_event(const SDL_Event &event);
00086
00087
00088
00089 void handle_keyboard_event(const SDL_KeyboardEvent &event,
00090 const int mousex, const int mousey);
00091
00092
00093
00094 void handle_mouse_button_event(const SDL_MouseButtonEvent &event,
00095 const int mousex, const int mousey);
00096
00097
00098
00099 bool changed_since_save() const;
00100
00101
00102 void redraw_everything();
00103
00104
00105 virtual void change_language();
00106
00107
00108
00109 virtual void toggle_grid();
00110 virtual void undo();
00111 virtual void redo();
00112 virtual void preferences();
00113 virtual void edit_quit();
00114 virtual void edit_new_map();
00115 virtual void edit_load_map();
00116 virtual void edit_save_map();
00117 virtual void edit_save_as();
00118
00119
00120 virtual void edit_set_start_pos();
00121 virtual void edit_flood_fill();
00122 virtual void edit_fill_selection();
00123 virtual void edit_rotate_selection();
00124 virtual void edit_cut();
00125 virtual void edit_copy();
00126 virtual void edit_paste();
00127 virtual void edit_revert();
00128 virtual void edit_resize();
00129 virtual void edit_flip();
00130
00131
00132 virtual void edit_select_all();
00133 virtual void edit_draw();
00134 virtual void edit_refresh();
00135 virtual void edit_update();
00136 virtual void edit_auto_update();
00137
00138 void perform_flood_fill(const t_translation::t_terrain fill_with);
00139 void perform_paste();
00140 void perform_set_starting_pos();
00141
00142 virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command, int) const;
00143
00144 virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command) const;
00145
00146
00147
00148 struct new_map_exception {
00149 new_map_exception(const std::string &map, const std::string filename="", const bool scenario = false)
00150 : new_map(map), new_filename(filename), from_scenario(scenario) {}
00151 const std::string new_map;
00152 const std::string new_filename;
00153 const bool from_scenario;
00154 };
00155
00156 private:
00157
00158 enum LEFT_BUTTON_HELD_FUNC {DRAW_TERRAIN, DRAW_TERRAIN_LAYER, ADD_SELECTION, REMOVE_SELECTION,
00159 MOVE_SELECTION, NONE};
00160
00161
00162 enum LEFT_BUTTON_FUNC {DRAW, SELECT_HEXES, FLOOD_FILL,
00163 SET_STARTING_POSITION, PASTE, NUM_L_BUTTON_FUNC};
00164
00165
00166
00167 void left_button_down(const int mousex, const int mousey);
00168
00169
00170 void left_click(const gamemap::location loc);
00171
00172
00173
00174 void right_button_down(const int mousex, const int mousey);
00175
00176
00177 void right_click(const gamemap::location loc);
00178
00179
00180
00181 void middle_button_down(const int mousex, const int mousey);
00182
00183
00184
00185
00186
00187 bool confirm_exit_and_save();
00188
00189
00190
00191 void set_starting_position(const int player, const gamemap::location loc);
00192
00193
00194 bool verify_filename(const std::string& filename, bool show_error) const;
00195
00196
00197 void show_menu(const std::vector<std::string>& items_arg, const int xloc,
00198 const int yloc, const bool context_menu=false);
00199
00200
00201
00202
00203 void execute_command(const hotkey::HOTKEY_COMMAND command);
00204
00205
00206
00207 void draw_terrain(const t_translation::t_terrain terrain,
00208 const std::vector<gamemap::location> &hexes, const bool one_layer_only);
00209
00210
00211
00212
00213 void recalculate_starting_pos_labels();
00214
00215
00216
00217 void update_mouse_over_hexes(const gamemap::location mouse_over_hex);
00218
00219
00220 void insert_selection_in_clipboard();
00221
00222
00223 void perform_fill_hexes(std::set<gamemap::location> &fill_hexes,
00224 const t_translation::t_terrain terrain, map_undo_action &undo_action);
00225
00226
00227 void perform_selection_move();
00228
00229
00230
00231
00232
00233 void highlight_selected_hexes(const bool clear_old=true);
00234
00235
00236
00237
00238 void clear_highlighted_hexes_in_gui();
00239
00240
00241 void set_mouseover_overlay();
00242
00243 void reset_mouseover_overlay() { gui_.clear_mouseover_hex_overlay(); }
00244
00245
00246
00247 void terrain_changed(const gamemap::location &hex);
00248
00249
00250
00251
00252
00253 void save_undo_action(const map_undo_action &action);
00254
00255
00256
00257
00258 void left_button_func_changed(const LEFT_BUTTON_FUNC func);
00259
00260
00261
00262
00263 void update_l_button_palette();
00264
00265
00266
00267 std::string get_action_name(const LEFT_BUTTON_FUNC func) const;
00268
00269
00270
00271 bool is_left_button_func_menu(const theme::menu &menu) const;
00272
00273
00274
00275 void draw_on_mouseover_hexes(const t_translation::t_terrain t, const bool one_layer_only = false);
00276
00277
00278 void load_tooltips(void);
00279
00280
00281
00282
00283 struct buffer_item {
00284 buffer_item(const gamemap::location &o, t_translation::t_terrain t, int start_side) :
00285 offset(o), terrain(t), starting_side(start_side) {}
00286 gamemap::location offset;
00287 t_translation::t_terrain terrain;
00288 int starting_side;
00289 };
00290
00291
00292 typedef std::vector<buffer_item> map_buffer;
00293
00294 void copy_buffer(map_buffer& buffer, const std::set<gamemap::location> &locs,
00295 const gamemap::location &origin);
00296 void paste_buffer(const map_buffer& buffer, const gamemap::location &loc,
00297 map_undo_action &undo_action);
00298 void clear_buffer(map_buffer& buffer) {buffer.clear();};
00299
00300 editor_display &gui_;
00301 editormap &map_;
00302 std::string filename_, original_filename_;
00303 bool from_scenario_;
00304 ABORT_MODE abort_;
00305
00306
00307
00308 static int num_operations_since_save_;
00309 size_specs size_specs_;
00310 config &theme_;
00311 config &game_config_;
00312 CKey key_;
00313 gamemap::location selected_hex_;
00314
00315
00316
00317 bool map_dirty_;
00318 bool auto_update_;
00319 bool l_button_palette_dirty_;
00320 bool everything_dirty_;
00321 terrain_palette palette_;
00322 brush_bar brush_;
00323 std::vector<gamemap::location> starting_positions_;
00324 std::set<gamemap::location> mouse_over_hexes_;
00325 std::set<gamemap::location> selected_hexes_;
00326 map_buffer clipboard_;
00327
00328 LEFT_BUTTON_HELD_FUNC l_button_held_func_;
00329 gamemap::location selection_move_start_;
00330
00331 tooltips::manager tooltip_manager_;
00332 font::floating_label_context floating_label_manager_;
00333
00334
00335 bool mouse_moved_;
00336 bool highlighted_locs_cleared_;
00337 const hotkey::manager hotkey_manager_;
00338 const preferences::display_manager prefs_disp_manager_;
00339 static config prefs_;
00340 static config hotkeys_;
00341 static bool first_time_created_;
00342 static LEFT_BUTTON_FUNC l_button_func_;
00343 static t_translation::t_terrain old_fg_terrain_, old_bg_terrain_;
00344 static int old_brush_size_;
00345 bool all_hexes_selected_;
00346
00347 };
00348
00349 }
00350
00351 #endif // EDITOR_H_INCLUDED
00352