16 #define GETTEXT_DOMAIN "wesnoth-editor" 69 , mouse_handler_base()
78 , floating_label_manager_(nullptr)
79 , help_manager_(nullptr)
117 const std::string& schedule_id = schedule[
"id"];
118 const std::string& schedule_name = schedule[
"name"];
119 if (schedule_id.empty()) {
120 ERR_ED <<
"Missing ID attribute in a TOD Schedule.";
125 if (times ==
tods_.end()) {
126 std::pair<tods_map::iterator, bool> new_times =
127 tods_.emplace(schedule_id, std::pair(schedule_name, std::vector<time_of_day>()));
129 times = new_times.first;
131 ERR_ED <<
"Duplicate TOD Schedule identifiers.";
136 times->second.second.emplace_back(time);
142 ERR_ED <<
"No editor time-of-day defined";
148 const std::string tag_name =
"editor_music";
149 if (game_config.
child_range(tag_name).size() == 0) {
150 ERR_ED <<
"No editor music defined";
157 WRN_ED <<
"Music track " << track.
id() <<
" not found.";
196 ERR_ED <<
"Screenshot creation failed!";
205 std::string modified;
210 message =
_(
"Do you really want to quit?");
212 message =
_(
"Do you really want to quit? Changes to this map since the last save will be lost.");
214 message =
_(
"Do you really want to quit? The following maps were modified and all changes since the last save will be lost:");
215 message +=
"\n" + modified;
244 unsigned i =
static_cast<unsigned>(
index);
248 if (i < context_manager_->open_maps()) {
269 return toolkit_->get_palette_manager()->can_scroll_up();
271 return toolkit_->get_palette_manager()->can_scroll_down();
273 return !
gui_->zoom_at_max();
275 return !
gui_->zoom_at_min();
315 units.
find(loc) != units.
end());
353 return toolkit_->get_palette_manager()->active_palette().supports_swap();
475 return context_manager_->is_active_transitions_hotkey(
"editor-auto-update-transitions")
478 return context_manager_->is_active_transitions_hotkey(
"editor-partial-update-transitions")
481 return context_manager_->is_active_transitions_hotkey(
"editor-no-update-transitions")
545 return static_cast<std::size_t
>(
index) ==
gui_->playing_team()
559 tods_map::const_iterator it =
tods_.begin();
560 std::advance(it, index);
561 const std::vector<time_of_day>& times1 = it->second.second;
567 tods_map::const_iterator it =
tods_.begin();
568 std::advance(it, index);
569 const std::vector<time_of_day>& times1 = it->second.second;
583 return command_executor::get_action_state(command, index);
603 unsigned i =
static_cast<unsigned>(
index);
604 if (i < context_manager_->
size()) {
617 toolkit_->get_palette_manager()->set_group(index);
620 gui_->set_team(index,
true);
621 gui_->set_playing_team(index);
622 toolkit_->get_palette_manager()->draw_contents();
627 const std::set<map_location>& area =
629 std::vector<map_location> locs(area.begin(), area.end());
631 gui_->scroll_to_tiles(locs.begin(), locs.end());
650 std::vector<config>
items;
651 items.emplace_back(
"id",
"editor-playlist");
652 std::shared_ptr<gui::button>
b =
gui_->find_menu_button(
"menu-playlist");
653 show_menu(items, b->location().x +1, b->location().y + b->height() +1,
false, *
gui_);
659 std::advance(iter, index);
668 std::advance(iter, index);
677 un->anim_comp().set_standing();
685 gui_->set_zoom(
true);
690 gui_->set_zoom(
false);
695 gui_->toggle_default_zoom();
711 toolkit_->get_palette_manager()->scroll_up();
714 toolkit_->get_palette_manager()->scroll_down();
735 toolkit_->get_palette_manager()->active_palette().swap();
755 toolkit_->hotkey_set_mouse_action(command);
771 bool unrenamable = un->unrenamable();
772 un->set_unrenamable(!unrenamable);
779 bool canrecruit = un->can_recruit();
780 un->set_can_recruit(!canrecruit);
781 un->anim_comp().set_standing();
791 toolkit_->hotkey_set_mouse_action(command);
797 toolkit_->update_mouse_action_highlights();
801 toolkit_->update_mouse_action_highlights();
805 toolkit_->update_mouse_action_highlights();
809 toolkit_->update_mouse_action_highlights();
925 toolkit_->get_palette_manager()->location_palette_->add_item(std::to_string(new_side_num));
931 gui_->set_team(0,
true);
932 gui_->set_playing_team(0);
1008 std::vector<config>
items;
1009 for(
const auto&
c : items_arg) {
1010 const std::string&
id =
c[
"id"];
1016 items.emplace_back(
"id",
id);
1026 const std::string& first_id = items.front()[
"id"];
1028 if(first_id ==
"EDITOR-LOAD-MRU-PLACEHOLDER") {
1033 if(first_id ==
"editor-switch-map") {
1038 if(first_id ==
"editor-palette-groups") {
1040 toolkit_->get_palette_manager()->active_palette().expand_palette_groups_menu(items, 0);
1043 if(first_id ==
"editor-switch-side") {
1048 if(first_id ==
"editor-switch-area") {
1053 if(!items.empty() && items.front()[
"id"] ==
"editor-switch-time") {
1058 if(first_id ==
"editor-assign-local-time") {
1063 if(first_id ==
"menu-unit-facings") {
1065 auto pos = items.erase(items.begin());
1072 if(first_id ==
"editor-playlist") {
1074 auto pos = items.erase(items.begin());
1080 if(first_id ==
"editor-assign-schedule") {
1082 auto pos = items.erase(items.begin());
1083 std::transform(
tods_.begin(),
tods_.end(), std::inserter<std::vector<config>>(
items, pos), [](
const tods_map::value_type& tod) ->
config {
1084 return config {
"label", tod.second.first};
1088 if(first_id ==
"editor-assign-local-schedule") {
1090 auto pos = items.erase(items.begin());
1091 std::transform(
tods_.begin(),
tods_.end(), std::inserter<std::vector<config>>(
items, pos), [](
const tods_map::value_type& tod) ->
config {
1092 return config {
"label", tod.second.first};
1102 gui2::dialogs::preferences_dialog::display();
1104 gui_->queue_rerender();
1110 gui_->invalidate_all();
1118 if(un != units.
end()) {
1140 const std::string title(
N_(
"Change Unit ID"));
1141 const std::string
label(
N_(
"ID:"));
1143 if(un != units.
end()) {
1144 std::string
id = un->id();
1145 if (gui2::dialogs::edit_text::execute(title, label,
id)) {
1157 const std::string title(
N_(
"Rename Unit"));
1158 const std::string
label(
N_(
"Name:"));
1160 if(un != units.
end()) {
1161 std::string name = un->name();
1162 if(gui2::dialogs::edit_text::execute(title, label, name)) {
1194 std::stringstream ssx, ssy;
1197 ssx <<
"x = " << i->wml_x();
1198 ssy <<
"y = " << i->wml_y();
1201 ssx <<
", " << i->wml_x();
1202 ssy <<
", " << i->wml_y();
1205 ssx <<
"\n" << ssy.str() <<
"\n";
1252 if (mouse_handler_base::mouse_motion_default(x, y, update))
return;
1255 std::unique_ptr<editor_action>
a;
1301 toolkit_->clear_mouseover_overlay();
1302 if (mouse_handler_base::left_click(x, y, browse))
1305 LOG_ED <<
"Left click, after generic handling";
1310 LOG_ED <<
"Left click action " << hex_clicked;
1339 toolkit_->clear_mouseover_overlay();
1340 if (mouse_handler_base::right_click(x, y, browse))
return true;
1341 LOG_ED <<
"Right click, after generic handling";
1344 LOG_ED <<
"Right click action " << hex_clicked;
1362 mouse_handler_base::right_mouse_up(x, y, browse);
1416 return toolkit_->get_palette_manager()->active_palette().action_pressed();
virtual bool in_context_menu(hotkey::HOTKEY_COMMAND command) const
const map_location & mouseover_hex() const
Randomize terrain in an area.
virtual std::unique_ptr< editor_action > drag_end_left(editor_display &disp, int x, int y)
The end of dragging.
void undo()
Un-does the last action, and puts it in the redo stack for a possible redo.
void set_scroll_up(bool on)
::tod_manager * tod_manager
void copy_selection()
Copy the selection on the current map to the clipboard.
static std::string write_translated_direction(DIRECTION dir)
void set_scroll_down(bool on)
bool minimap_draw_units()
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
A map fragment – a collection of locations and information abut them.
void add_to_playlist(const sound::music_track &track)
const std::string & id() const
std::unique_ptr< font::floating_label_context > floating_label_manager_
void queue_rerender()
Marks everything for rendering including all tiles and sidebar.
const t_translation::terrain_code & get_selected_bg_terrain()
bool dragging_right_
RMB drag init flag.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void save_map() override
Save the map, open dialog if not named yet.
void init_tods(const game_config_view &game_config)
init the available time-of-day settings
void export_selection_coords()
Export the WML-compatible list of selected tiles to the system clipboard.
virtual std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y)=0
A click, possibly the beginning of a drag.
game_classification * classification
void show_terrain_description(const terrain_type &t)
void perform_refresh_delete(std::unique_ptr< editor_action > action, bool drag_part=false)
Peform an action on the current map_context, then refresh the display and delete the pointer...
void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc=map_location::null_location()) override
Called when a mouse motion event takes place.
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
bool quit_confirm()
Show a quit confirmation dialog and returns true if the user pressed 'yes'.
bool draw_num_of_bitmaps()
void save_area(const std::set< map_location > &area)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
void new_side()
Adds a new side to the map.
std::unique_ptr< editor_toolkit > toolkit_
void custom_tods_dialog()
Display the settings dialog, used to control e.g.
void process_keyup_event(const SDL_Event &event) override
Process keyup (always).
void left_drag_end(int x, int y, const bool browse) override
Called whenever the left mouse drag has "ended".
config_array_view child_range(config_key_type key) const
void toggle_debug_flag(DEBUG_FLAG flag)
bool minimap_movement_coding()
const std::string & get_filename() const
editor_display & gui() override
Reference to the used display objects.
bool can_execute_command(const hotkey::hotkey_command &command, int index=-1) const override
command_executor override
child_itors child_range(config_key_type key)
void new_area(const std::set< map_location > &area)
void show_unit_list(display &gui)
bool right_click_show_menu(int x, int y, const bool browse) override
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
void set_active_area(int index)
int get_current_time(const map_location &loc=map_location::null_location()) const
map_labels & get_labels()
void save_area()
Save the current selection to the active area.
void preferences() override
Show the preferences dialog.
static bool show_prompt(const std::string &message)
void show_help() override
Stores all information related to functions that can be bound to hotkeys.
const std::vector< std::string > items
save_result save_image(const locator &i_locator, const std::string &filename)
const mouse_action & get_mouse_action() const
Get the current mouse action.
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
void add_area()
Add a new area to the current context, filled with the selection if any.
virtual void play_slice(bool is_delay_enabled=true)
void redo()
Re-does a previously undid action, and puts it back in the undo stack.
HOTKEY_COMMAND command
The command associated with this hotkey.
List of starting locations and location ids.
void play_music_once(const std::string &file)
void rename_unit() override
static std::string _(const char *str)
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
bool draw_terrain_codes()
void unit_list() override
virtual std::unique_ptr< editor_action > up_right(editor_display &disp, int x, int y)
editor::menu_type active_menu_
void partial_undo()
Un-does a single step from a undo action chain.
virtual std::unique_ptr< editor_action > drag_end_right(editor_display &disp, int x, int y)
Keyboard shortcuts for game actions.
Unit and team statistics.
void remove_area(int index)
void flush_cache()
Purges all image caches.
void perform_delete(std::unique_ptr< editor_action > action)
Perform an action, then delete the action object.
bool minimap_draw_villages()
void show() const
Shows the error in a dialog.
const std::unique_ptr< editor_display > gui_
The display object used and owned by the editor.
Overlays x,y coords on tiles.
void unit_description() override
void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &disp) override
controller_base override
bool do_execute_command(const hotkey::hotkey_command &command, int index=-1, bool press=true, bool release=false) override
command_executor override
map_context & get_current_map_context() const
void right_mouse_up(int x, int y, const bool browse) override
Called when the right mouse button is up.
void clear_help_string()
Removes the help string.
void right_drag_end(int x, int y, const bool browse) override
Called whenever the right mouse drag has "ended".
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
void set_local_starting_time(int time)
TODO.
virtual std::unique_ptr< editor_action > key_event(editor_display &disp, const SDL_Event &e)
Function called by the controller on a key event for the current mouse action.
std::string label
What to show in the filter's drop-down list.
const std::set< map_location > & selection() const
Return the selection set.
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
virtual bool has_context_menu() const
void remove_side()
removes the last side from the scenario
Implements a quit confirmation dialog.
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.
bool on_board_with_border(const map_location &loc) const
void undo() override
Undos an action in the current map context.
virtual hotkey::command_executor * get_hotkey_command_executor() override
Optionally get a command executor to handle context menu events.
map_location drag_from_hex_
Drag start map location.
void replace_schedule(const std::vector< time_of_day > &schedule)
void set_starting_time(int time)
TODO.
int show_menu(lua_State *L)
Displays a popup menu at the current mouse position Best used from a [set_menu_item], to show a submenu.
void init_music(const game_config_view &game_config)
init background music for the editor
editor_action * last_undo_action()
bool draw_hex_coordinates()
void touch_motion(int x, int y, const bool browse, bool update=false, map_location new_loc=map_location::null_location()) override
void refresh_image_cache()
Reload images.
Manage the empty-palette in the editor.
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.
uint32_t get_mouse_button_mask()
Returns the current mouse button mask.
void terrain_description() override
Paint the same terrain on a number of locations on the map.
bool dragging_left_
LMB drag init flag.
virtual bool supports_brushes() const
Whether we need the brush bar, is used to grey it out.
static bool quit()
Shows the quit confirmation if needed.
std::vector< std::string > get_area_ids() const
Encapsulates the map of the game.
Helper class, don't construct this directly.
void perform_partial_action(const editor_action &action)
Performs a partial action, assumes that the top undo action has been modified to maintain coherent st...
unit_iterator find(std::size_t id)
void recalculate_labels()
void set_starting_position_labels(display &disp)
static void quit_to_desktop()
void init_gui()
init the display object and general set-up
void scroll_right(bool on) override
void status_table() override
bool everything_selected() const
void left_mouse_up(int x, int y, const bool browse) override
Called when the left mouse button is up.
virtual void highlight_hex(map_location hex)
Game configuration data as global variables.
void show_unit_help(const std::string &show_topic, bool has_variations, bool hidden, int xloc, int yloc)
Open the help browser, show unit with id unit_id.
const tod_manager * get_time_manager() const
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
structure which will hide all current floating labels, and cause floating labels instantiated after i...
const std::string & selected_item() const
Return the currently selected item.
Internal representation of music tracks.
The help implementation caches data parsed from the game_config.
virtual std::vector< std::string > additional_actions_pressed() override
void set_scroll_right(bool on)
void cut_selection()
Cut the selection from the current map to the clipboard.
virtual bool do_execute_command(const hotkey_command &command, int index=-1, bool press=true, bool release=false)
void set_debug_flag(DEBUG_FLAG flag, bool value)
DIRECTION
Valid directions which can be moved in our hexagonal world.
void display_redraw_callback(display &)
Callback function passed to display to be called on queue_rerender.
std::vector< sound::music_track > music_tracks_
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.
void do_screenshot(const std::string &screenshot_filename="map_screenshot.png")
Takes a screenshot.
void toggle_grid() override
Grid toggle.
virtual std::unique_ptr< editor_action > up_left(editor_display &disp, int x, int y)
bool allow_mouse_wheel_scroll(int x, int y) override
Derived classes can override this to disable mousewheel scrolling under some circumstances, e.g.
void scroll_left(bool on) override
bool left_click(int x, int y, const bool browse) override
Overridden in derived classes, called on a left click (mousedown).
const std::string & file_path() const
virtual const unit_map & units() const override
Const units accessor.
bool do_quit_
Quit main loop flag.
void set_scroll_left(bool on)
EXIT_STATUS main_loop()
Editor main loop.
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Overlays number of bitmaps on tiles.
const game_config_view & game_config_
bool minimap_draw_terrain()
virtual const editor_map & map() const override
Const map accessor.
void set_draw_terrain_codes(bool value)
int get_active_area() const
std::unique_ptr< help::help_manager > help_manager_
virtual void move(editor_display &disp, const map_location &hex)
Mouse move (not a drag).
bool is_in_playlist(std::string track_id)
virtual std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y)=0
A click, possibly the beginning of a drag.
Overlays terrain codes on tiles.
void replace_local_schedule(const std::vector< time_of_day > &schedule)
Replace the [time]s of the currently active area.
virtual std::unique_ptr< editor_action > drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Drag operation.
Container associating units to locations.
const std::set< map_location > & get_area_by_index(int index) const
void set_draw_num_of_bitmaps(bool value)
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
int get_current_area_time(int index) const
void set_draw_hex_coordinates(bool value)
const std::string & title() const
editor_controller()
The constructor.
There are still moves and/or attacks possible, but the unit doesn't fit in the "unmoved" status...
const std::unique_ptr< context_manager > context_manager_
A config object defines a single node in a WML file, with access to child nodes.
void scroll_down(bool on) override
virtual std::unique_ptr< editor_action > drag_right(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Drag operation.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
void scroll_up(bool on) override
Handle hotkeys to scroll map.
bool right_click(int x, int y, const bool browse) override
Overridden in derived classes, called on a right click (mousedown).
virtual const std::vector< team > & teams() const override
Const teams accessor.
static std::vector< std::string > saved_windows_
std::string::const_iterator iterator
void redo() override
Redos an action in the current map context.
bool select_area(int index)
Select the nth tod area.
hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const override
command_executor override
bool minimap_terrain_coding()