16 #define GETTEXT_DOMAIN "wesnoth-editor"
61 #include <boost/algorithm/string.hpp>
62 #include <boost/filesystem.hpp>
66 std::vector<std::unique_ptr<editor::map_context>> saved_contexts_;
67 int last_context_ = 0;
69 const std::string get_menu_marker(
const bool changed)
87 , current_addon_(addon_id)
89 , last_map_generator_(nullptr)
90 , current_context_index_(0)
91 , auto_update_transitions_(
prefs::
get().editor_auto_update_transitions())
147 for(std::size_t
i = 10;
i <= n_teams;
i++) {
166 return (item ==
"editor-auto-update-transitions");
168 return (item ==
"editor-partial-update-transitions");
170 return (item ==
"editor-no-update-transitions");
190 std::vector<std::string> modified;
193 if(!mc->get_name().empty()) {
194 modified.push_back(mc->get_name());
195 }
else if(!mc->get_filename().empty()) {
196 modified.push_back(mc->get_filename());
198 modified.push_back(mc->get_default_context_name());
203 for(std::string& str : modified) {
207 return modified.size();
234 if(mru.empty() ||
index >= mru.size()) {
245 if(gui2::dialogs::editor_edit_side::execute(team_info)) {
261 gui2::dialogs::prompt::execute(new_addon_id);
266 std::string main_cfg = new_dir +
"/_main.cfg";
287 std::string
id = context.
get_id();
288 std::string name = context.
get_name();
297 const bool ok = gui2::dialogs::editor_edit_scenario::execute(
298 id, name, description, turns, xp_mod, victory, random
319 if(gui2::dialogs::editor_new_map::execute(
_(
"New Map"),
w,
h)) {
332 if(gui2::dialogs::editor_new_map::execute(
_(
"New Scenario"),
w,
h)) {
340 for(std::size_t mci = 0; mci <
map_contexts_.size(); ++mci) {
354 std::ostringstream ss;
355 ss <<
"[" << mci + 1 <<
"] ";
369 const std::string
label = ss.str();
370 const std::string details = get_menu_marker(changed);
372 items.emplace_back(
"label",
label,
"details", details);
380 items.emplace_back(
"label",
_(
"No Recent Files"));
384 for(
const std::string&
path : mru) {
399 std::vector<std::string> area_ids = tod->
get_area_ids();
401 for(std::size_t mci = 0; mci < area_ids.size(); ++mci) {
402 const std::string& area = area_ids[mci];
404 std::stringstream ss;
405 ss <<
"[" << mci + 1 <<
"] ";\
417 const std::string
label = ss.str();
418 const std::string details = get_menu_marker(changed);
420 items.emplace_back(
"label",
label,
"details", details);
429 const std::string& teamname =
t.user_team_name();
430 std::stringstream
label;
431 label <<
"[" << mci+1 <<
"] ";
433 if(teamname.empty()) {
439 items.emplace_back(
"label",
label.str());
446 assert(tod_m !=
nullptr);
450 items.emplace_back(
"details", time.name,
"image", time.image);
460 items.emplace_back(
"details", time.name,
"image", time.image);
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";
637 auto chain = std::make_unique<editor_action_chain>();
639 for (
const auto& u : units) {
640 map_location l{u.get_location().
x - x_offset, u.get_location().y - y_offset};
641 chain->append_action(std::make_unique<editor_action_unit_replace>(u.get_location(), l));
644 chain->append_action(std::make_unique<editor_action_item_move_all>(x_offset, y_offset));
645 chain->append_action(std::make_unique<editor_action_time_area_move_all>(x_offset, y_offset));
654 if (old_label ==
nullptr) {
662 chain->append_action(std::make_unique<editor_action_label_delete>(
loc));
663 chain->append_action(std::make_unique<editor_action_label_delete>(new_loc));
664 chain->append_action(
665 std::make_unique<editor_action_label>(
678 chain->append_action(
679 std::make_unique<editor_action_resize_map>(
w,
h, x_offset, y_offset,
fill));
686 bool first_pick =
false;
688 if(input_name.empty()) {
712 std::string last_folder = save_path.parent_path().filename().string();
713 if ((last_folder ==
"scenarios")
717 VGETTEXT(
"Do you really want to save $type1 in $type2 folder?", {{
"type1",
"map"}, {
"type2",
"scenarios"}}),
739 bool first_pick =
false;
741 if(input_name.empty()) {
761 std::string last_folder = save_path.parent_path().filename().string();
762 if ((last_folder ==
"maps")
766 VGETTEXT(
"Do you really want to save $type1 in $type2 folder?", {{
"type1",
"scenario"}, {
"type2",
"maps"}}),
791 if(
i[
"map_generation"].empty() &&
i[
"scenario_generation"].empty()) {
795 if(
const auto generator_cfg =
i.optional_child(
"generator")) {
798 ERR_ED <<
"Scenario \"" <<
i[
"name"] <<
"\" with id " <<
i[
"id"]
799 <<
" has map_generation= but no [generator] tag";
815 std::string map_string;
824 if(map_string.empty()) {
893 if(display_confirmation) {
908 if(display_confirmation) {
965 LOG_ED <<
"Load map: " <<
filename << (new_context ?
" (new)" :
" (same)");
969 if(mc->get_filename() !=
filename) {
984 const std::string&
msg =
_(
"Loaded embedded map data");
1005 ERR_ED <<
"Empty filename in map revert";
1048 if(start_pos_count == 0) {
1049 start_pos_count = 1;
1051 for(
int i = 0;
i < start_pos_count;
i++) {
1063 template<
typename... T>
1066 map_contexts_.emplace_back(std::make_unique<map_context>(args...));
1076 template<
typename... T>
1090 if(saved_contexts_.empty()) {
1129 WRN_ED <<
"Invalid index in switch map context: " <<
index;
A config object defines a single node in a WML file, with access to child nodes.
void set_viewing_team_index(std::size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
void recalculate_minimap()
Schedule the minimap for recalculation.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
void set_playing_team_index(std::size_t team)
sets the team whose turn it currently is
void rebuild_all()
Rebuild all dynamic terrain.
void change_display_context(const display_context *dc)
void invalidate_all()
Function to invalidate all tiles.
void init_flags()
Init the flag list and the team colors used by ~TC.
void reload_map()
Updates internals that cache map size.
const game_config_view & game_config_
std::vector< std::unique_ptr< map_context > > map_contexts_
The currently opened map context object.
bool write_scenario(bool display_confirmation=true)
context_manager(editor_display &gui, const game_config_view &game_config, const std::string &addon_id)
bool is_active_transitions_hotkey(const std::string &item)
void new_scenario(int width, int height, const t_translation::terrain_code &fill, bool new_context)
Create a new scenario.
void expand_local_time_menu(std::vector< config > &items) const
Menu expanding for the map's defined areas.
void new_map(int width, int height, const t_translation::terrain_code &fill, bool new_context)
Create a new map.
void fill_selection()
Fill the selection with the foreground terrain.
void new_map_dialog()
Display a new map dialog and process user input.
bool confirm_discard()
Shows an are-you-sure dialog if the map was modified.
void generate_map_dialog()
Display a generate random map dialog and process user input.
int auto_update_transitions_
Flag to rebuild terrain on every terrain change.
void rename_area_dialog()
Display an dialog to querry a new id for an [time_area].
void revert_map()
Revert the map by reloading it from disk.
void load_map_dialog(bool force_same_context=false)
Display a load map dialog and process user input.
bool check_switch_open_map(const std::string &fn)
Check if a map is already open.
std::vector< std::unique_ptr< map_generator > > map_generators_
Available random map generators.
void set_window_title()
Displays the specified map name in the window titlebar.
void switch_context(const int index, const bool force=false)
Switches the context to the one under the specified index.
map_generator * last_map_generator_
void expand_sides_menu(std::vector< config > &items) const
Menu expanding for the map's player sides.
std::size_t check_open_map(const std::string &fn) const
Check if a map is already open.
void save_scenario_as_dialog()
Display a save map as dialog and process user input.
void refresh_all()
Refresh everything, i.e.
void init_map_generators(const game_config_view &game_config)
init available random map generators
void save_all_maps()
Save all maps, show save dialogs for unsaved ones.
int add_map_context_of(std::unique_ptr< map_context > &&mc)
bool toggle_update_transitions()
void expand_time_menu(std::vector< config > &items) const
Menu expanding for the map's defined areas.
void map_to_scenario()
Convert existing map to scenario.
void save_map_as_dialog()
Display a save map as dialog and process user input.
void create_default_context()
Creates a default map context object, used to ensure there is always at least one.
void new_scenario_dialog()
Display a new map dialog and process user input.
void replace_map_context(const T &... args)
Replace the current map context and refresh accordingly.
void apply_mask_dialog()
Display an apply mask dialog and process user input.
void load_map(const std::string &filename, bool new_context)
Load a map given the filename.
void reload_map()
Reload the map after it has significantly changed (when e.g.
void save_contexts()
Save all open map_contexts to memory.
void set_addon_id(const std::string &id)
void create_mask_to_dialog()
Display an apply mask dialog and process user input.
void close_current_context()
Closes the active map context.
void resize_map_dialog()
Display a load map dialog and process user input.
void edit_scenario_dialog()
Display a scenario edit dialog and process user input.
std::string current_addon_
The currently selected add-on.
void replace_map_context_with(std::unique_ptr< map_context > &&mc)
void perform_refresh(const editor_action &action, bool drag_part=false)
Perform an action on the current map_context, then refresh the display.
int add_map_context(const T &... args)
Add a map context.
void init_context(int width, int height, const t_translation::terrain_code &fill, bool new_context, bool is_pure_map=true)
void expand_load_mru_menu(std::vector< config > &items) const
Menu expanding for most recent loaded list.
void save_map(bool show_confirmation=true)
Save the map, open dialog if not named yet.
void edit_side_dialog(const team &t)
Display a side edit dialog and process user input.
void create_blank_context()
bool write_map(bool display_confirmation=true)
Save the map under a given filename.
void load_mru_item(unsigned index, bool force_same_context=false)
Open the specified entry from the recent files list.
map_context & get_map_context()
Get the current map context object.
void expand_areas_menu(std::vector< config > &items) const
Menu expanding for the map's defined areas.
int current_context_index_
void expand_open_maps_menu(std::vector< config > &items) const
Menu expanding for open maps list.
class location_palette * locs_
void refresh_after_action(bool drag_part=false)
Refresh the display after an action has been performed.
void refresh_on_context_change()
Performs the necessary housekeeping necessary when switching contexts.
std::size_t modified_maps(std::string &modified)
Paint the same terrain on a number of locations on the map.
Replace contents of the entire map, Useful as a fallback undo method when something else would be imp...
Base class for all editor actions.
static std::string current_addon_id_
void rebuild_terrain(const map_location &loc)
void set_status(const std::string &str, const bool is_success)
Set a status text at the bottom left of the map area.
This class adds extra editor-specific functionality to a normal gamemap.
const std::set< map_location > & selection() const
Return the selection set.
void add_item(const std::string &id)
This class wraps around a map to provide a concise interface for the editor to work with.
virtual const unit_map & units() const override
Const units accessor.
int get_active_area() const
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
void set_needs_reload(bool value=true)
Setter for the reload flag.
void new_side()
Adds a new side to the map.
const std::string & get_id() const
bool random_start_time() const
void set_side_setup(editor_team_info &info)
void save_scenario()
Saves the scenario under the current filename.
void perform_action(const editor_action &action)
Performs an action (thus modifying the map).
const std::string & get_description() const
void clear_changed_locations()
const tod_manager * get_time_manager() const
void save_map()
Saves the map under the current filename.
void reset_starting_position_labels(display &disp)
virtual const editor_map & map() const override
Const map accessor.
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
const t_string get_default_context_name() const
const std::string & get_filename() const
map_labels & get_labels()
virtual const std::vector< team > & teams() const override
Const teams accessor.
game_classification & get_classification()
bool victory_defeated() const
void set_filename(const std::string &fn)
const std::set< map_location > changed_locations() const
utils::optional< int > get_xp_mod() const
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)
const std::string & get_name() const
A class grating read only view to a vector of config objects, viewed as one config with all children ...
const config & find_mandatory_child(std::string_view key, const std::string &name, const std::string &value) const
int w() const
Effective map width.
int h() const
Effective map height.
void for_each_loc(const F &f) const
int num_valid_starting_positions() const
Counts the number of sides that have valid starting positions on this map.
utils::optional< uint32_t > get_seed()
void select_map_generator(map_generator *mg)
map_generator * get_selected_map_generator()
file_dialog & set_extension(const std::string &value)
Sets allowed file extensions for file names in save mode.
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
file_dialog & set_save_mode(bool value)
Sets the dialog's behavior on non-existent file name inputs.
std::string path() const
Gets the current file selection.
file_dialog & add_extra_path(desktop::GAME_PATH_TYPES path)
@ yes_no_buttons
Shows a yes and no button.
bool show(const unsigned auto_close_time=0)
Shows the window.
virtual std::string create_map(utils::optional< uint32_t > randomseed={})=0
Creates a new map and returns it.
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
void enable(bool is_enabled)
std::vector< std::string > recent_files()
Retrieves the list of recently opened files.
This class stores all the data for a single 'side' (in game nomenclature).
To store label data Class implements logic for rendering.
bool visible_in_shroud() const
bool visible_in_fog() const
const color_t & color() const
const std::string & category() const
const t_string & text() const
const std::string & team_name() const
int number_of_turns() const
std::vector< std::string > get_area_ids() const
const std::set< map_location > & get_area_by_index(int index) const
void set_area_id(int area_index, const std::string &id)
const std::vector< time_of_day > & times() const
void swap(config &lhs, config &rhs) noexcept
Implement non-member swap function for std::swap (calls config::swap).
Declarations for File-IO.
static std::string _(const char *str)
std::string label
What to show in the filter's drop-down list.
map_generator * create_map_generator(const std::string &name, const config &cfg, const config *vars)
@ GAME_EDITOR_MAP_DIR
Editor map dir.
void fill(const ::rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
Manage the empty-palette in the editor.
const t_translation::terrain_code & get_selected_bg_terrain()
std::string initialize_addon()
std::string get_legacy_editor_dir()
const std::string wml_extension
bool is_cfg(const std::string &filename)
Returns true if the file ends with the wmlfile extension.
static bfs::path get_dir(const bfs::path &dirpath)
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
bool rename_dir(const std::string &old_dir, const std::string &new_dir)
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
const std::string map_extension
utils::optional< std::string > get_addon_id_from_path(const std::string &location)
Returns the add-on ID from a path.
const std::string mask_extension
void write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode)
Throws io_exception if an error occurs.
std::string get_current_editor_dir(const std::string &addon_id)
const std::string unicode_bullet
Game configuration data as global variables.
std::string get_default_title_string()
std::string default_terrain
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 show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
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.
@ OK
Dialog was closed with the OK button.
@ CANCEL
Dialog was closed with the CANCEL button.
std::string italic(Args &&... data)
Applies italic Pango markup to the input.
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
const int TRANSITION_UPDATE_ON
const int TRANSITION_UPDATE_COUNT
const int TRANSITION_UPDATE_OFF
const int TRANSITION_UPDATE_PARTIAL
::tod_manager * tod_manager
game_classification * classification
filter_context * filter_con
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
const terrain_code NONE_TERRAIN
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void set_window_title(const std::string &title)
Sets the title of the main window.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
static std::string get_filename(const std::string &file_code)
std::string filename
Filename.
Encapsulates the map of the game.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Object which defines a time of day with associated bonuses, image, sounds etc.
bool addon_filename_legal(const std::string &name)
Checks whether an add-on file name is legal or not.