The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
context_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[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 CONTEXT_MANAGER_HPP_INCLUDED
16 #define CONTEXT_MANAGER_HPP_INCLUDED
17 
21 class map_generator;
22 
23 namespace editor {
24 
26 
28 
29 public:
30 
31  bool is_active_transitions_hotkey(const std::string& item);
32 
33  size_t modified_maps(std::string& modified);
34 
38  }
39 
47  return true;
48  }
49  return false;
50  }
51 
52  bool clipboard_empty() {
53  return clipboard_.empty();
54  }
55 
57  return clipboard_;
58  }
59 
60  /** Fill the selection with the foreground terrain */
61  void fill_selection();
62 
63  /** Index into the map_contexts_ array */
66  }
67 
68 public:
71 
72  size_t open_maps(void) {
73  return map_contexts_.size();
74  }
75 
76  /**
77  * Perform an action on the current map_context, then refresh the display.
78  */
79  void perform_refresh(const editor_action& action, bool drag_part = false);
80 
81  /**
82  * Save all maps, open dialog if not named yet, except when using
83  * auto_save_windows which will name unnamed maps "windows_N".
84  * Also record all filenames for future reopening.
85  */
86  void save_all_maps(bool auto_save_windows = false);
87 
88  /** Save the map, open dialog if not named yet. */
89  void save_map();
90 
92  return gui_;
93  }
94 
95  /**
96  * Refresh everything, i.e. invalidate all hexes and redraw them. Does *not* reload the map.
97  */
98  void refresh_all();
99 
100  /** Display an apply mask dialog and process user input. */
101  void apply_mask_dialog();
102 
103  /** Display an apply mask dialog and process user input. */
104  void create_mask_to_dialog();
105 
106  /** Display an dialog to querry a new id for an [time_area] */
107  void rename_area_dialog();
108 
109  /** Menu expanding for open maps list */
110  void expand_open_maps_menu(std::vector<std::string>& items);
111 
112  /** Menu expanding for most recent loaded list */
113  void expand_load_mru_menu(std::vector<std::string>& items);
114 
115  /** Menu expanding for the map's player sides */
116  void expand_sides_menu(std::vector<std::string>& items);
117 
118  /** Menu expanding for the map's defined areas */
119  void expand_areas_menu(std::vector<std::string>& items);
120 
121  /** Menu expanding for the map's defined areas */
122  void expand_time_menu(std::vector<std::string>& items);
123 
124  /** Menu expanding for the map's defined areas */
125  void expand_local_time_menu(std::vector<std::string>& items);
126 
127  /** Display a load map dialog and process user input. */
128  void load_map_dialog(bool force_same_context = false);
129 
130  /** Open the specified entry from the recent files list. */
131  void load_mru_item(unsigned index, bool force_same_context = false);
132 
133  /** Display a scenario edit dialog and process user input. */
134  void edit_scenario_dialog();
135 
136  /** TODO */
137  void edit_side_dialog(int side);
138 
139  /** Display a new map dialog and process user input. */
140  void new_map_dialog();
141 
142  /** Display a new map dialog and process user input. */
143  void new_scenario_dialog();
144 
145  /** Display a save map as dialog and process user input. */
146  void save_map_as_dialog();
147 
148  /** Display a save map as dialog and process user input. */
150 
151  /** Display a generate random map dialog and process user input. */
152  void generate_map_dialog();
153 
154  /** Display a load map dialog and process user input. */
155  void resize_map_dialog();
156 
157  size_t size() {
158  return map_contexts_.size();
159  }
160 
161  /** Get the current map context object */
164  }
165  /** Get the map from the current map context object - const version*/
166  const editor_map& get_map() const {
167  return get_map_context().get_map();
168  }
169 
170  /** Set the default dir (where the filebrowser is pointing at when there is no map file opened) */
171  void set_default_dir(const std::string& str);
172 
173 private:
174 
175  /**
176  * Replace the current map context and refresh accordingly
177  */
178  void replace_map_context(map_context* new_mc);
179  /** init available random map generators */
181 
182  /**
183  * Shows an are-you-sure dialog if the map was modified.
184  * @return true if the user confirmed or the map was not modified, false otherwise
185  */
186  bool confirm_discard();
187 
188  /** Get the current map context object - const version */
189  const map_context& get_map_context() const {
191  }
192 
193 
194  /**
195  * Add a map context. The controller assumes ownership.
196  * @return the index of the added map context in the map_contexts_ array
197  */
198  int add_map_context(map_context* mc);
199 
200  /**
201  * Creates a default map context object, used to ensure there is always at least one.
202  * Except when we saved windows, in which case reopen them
203  */
204  void create_default_context();
205 
206 public:
207  /**
208  * Refresh the display after an action has been performed.
209  * The map context contains details of what needs to be refreshed.
210  */
211  void refresh_after_action(bool drag_part = false);
212 
213  /** Get the map from the current map context object */
215  return get_map_context().get_map();
216  }
217 
218  /** Closes the active map context. Switches to a valid context afterward or creates a dummy one. */
219  void close_current_context();
220 
221  /** Switches the context to the one under the specified index. */
222  void switch_context(const int index, const bool force = false);
223 
224 private:
225  /**
226  * Save the map under a given filename.
227  * @return true on success
228  */
229  bool save_map_as(const std::string& filename);
230  //TODO
231  bool save_scenario_as(const std::string& filename);
232 
233  /**
234  * Save the map under a given filename. Displays an error message on failure.
235  * @return true on success
236  */
237  bool write_map(bool display_confirmation = false);
238  bool write_scenario(bool display_confirmation = false);
239 
240  /**
241  * Create a new map.
242  */
243  void new_map(int width, int height, const t_translation::t_terrain & fill,
244  bool new_context);
245 
246  /**
247  * Create a new scenario.
248  */
249  void new_scenario(int width, int height, const t_translation::t_terrain & fill,
250  bool new_context);
251 
252  /**
253  * Check if a map is already open.
254  * @return index of the map context containing the given filename,
255  * or map_contexts_.size() if not found.
256  */
257  size_t check_open_map(const std::string& fn) const;
258 
259  /**
260  * Check if a map is already open. If yes, switch to it
261  * and return true, return false otherwise.
262  */
263  bool check_switch_open_map(const std::string& fn);
264 
265  /**
266  * Displays the specified map name in the window titlebar
267  */
268  void set_window_title();
269 public:
270  /**
271  * Load a map given the filename
272  */
273  void load_map(const std::string& filename, bool new_context);
274 
275  /**
276  * Revert the map by reloading it from disk
277  */
278  void revert_map();
279 
280  /**
281  * Reload the map after it has significantly changed (when e.g. the dimensions changed).
282  * This is necessary to avoid issues with parts of the map being cached in the display class.
283  */
284  void reload_map();
285 
286 private:
287 
289 
291 
292  /** Default directory for map load/save as dialogs */
294 
295  /** Available random map generators */
296  std::vector<map_generator*> map_generators_;
298 
300 
301  /** Flag to rebuild terrain on every terrain change */
303 
304 
305  /** The currently opened map context object */
306  std::vector<map_context*> map_contexts_;
307 
308  /** Clipboard map_fragment -- used for copy-paste. */
310 };
311 
312 }
313 
314 #endif
map_labels * get_current_labels()
bool write_scenario(bool display_confirmation=false)
void expand_areas_menu(std::vector< std::string > &items)
Menu expanding for the map's defined areas.
void apply_mask_dialog()
Display an apply mask dialog and process user input.
A map fragment – a collection of locations and information abut them.
bool check_switch_open_map(const std::string &fn)
Check if a map is already open.
int auto_update_transitions_
Flag to rebuild terrain on every terrain change.
int current_context_index()
Index into the map_contexts_ array.
void edit_scenario_dialog()
Display a scenario edit dialog and process user input.
int add_map_context(map_context *mc)
Add a map context.
void replace_map_context(map_context *new_mc)
Replace the current map context and refresh accordingly.
void new_map(int width, int height, const t_translation::t_terrain &fill, bool new_context)
Create a new map.
void reload_map()
Reload the map after it has significantly changed (when e.g.
void resize_map_dialog()
Display a load map dialog and process user input.
void save_scenario_as_dialog()
Display a save map as dialog and process user input.
map_fragment clipboard_
Clipboard map_fragment – used for copy-paste.
void rename_area_dialog()
Display an dialog to querry a new id for an [time_area].
void refresh_after_action(bool drag_part=false)
Refresh the display after an action has been performed.
void expand_time_menu(std::vector< std::string > &items)
Menu expanding for the map's defined areas.
context_manager(editor_display &gui, const config &game_config)
void save_map()
Save the map, open dialog if not named yet.
General purpose widgets.
std::string default_dir_
Default directory for map load/save as dialogs.
void perform_refresh(const editor_action &action, bool drag_part=false)
Perform an action on the current map_context, then refresh the display.
size_t check_open_map(const std::string &fn) const
Check if a map is already open.
const std::vector< std::string > items
editor_map & get_map()
Get the map from the current map context object.
GLenum mode
Definition: glew.h:2390
bool confirm_discard()
Shows an are-you-sure dialog if the map was modified.
void set_default_dir(const std::string &str)
Set the default dir (where the filebrowser is pointing at when there is no map file opened) ...
map_context & get_map_context()
Get the current map context object.
void refresh_all()
Refresh everything, i.e.
void revert_map()
Revert the map by reloading it from disk.
void edit_side_dialog(int side)
TODO.
const editor_map & get_map() const
Get the map from the current map context object - const version.
void close_current_context()
Closes the active map context.
std::vector< map_generator * > map_generators_
Available random map generators.
void expand_sides_menu(std::vector< std::string > &items)
Menu expanding for the map's player sides.
void load_map_dialog(bool force_same_context=false)
Display a load map dialog and process user input.
editor_map & get_map()
Map accessor.
Definition: map_context.hpp:75
void set_auto_update_transitions(int value)
void new_scenario_dialog()
Display a new map dialog and process user input.
void expand_open_maps_menu(std::vector< std::string > &items)
Menu expanding for open maps list.
void expand_local_time_menu(std::vector< std::string > &items)
Menu expanding for the map's defined areas.
Manage the empty-palette in the editor.
Definition: action.cpp:28
map_fragment & get_clipboard()
bool is_active_transitions_hotkey(const std::string &item)
void switch_context(const int index, const bool force=false)
Switches the context to the one under the specified index.
void expand_load_mru_menu(std::vector< std::string > &items)
Menu expanding for most recent loaded list.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
void load_map(const std::string &filename, bool new_context)
Load a map given the filename.
std::vector< map_context * > map_contexts_
The currently opened map context object.
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
void fill_selection()
Fill the selection with the foreground terrain.
void save_map_as_dialog()
Display a save map as dialog and process user input.
bool write_map(bool display_confirmation=false)
Save the map under a given filename.
Game configuration data as global variables.
Definition: build_info.cpp:38
bool save_scenario_as(const std::string &filename)
GLuint index
Definition: glew.h:1782
editor_display & gui()
Base class for all editor actions.
Definition: action_base.hpp:41
void save_all_maps(bool auto_save_windows=false)
Save all maps, open dialog if not named yet, except when using auto_save_windows which will name unna...
size_t modified_maps(std::string &modified)
void create_mask_to_dialog()
Display an apply mask dialog and process user input.
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:41
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
map_generator * last_map_generator_
void new_scenario(int width, int height, const t_translation::t_terrain &fill, bool new_context)
Create a new scenario.
void generate_map_dialog()
Display a generate random map dialog and process user input.
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
void set_window_title()
Displays the specified map name in the window titlebar.
void create_default_context()
Creates a default map context object, used to ensure there is always at least one.
bool save_map_as(const std::string &filename)
Save the map under a given filename.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void init_map_generators(const config &game_config)
init available random map generators
void load_mru_item(unsigned index, bool force_same_context=false)
Open the specified entry from the recent files list.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void set_update_trasitions_mode(int mode)
const map_context & get_map_context() const
Get the current map context object - const version.
void new_map_dialog()
Display a new map dialog and process user input.