14 #define GETTEXT_DOMAIN "wesnoth-editor"
49 static std::vector<std::string> saved_windows_;
94 current_labels->
enable(
false);
96 current_labels->
enable(
true);
110 return (item ==
"editor-auto-update-transitions");
112 return (item ==
"editor-partial-update-transitions");
114 return (item ==
"editor-no-update-transitions");
120 std::vector<std::string> modified;
122 if (mc->modified()) {
123 if (!mc->get_filename().empty()) {
124 modified.push_back(mc->get_filename());
126 modified.push_back(
_(
"(New Map)"));
133 return modified.size();
138 , game_config_(game_config)
141 , last_map_generator_(nullptr)
142 , current_context_index_(0)
199 if(mru.empty() || index >= mru.size()) {
203 load_map(mru[index], !force_same_context);
231 gold, income, village_gold, village_support,
232 fog, shroud, share_vision,
233 controller, no_leader, hidden,
238 gold, income, village_gold, village_support,
239 fog, shroud, share_vision, controller, hidden, no_leader);
292 for (
unsigned int i = 0;
i < items.size(); ++
i) {
293 if (items[
i] ==
"editor-switch-map") {
294 items.erase(items.begin() +
i);
295 std::vector<std::string> contexts;
300 if (filename.empty()) {
302 filename =
_(
"(New Map)");
304 filename =
_(
"(New Scenario)");
306 std::string label =
"[" + std::to_string(mci) +
"] "
307 + filename + (changed ?
" [*]" :
"");
311 contexts.push_back(label);
313 items.insert(items.begin() +
i, contexts.begin(), contexts.end());
323 for (
unsigned int i = 0;
i < items.size(); ++
i) {
324 if (items[
i] !=
"EDITOR-LOAD-MRU-PLACEHOLDER") {
328 items.erase(items.begin() +
i);
331 items.insert(items.begin() +
i,
_(
"No Recent Files"));
343 items.insert(items.begin() +
i, mru.begin(), mru.end());
355 for (
unsigned int i = 0;
i < items.size(); ++
i) {
356 if (items[
i] ==
"editor-switch-area") {
357 items.erase(items.begin() +
i);
358 std::vector<std::string> area_entries;
360 std::vector<std::string> area_ids =
363 for (
size_t mci = 0; mci < area_ids.size(); ++mci) {
366 std::stringstream label;
367 label <<
"[" << mci+1 <<
"] ";
368 label << (area.empty() ?
_(
"(Unnamed Area)") : area);
374 area_entries.push_back(label.str());
377 items.insert(items.begin() +
i,
378 area_entries.begin(), area_entries.end());
386 for (
unsigned int i = 0;
i < items.size(); ++
i) {
387 if (items[
i] ==
"editor-switch-side") {
388 items.erase(items.begin() +
i);
389 std::vector<std::string> contexts;
395 std::stringstream label;
396 label <<
"[" << mci+1 <<
"] ";
397 label << (teamname.empty() ?
_(
"(New Side)") : teamname);
398 contexts.push_back(label.str());
401 items.insert(items.begin() +
i, contexts.begin(), contexts.end());
409 for (
unsigned int i = 0;
i < items.size(); ++
i) {
410 if (items[
i] ==
"editor-switch-time") {
411 items.erase(items.begin() +
i);
412 std::vector<std::string> times;
416 assert(tod_m !=
nullptr);
420 std::stringstream label;
421 if (!time.image.empty())
424 times.push_back(label.str());
427 items.insert(items.begin() +
i, times.begin(), times.end());
435 for (
unsigned int i = 0;
i < items.size(); ++
i) {
436 if (items[
i] ==
"editor-assign-local-time") {
437 items.erase(items.begin() +
i);
438 std::vector<std::string> times;
444 std::stringstream label;
445 if (!time.image.empty())
448 times.push_back(label.str());
451 items.insert(items.begin() +
i, times.begin(), times.end());
522 const std::set<map_location>& changed_locs =
585 WRN_ED <<
"Unknown resize expand direction" << std::endl;
616 if (input_name.empty()) {
621 int overwrite_res = 1;
623 input_name = old_input_name;
636 }
while (overwrite_res != 0);
644 if (input_name.empty()) {
649 int overwrite_res = 1;
651 input_name = old_input_name;
664 }
while (overwrite_res != 0);
673 if (!
i[
"map_generation"].empty() || !
i[
"scenario_generation"].empty()) {
675 const config &generator_cfg =
i.child(
"generator");
676 if (!generator_cfg) {
677 ERR_ED <<
"Scenario \"" <<
i[
"name"] <<
"\" with id " <<
i[
"id"]
678 <<
" has map_generation= but no [generator] tag";
691 _(
"No random map generators found."));
707 if (map_string.empty()) {
738 if(saved_windows_.empty()) {
746 for (
const std::string& filename : saved_windows_) {
750 saved_windows_.clear();
782 saved_windows_.clear();
786 if(auto_save_windows) {
788 std::ostringstream
s;
794 saved_windows_.push_back(name);
864 if (display_confirmation) {
878 if (display_confirmation) {
909 LOG_ED <<
"Load map: " << filename << (new_context ?
" (new)" :
" (same)") <<
"\n";
912 if (mc->get_filename() != filename) {
927 ERR_ED <<
"Internal error, map context filename changed: "
929 <<
" with no apparent scenario load\n";
932 symbols[
"old"] = filename;
953 if (filename.empty()) {
954 ERR_ED <<
"Empty filename in map revert" << std::endl;
994 if (index < 0 || static_cast<size_t>(index) >=
map_contexts_.size()) {
995 WRN_ED <<
"Invalid index in switch map context: " << index << std::endl;
1021 if(map_name.empty()){
map_labels * get_current_labels()
int auto_update_transitions()
bool write_scenario(bool display_confirmation=false)
int current_context_index_
child_itors child_range(const std::string &key)
void expand_areas_menu(std::vector< std::string > &items)
Menu expanding for the map's defined areas.
int show_file_chooser_dialog_save(CVideo &video, std::string &filename, std::string const &title, const std::string &default_file_name, bool show_directory_buttons, const std::string &type_a_head, int xloc, int yloc)
Show a filechooser dialog in a "save" mode, that is, without relying on autocomplete to allow saving ...
bool victory_defeated() const
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
char const IMG_TEXT_SEPARATOR
map_generator * get_selected_map_generator()
::tod_manager * tod_manager
void apply_mask_dialog()
Display an apply mask dialog and process user input.
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.
std::vector< std::string > recent_files()
Retrieves the list of recently opened files.
void edit_scenario_dialog()
Display a scenario edit dialog and process user input.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
game_classification * classification
int add_map_context(map_context *mc)
Add a map context.
const config & game_config_
const char * what() const
void change_display_context(const display_context *dc)
void replace_map_context(map_context *new_mc)
Replace the current map context and refresh accordingly.
void set_map_generators(std::vector< map_generator * > mg)
void new_map(int width, int height, const t_translation::t_terrain &fill, bool new_context)
Create a new map.
const mp_game_settings * mp_settings
void reload_map()
Reload the map after it has significantly changed (when e.g.
bool save_scenario()
Saves the scenario under the current filename.
void resize_map_dialog()
Display a load map dialog and process user input.
const t_terrain NONE_TERRAIN
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
void save_scenario_as_dialog()
Display a save map as dialog and process user input.
void rename_area_dialog()
Display an dialog to querry a new id for an [time_area].
static bool execute(std::string &id, std::string &name, std::string &description, int &turns, int &experience_modifier, bool &victory_when_enemies_defeated, bool &random_start_time, CVideo &video)
The execute function see tdialog for more information.
void refresh_after_action(bool drag_part=false)
Refresh the display after an action has been performed.
void init_flags()
Init the flag list and the team colors used by ~TC.
void expand_time_menu(std::vector< std::string > &items)
Menu expanding for the map's defined areas.
void set_area_id(int area_index, const std::string &id)
context_manager(editor_display &gui, const config &game_config)
map_labels & get_labels()
void save_map()
Save the map, open dialog if not named yet.
std::string default_dir_
Default directory for map load/save as dialogs.
std::string get_default_title_string()
void perform_refresh(const editor_action &action, bool drag_part=false)
Perform an action on the current map_context, then refresh the display.
static CVideo & get_singleton()
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
mp_game_settings & get_mp_settings()
size_t check_open_map(const std::string &fn) const
Check if a map is already open.
const std::string & get_filename() const
const std::vector< std::string > items
virtual void draw()
Draws invalidated items.
Replace contents of the entire map, Useful as a fallback undo method when something else would be imp...
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) ...
t_terrain read_terrain_code(const std::string &str, const t_layer filler)
Reads a single terrain from a string.
void set_needs_reload(bool value=true)
Setter for the reload flag.
map_context & get_map_context()
Get the current map context object.
const std::string & get_description() const
void refresh_all()
Refresh everything, i.e.
void set_scenario_setup(const std::string &id, const std::string &name, const std::string &description, int turns, int xp_mod, bool victory_defeated, bool random_time)
TODO.
void revert_map()
Revert the map by reloading it from disk.
const std::set< map_location > changed_locations() const
SHARE_VISION share_vision() const
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 set_side_setup(int side, const std::string &id, const std::string &name, int gold, int income, int village_gold, int village_support, bool fog, bool shroud, team::SHARE_VISION share_vision, team::CONTROLLER controller, bool hidden, bool no_leader)
TODO.
std::string default_dir()
overlay_map & get_overlays()
game_classification & get_classification()
void set_window_title(const std::string &title)
Sets the title of the main window.
static map_labels * current_labels
Object which defines a time of day with associated bonuses, image, sounds etc.
This class stores all the data for a single 'side' (in game nomenclature).
void close_current_context()
Closes the active map context.
static UNUSEDNOWARN std::string _(const char *str)
const std::string & get_name() const
tod_manager * get_time_manager()
static bool execute(const std::string &title, const std::string &label, std::string &text, CVideo &video)
Executes the dialog.
GLsizei const char ** path
Dialog is closed with ok button.
std::vector< map_generator * > map_generators_
Available random map generators.
std::map< std::string, t_string > string_map
std::vector< team > * teams
int village_support() const
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.
const t_string & user_team_name() const
std::string get_user_data_dir()
void select_map_generator(map_generator *mg)
void reset_starting_position_labels(display &disp)
void recalculate_minimap()
Schedule the minimap for recalculation.
Dialog is closed with the cancel button.
GLubyte GLubyte GLubyte GLubyte w
std::string base_name(const std::string &file)
Returns the base filename of a file, with directory name stripped.
void set_embedded(bool v)
int w() const
Effective map width.
void show_message(CVideo &video, const std::string &title, const std::string &message, const std::string &button_caption, const bool auto_close, const bool message_use_markup)
Shows a message to the user.
editor_map & get_map()
Map accessor.
virtual std::string create_map(boost::optional< boost::uint32_t > randomseed=boost::none)=0
Creates a new map and returns it.
GLboolean GLboolean GLboolean GLboolean a
The dialog for selecting which random generator to use in the editor.
void new_scenario_dialog()
Display a new map dialog and process user input.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
const std::string & team_name() const
void expand_open_maps_menu(std::vector< std::string > &items)
Menu expanding for open maps list.
bool save_map()
Saves the map under the current filename.
void enable(bool is_enabled)
void expand_local_time_menu(std::vector< std::string > &items)
Menu expanding for the map's defined areas.
Modify, read and display user preferences.
int show_file_chooser_dialog(CVideo &video, std::string &filename, std::string const &title, bool show_directory_buttons, const std::string &type_a_head, int xloc, int yloc)
Show a dialog where the user can navigate through files and select a file.
map_display and display: classes which take care of displaying the map and game-data on the screen...
map_context_refresher(context_manager &ec, const map_context &other_mc)
Manage the empty-palette in the editor.
std::string default_terrain
void perform_action(const editor_action &action)
Performs an action (thus modifying the map).
void invalidate_all()
Function to invalidate all tiles.
bool is_active_transitions_hotkey(const std::string &item)
Utility class to properly refresh the display when the map context object is replaced without duplica...
void switch_context(const int index, const bool force=false)
Switches the context to the one under the specified index.
std::string get_dir(const std::string &dir)
Paint the same terrain on a number of locations on the map.
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...
void load_map(const std::string &filename, bool new_context)
Load a map given the filename.
map_generator * create_map_generator(const std::string &name, const config &cfg)
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
Encapsulates the map of the game.
static bool execute(int &width, int &height, EXPAND_DIRECTION &expand_direction, bool ©_edge_terrain, CVideo &video)
The execute function see tdialog for more information.
void clear_changed_locations()
std::vector< team > & get_teams()
Get the team from the current map context object.
std::vector< map_context * > map_contexts_
The currently opened map context object.
std::vector< std::string > get_area_ids() const
This class adds extra editor-specific functionality to a normal gamemap.
int h() const
Effective map height.
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.
const t_translation::t_terrain & get_selected_bg_terrain()
void rebuild_terrain(const map_location &loc)
bool save_scenario_as(const std::string &filename)
unit_map & get_units()
Get the unit map from the current map context object.
Base class for all editor actions.
const std::string & get_map_data_key() const
GLfloat GLfloat GLfloat GLfloat h
const std::set< map_location > & get_area_by_index(int index) const
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...
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
size_t modified_maps(std::string &modified)
void create_mask_to_dialog()
Display an apply mask dialog and process user input.
Declarations for File-IO.
bool random_start_time() const
This class wraps around a map to provide a concise interface for the editor to work with...
const std::set< map_location > & selection() const
Return the selection set.
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
GLuint const GLchar * name
CONTROLLER controller() const
static std::string get_filename(const std::string &file_code)
map_generator * last_map_generator_
void reload_map()
Updates internals that cache map size.
void new_scenario(int width, int height, const t_translation::t_terrain &fill, bool new_context)
Create a new scenario.
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
boost::optional< boost::uint32_t > get_seed()
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
CVideo & video()
Gets the underlying screen object.
void set_filename(const std::string &fn)
GLsizei GLenum GLuint GLuint GLsizei char * message
int get_active_area() const
void generate_map_dialog()
Display a generate random map dialog and process user input.
GLint GLint GLint GLint GLint GLint GLsizei width
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.
static bool execute(int &width, int &height, CVideo &video)
The execute function see tdialog for more information.
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.
static bool execute(int side, std::string &team_name, std::string &user_team_name, int &gold, int &income, int &village_income, int &village_support, bool &fog, bool &shroud, team::SHARE_VISION &share_vision, team::CONTROLLER &controller, bool &no_leader, bool &hidden, CVideo &video)
The execute function see tdialog for more information.
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.
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
GLsizei const GLcharARB ** string
context_manager & context_manager_
Shows a yes and no button.
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
void rebuild_all()
Rebuild all dynamic terrain.
int number_of_turns() const
void replace_overlay_map(overlay_map *overlays)
void new_map_dialog()
Display a new map dialog and process user input.
const std::string & get_id() const