The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
editor_controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Tomasz Sniatowski <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef EDITOR_EDITOR_CONTROLLER_HPP_INCLUDED
16 #define EDITOR_EDITOR_CONTROLLER_HPP_INCLUDED
17 
19 #include "editor/editor_main.hpp"
24 
25 #include "controller_base.hpp"
26 #include "help/help.hpp"
28 #include "mouse_handler_base.hpp"
29 #include "tooltips.hpp"
30 
31 #include "sound_music_track.hpp"
32 
33 class map_generator;
34 
35 namespace tooltips {
36 struct manager;
37 }
38 
39 namespace font {
41 }
42 
43 namespace editor {
44 
45 class editor_map;
46 
48 
49 enum menu_type {
50  MAP,
61 };
62 
63 /**
64  * The editor_controller class contains the mouse and keyboard event handling
65  * routines for the editor. It also serves as the main editor class with the
66  * general logic.
67  */
71  private boost::noncopyable,
73 {
74  public:
75  /**
76  * The constructor. A initial map context can be specified here, the controller
77  * will assume ownership and delete the pointer during destruction, but changes
78  * to the map can be retrieved between the main loop's end and the controller's
79  * destruction.
80  */
82 
84 
85  /** Editor main loop */
87 
88  /** Takes a screenshot **/
89  void do_screenshot(const std::string& screenshot_filename = "map_screenshot.bmp");
90 
91  /** Process a hotkey quit command */
92  void hotkey_quit();
93 
94  /** Show a quit confirmation dialog and returns true if the user pressed 'yes' */
95  bool quit_confirm();
96 
97  /** Display the settings dialog, used to control e.g. the lighting settings */
98  void custom_tods_dialog();
99 
100  /** Save the map, open dialog if not named yet. */
101  void save_map() {context_manager_->save_map();}
102 
103  /** command_executor override */
104  bool can_execute_command(const hotkey::hotkey_command& command, int index = -1) const;
105 
106  /** command_executor override */
108 
109  /** command_executor override */
110  bool execute_command(const hotkey::hotkey_command& command, int index = -1, bool press=true);
111 
112  /** controller_base override */
113  void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp);
114 
115  void show_help();
116  void status_table();
117 
118  /** Show the preferences dialog */
119  void preferences();
120 
121  /** Handle hotkeys to scroll map */
122  void scroll_up(bool on);
123  void scroll_down(bool on);
124  void scroll_left(bool on);
125  void scroll_right(bool on);
126 
127  /** Grid toggle */
128  void toggle_grid();
129 
130  void terrain_description();
131  void unit_description();
132  void change_unit_id();
133  void rename_unit();
134 
135  void unit_list();
136 
137  /** Copy the selection on the current map to the clipboard */
138  void copy_selection();
139 
140  /** Cut the selection from the current map to the clipboard */
141  void cut_selection();
142 
143  /** Export the WML-compatible list of selected tiles to the system clipboard */
145 
147 
148  /** Save the current selection to the active area. */
149  void save_area();
150 
151  /** Add a new area to the current context, filled with the selection if any. */
152  void add_area();
153 
154  /* mouse_handler_base overrides */
155  void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc = map_location::null_location());
156  editor_display& gui() { return *gui_; }
157  const editor_display& gui() const { return *gui_; }
158  bool allow_mouse_wheel_scroll(int x, int y);
159  bool right_click_show_menu(int x, int y, const bool browse);
160  bool left_click(int x, int y, const bool browse);
161  void left_drag_end(int x, int y, const bool browse);
162  void left_mouse_up(int x, int y, const bool browse);
163  bool right_click(int x, int y, const bool browse);
164  void right_drag_end(int x, int y, const bool browse);
165  void right_mouse_up(int x, int y, const bool browse);
166 
168 
169  protected:
170  /* controller_base overrides */
171  void process_keyup_event(const SDL_Event& event);
174 
175  /** Get the current mouse action */
177 
178  /**
179  * Perform an action, then delete the action object.
180  * The pointer can be nullptr, in which case nothing will happen.
181  */
182  void perform_delete(editor_action* action);
183 
184  /**
185  * Peform an action on the current map_context, then refresh the display
186  * and delete the pointer. The pointer can be nullptr, in which case nothing will happen.
187  */
188  void perform_refresh_delete(editor_action* action, bool drag_part = false);
189 
190 
191  virtual std::vector<std::string> additional_actions_pressed() override;
192 
193  private:
194 
195  /** init the display object and general set-up */
196  void init_gui();
197 
198  /** init the available time-of-day settings */
199  void init_tods(const config& game_config);
200 
201  /** init background music for the editor */
202  void init_music(const config& game_config);
203 
204  /** Load editor-specific tooltips */
205  void load_tooltips();
206 
207  /** Reload images */
208  void refresh_image_cache();
209 
210  /**
211  * Callback function passed to display to be called on each redraw_everything run.
212  * Redraws toolbar, brush bar and related items.
213  */
215 
216  /**
217  * Undos an action in the current map context
218  */
219  void undo();
220 
221  /**
222  * Redos an action in the current map context
223  */
224  void redo();
225 
227 
228  /** Reports object. Must be initialized before the gui_ */
229  boost::scoped_ptr<reports> reports_;
230 
231  /** The display object used and owned by the editor. */
232  boost::scoped_ptr<editor_display> gui_;
233 
234  /** Pre-defined time of day lighting settings for the settings dialog */
235  typedef std::map<std::string, std::pair<std::string ,std::vector<time_of_day> > > tods_map;
236  tods_map tods_;
237 
238  /* managers */
239  public:
240  boost::scoped_ptr<context_manager> context_manager_;
241  private:
242  boost::scoped_ptr<editor_toolkit> toolkit_;
244  boost::scoped_ptr<font::floating_label_context> floating_label_manager_;
245 
246  boost::scoped_ptr<help::help_manager> help_manager_;
247 
248  /** Quit main loop flag */
249  bool do_quit_;
251 
252  std::vector<sound::music_track> music_tracks_;
253 };
254 
255 } //end namespace editor
256 
257 #endif
void perform_refresh_delete(editor_action *action, bool drag_part=false)
Peform an action on the current map_context, then refresh the display and delete the pointer...
const editor_display & gui() const
Const version.
bool right_click_show_menu(int x, int y, const bool browse)
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
boost::scoped_ptr< editor_toolkit > toolkit_
void copy_selection()
Copy the selection on the current map to the clipboard.
void save_map()
Save the map, open dialog if not named yet.
editor_display & gui()
Reference to the used display objects.
tooltips::manager tooltip_manager_
void export_selection_coords()
Export the WML-compatible list of selected tiles to the system clipboard.
void do_screenshot(const std::string &screenshot_filename="map_screenshot.bmp")
Takes a screenshot.
bool right_click(int x, int y, const bool browse)
Overridden in derived classes, called on a right click (mousedown).
Graphical text output.
std::string get_left_button_function()
bool quit_confirm()
Show a quit confirmation dialog and returns true if the user pressed 'yes'.
bool left_click(int x, int y, const bool browse)
Overridden in derived classes, called on a left click (mousedown).
void custom_tods_dialog()
Display the settings dialog, used to control e.g.
editor_display & get_display()
Get a reference to a display member a derived class uses.
Definition: video.hpp:58
void redo()
Redos an action in the current map context.
void left_drag_end(int x, int y, const bool browse)
Called whenever the left mouse drag has "ended".
void save_area()
Save the current selection to the active area.
bool can_execute_command(const hotkey::hotkey_command &command, int index=-1) const
command_executor override
Stores all information related to functions that can be bound to hotkeys.
hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const
command_executor override
void add_area()
Add a new area to the current context, filled with the selection if any.
boost::scoped_ptr< font::floating_label_context > floating_label_manager_
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
controller_base framework: controller_base is roughly analogous to a "dialog" class in a GUI toolkit ...
boost::scoped_ptr< context_manager > context_manager_
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
void scroll_up(bool on)
Handle hotkeys to scroll map.
void load_tooltips()
Load editor-specific tooltips.
void right_drag_end(int x, int y, const bool browse)
Called whenever the right mouse drag has "ended".
void toggle_grid()
Grid toggle.
bool allow_mouse_wheel_scroll(int x, int y)
Derived classes can override this to disable mousewheel scrolling under some circumstances, e.g.
void init_tods(const config &game_config)
init the available time-of-day settings
Implements a quit confirmation dialog.
mouse_action * get_mouse_action()
Get the current mouse action.
void preferences()
Show the preferences dialog.
boost::scoped_ptr< reports > reports_
Reports object.
virtual hotkey::command_executor * get_hotkey_command_executor()
Get (optionally) a command executor to handle context menu events.
editor_controller(const config &game_config, CVideo &video)
The constructor.
void refresh_image_cache()
Reload images.
Manage the empty-palette in the editor.
Definition: action.cpp:28
void show_menu(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &disp)
controller_base override
void undo()
Undos an action in the current map context.
static const map_location & null_location()
Definition: location.hpp:195
boost::scoped_ptr< help::help_manager > help_manager_
Encapsulates the map of the game.
Definition: location.hpp:38
void process_keyup_event(const SDL_Event &event)
Process keyup (always).
boost::scoped_ptr< editor_display > gui_
The display object used and owned by the editor.
tooltips.
void init_gui()
init the display object and general set-up
Game configuration data as global variables.
Definition: build_info.cpp:38
GLuint index
Definition: glew.h:1782
structure which will hide all current floating labels, and cause floating labels instantiated after i...
Base class for all editor actions.
Definition: action_base.hpp:41
virtual std::vector< std::string > additional_actions_pressed() override
void cut_selection()
Cut the selection from the current map to the clipboard.
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
void left_mouse_up(int x, int y, const bool browse)
Called when the left mouse button is up.
void display_redraw_callback(display &)
Callback function passed to display to be called on each redraw_everything run.
std::vector< sound::music_track > music_tracks_
void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc=map_location::null_location())
Called when a mouse motion event takes place.
std::map< std::string, std::pair< std::string,std::vector< time_of_day > > > tods_map
Pre-defined time of day lighting settings for the settings dialog.
mouse_handler_base & get_mouse_handler_base()
Get a reference to a mouse handler member a derived class uses.
void perform_delete(editor_action *action)
Perform an action, then delete the action object.
bool do_quit_
Quit main loop flag.
EXIT_STATUS main_loop()
Editor main loop.
cl_event event
Definition: glew.h:3070
bool execute_command(const hotkey::hotkey_command &command, int index=-1, bool press=true)
command_executor override
void init_music(const config &game_config)
init background music for the editor
A mouse action receives events from the controller, and responds to them by creating an appropriate e...
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void hotkey_quit()
Process a hotkey quit command.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void right_mouse_up(int x, int y, const bool browse)
Called when the right mouse button is up.