16 #define GETTEXT_DOMAIN "wesnoth-editor" 59 std::ostringstream ss;
63 ss <<
"color='#f00' ";
73 , game_config_(game_config)
76 , last_map_generator_(nullptr)
77 , current_context_index_(0)
109 if (
gui().get_teams().
size() > 0) {
132 for(
const auto& loc :
get_map_context().map().special_locations().left) {
139 for(
size_t i = 10;
i <= n_teams;
i++) {
158 return (item ==
"editor-auto-update-transitions");
160 return (item ==
"editor-partial-update-transitions");
162 return (item ==
"editor-no-update-transitions");
182 std::vector<std::string> modified;
185 if(!mc->get_name().empty()) {
186 modified.push_back(mc->get_name());
187 }
else if(!mc->get_filename().empty()) {
188 modified.push_back(mc->get_filename());
190 modified.push_back(mc->get_default_context_name());
195 for(std::string& str : modified) {
199 return modified.size();
222 if(mru.empty() || index >= mru.size()) {
226 load_map(mru[index], !force_same_context);
235 if(gui2::dialogs::editor_edit_side::execute(team_info)) {
247 std::string
id = context.
get_id();
248 std::string name = context.
get_name();
257 const bool ok = gui2::dialogs::editor_edit_scenario::execute(
258 id, name, description, turns, xp_mod, victory, random
279 if(gui2::dialogs::editor_new_map::execute(
_(
"New Map"), w, h)) {
292 if(gui2::dialogs::editor_new_map::execute(
_(
"New Scenario"), w, h)) {
300 auto pos = items.erase(items.begin() +
i);
301 std::vector<config> contexts;
303 for(std::size_t mci = 0; mci <
map_contexts_.size(); ++mci) {
306 std::string filename;
313 if(filename.empty()) {
317 std::ostringstream ss;
318 ss <<
"[" << mci + 1 <<
"] ";
323 ss <<
"<i>" << filename <<
"</i>";
332 const std::string
label = ss.str();
335 contexts.emplace_back(
"label", label,
"details", details);
338 items.insert(pos, contexts.begin(), contexts.end());
345 auto pos = items.erase(items.begin() +
i);
348 items.insert(pos,
config {
"label",
_(
"No Recent Files")});
352 for(std::string&
path : mru) {
359 std::vector<config> temp;
360 std::transform(mru.begin(), mru.end(), std::back_inserter(temp), [](
const std::string& str) {
361 return config {
"label", str};
364 items.insert(pos, temp.begin(), temp.end());
374 auto pos = items.erase(items.begin() +
i);
375 std::vector<config> area_entries;
377 std::vector<std::string> area_ids = tod->
get_area_ids();
379 for(std::size_t mci = 0; mci < area_ids.size(); ++mci) {
380 const std::string& area = area_ids[mci];
382 std::stringstream ss;
383 ss <<
"[" << mci + 1 <<
"] ";\
386 ss <<
"<i>" <<
_(
"Unnamed Area") <<
"</i>";
395 const std::string
label = ss.str();
398 area_entries.emplace_back(
"label", label,
"details", details);
401 items.insert(pos, area_entries.begin(), area_entries.end());
406 auto pos = items.erase(items.begin() +
i);
407 std::vector<config> contexts;
413 std::stringstream
label;
414 label <<
"[" << mci+1 <<
"] ";
416 if(teamname.empty()) {
417 label <<
"<i>" <<
_(
"New Side") <<
"</i>";
422 contexts.emplace_back(
"label", label.str());
425 items.insert(pos, contexts.begin(), contexts.end());
430 auto pos = items.erase(items.begin() +
i);
431 std::vector<config> times;
435 assert(tod_m !=
nullptr);
439 "details", time.name,
444 items.insert(pos, times.begin(), times.end());
449 auto pos = items.erase(items.begin() +
i);
450 std::vector<config> times;
456 "details", time.name,
461 items.insert(pos, times.begin(), times.end());
502 if(gui2::dialogs::edit_text::execute(
N_(
"Rename Area"),
N_(
"Identifier:"), name)) {
583 if(!gui2::dialogs::editor_resize_map::execute(w, h, dir, copy)) {
587 if(w != map.
w() || h != map.
h()) {
593 int x_offset = map.
w() -
w;
594 int y_offset = map.
h() -
h;
613 WRN_ED <<
"Unknown resize expand direction";
645 if(input_name.empty()) {
666 if(input_name.empty()) {
687 if(
i[
"map_generation"].empty() &&
i[
"scenario_generation"].empty()) {
692 if(
const auto generator_cfg =
i.optional_child(
"generator")) {
695 ERR_ED <<
"Scenario \"" <<
i[
"name"] <<
"\" with id " <<
i[
"id"]
696 <<
" has map_generation= but no [generator] tag";
712 std::string map_string;
721 if(map_string.empty()) {
753 saved_windows_.clear();
757 if(auto_save_windows) {
759 std::ostringstream
s;
765 saved_windows_.push_back(name);
840 if(display_confirmation) {
855 if(display_confirmation) {
894 LOG_ED <<
"Load map: " << filename << (new_context ?
" (new)" :
" (same)");
898 if(mc->get_filename() != filename) {
913 const std::string&
msg =
_(
"Loaded embedded map data");
918 ERR_ED <<
"Internal error, map context filename changed: " 920 <<
" with no apparent scenario load";
923 symbols[
"old"] = filename;
924 const std::string&
msg =
_(
"Loaded referenced map file:\n$new");
946 if(filename.empty()) {
947 ERR_ED <<
"Empty filename in map revert";
990 template<
typename... T>
1003 template<
typename... T>
1018 if(saved_windows_.empty()) {
1025 for(
const std::string& filename : saved_windows_) {
1029 saved_windows_.clear();
1052 if(index < 0 || static_cast<std::size_t>(index) >=
map_contexts_.size()) {
1053 WRN_ED <<
"Invalid index in switch map context: " <<
index;
int auto_update_transitions()
bool write_scenario(bool display_confirmation=false)
int current_context_index_
Dialog was closed with the CANCEL button.
void set_side_setup(editor_team_info &info)
TODO.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
const std::string & get_name() const
::tod_manager * tod_manager
void apply_mask_dialog()
Display an apply mask dialog and process user input.
std::size_t check_open_map(const std::string &fn) const
Check if a map is already open.
bool check_switch_open_map(const std::string &fn)
Check if a map is already open.
std::unique_ptr< map_context > context_ptr
std::size_t modified_maps(std::string &modified)
int auto_update_transitions_
Flag to rebuild terrain on every terrain change.
const t_translation::terrain_code & get_selected_bg_terrain()
std::vector< std::string > recent_files()
Retrieves the list of recently opened files.
const terrain_code NONE_TERRAIN
void edit_scenario_dialog()
Display a scenario edit dialog and process user input.
std::map< std::string, t_string > string_map
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
file_dialog & set_extension(const std::string &value)
Sets the default file extension for file names in save mode.
game_classification * classification
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
void set_window_title(const std::string &title)
Sets the title of the main window.
void change_display_context(const display_context *dc)
void replace_map_context_with(context_ptr &&mc)
std::vector< context_ptr > map_contexts_
The currently opened map context object.
void new_side()
Adds a new side to the map.
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.
void set_playing_team(std::size_t team)
set_playing_team sets the team whose turn it currently is
config_array_view child_range(config_key_type key) const
std::optional< uint32_t > get_seed()
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].
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.
const std::string & get_filename() const
void set_area_id(int area_index, const std::string &id)
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.
const std::vector< std::string > items
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
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.
file_dialog & set_save_mode(bool value)
Sets the dialog's behavior on non-existent file name inputs.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
int add_map_context(const T &... args)
Add a map context.
Replace contents of the entire map, Useful as a fallback undo method when something else would be imp...
static std::string _(const char *str)
bool show(const unsigned auto_close_time=0)
Shows the window.
bool confirm_discard()
Shows an are-you-sure dialog if the map was modified.
void set_needs_reload(bool value=true)
Setter for the reload flag.
map_context & get_map_context()
Get the current map context object.
void refresh_all()
Refresh everything, i.e.
int add_map_context_of(context_ptr &&mc)
map_generator * get_selected_map_generator()
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.
static bfs::path get_dir(const bfs::path &dirpath)
void revert_map()
Revert the map by reloading it from disk.
const std::string & get_id() const
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
void expand_areas_menu(std::vector< config > &items, int i)
Menu expanding for the map's defined areas.
std::string path() const
Gets the current file selection.
std::string default_dir()
game_classification & get_classification()
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.
std::string label
What to show in the filter's drop-down list.
int w() const
Effective map width.
const std::set< map_location > & selection() const
Return the selection set.
void load_map_dialog(bool force_same_context=false)
Display a load map dialog and process user input.
std::string get_user_data_dir()
void reset_starting_position_labels(display &disp)
void recalculate_minimap()
Schedule the minimap for recalculation.
void select_map_generator(map_generator *mg)
filter_context * filter_con
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
void set_embedded(bool v)
const game_config_view & game_config_
const std::set< map_location > changed_locations() const
void set_auto_update_transitions(int value)
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.
bool random_start_time() const
bool save_map()
Saves the map under the current filename.
void enable(bool is_enabled)
Modify, read and display user preferences.
Shows a yes and no button.
map_display and display: classes which take care of displaying the map and game-data on the screen...
void refresh_on_context_change()
Performs the necessary housekeeping necessary when switching contexts.
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).
const char * what() const noexcept
void invalidate_all()
Function to invalidate all tiles.
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 new_scenario(int width, int height, const t_translation::terrain_code &fill, bool new_context)
Create a new scenario.
Paint the same terrain on a number of locations on the map.
void new_map(int width, int height, const t_translation::terrain_code &fill, bool new_context)
Create a new map.
int number_of_turns() const
void load_map(const std::string &filename, bool new_context)
Load a map given the filename.
std::vector< std::string > get_area_ids() const
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
Encapsulates the map of the game.
class location_palette * locs_
const std::string & get_description() const
void clear_changed_locations()
This class adds extra editor-specific functionality to a normal gamemap.
map_generator * create_map_generator(const std::string &name, const config &cfg, const config *vars)
void add_item(const std::string &id)
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.
void expand_local_time_menu(std::vector< config > &items, int i)
Menu expanding for the map's defined areas.
void rebuild_terrain(const map_location &loc)
bool save_scenario_as(const std::string &filename)
const tod_manager * get_time_manager() const
static map_location::DIRECTION s
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
Base class for all editor actions.
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...
const std::string & get_map_data_key() const
void create_mask_to_dialog()
Display an apply mask dialog and process user input.
Declarations for File-IO.
This class wraps around a map to provide a concise interface for the editor to work with...
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
const std::string unicode_bullet
void replace_map_context(const T &... args)
Replace the current map context and refresh accordingly.
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
context_manager(editor_display &gui, const game_config_view &game_config)
void set_team(std::size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
void expand_sides_menu(std::vector< config > &items, int i)
Menu expanding for the map's player sides.
bool victory_defeated() const
static std::string get_filename(const std::string &file_code)
map_generator * last_map_generator_
bool toggle_update_transitions()
void edit_side_dialog(int side_index)
Display a side edit dialog and process user input.
void reload_map()
Updates internals that cache map size.
virtual const editor_map & map() const override
Const map accessor.
int get_active_area() const
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
std::optional< int > get_xp_mod() const
std::vector< std::unique_ptr< map_generator > > map_generators_
Available random map generators.
void set_filename(const std::string &fn)
void expand_load_mru_menu(std::vector< config > &items, int i)
Menu expanding for most recent loaded list.
const std::set< map_location > & get_area_by_index(int index) const
void init_map_generators(const game_config_view &game_config)
init available random map generators
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
void generate_map_dialog()
Display a generate random map dialog and process user input.
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.
The dialog for selecting which random generator to use in the editor.
bool save_map_as(const std::string &filename)
Save the map under a given filename.
void expand_time_menu(std::vector< config > &items, int i)
Menu expanding for the map's defined areas.
A config object defines a single node in a WML file, with access to child nodes.
virtual std::string create_map(std::optional< uint32_t > randomseed={})=0
Creates a new map and returns it.
void load_mru_item(unsigned index, bool force_same_context=false)
Open the specified entry from the recent files list.
virtual const std::vector< team > & teams() const override
Const teams accessor.
int h() const
Effective map height.
static std::vector< std::string > saved_windows_
static const std::string get_menu_marker(const bool changed)
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void expand_open_maps_menu(std::vector< config > &items, int i)
Menu expanding for open maps list.
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
const t_string & user_team_name() const
std::pair< std::string, unsigned > item
const t_string get_default_context_name() const
void rebuild_all()
Rebuild all dynamic terrain.
void new_map_dialog()
Display a new map dialog and process user input.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.