14 #define GETTEXT_DOMAIN "wesnoth-editor"
16 #include "widgets/slider.hpp"
59 static std::vector<std::string> saved_windows_;
66 , mouse_handler_base()
74 , tooltip_manager_(video)
75 , floating_label_manager_(nullptr)
76 , help_manager_(nullptr)
116 const std::string& schedule_name = schedule[
"name"];
117 if (schedule_id.empty()) {
118 ERR_ED <<
"Missing ID attribute in a TOD Schedule." << std::endl;
123 if (times ==
tods_.end()) {
124 std::pair<tods_map::iterator, bool> new_times =
126 (schedule_id, std::pair<
std::string, std::vector<time_of_day> >(schedule_name, std::vector<time_of_day>())) );
127 times = new_times.first;
129 ERR_ED <<
"Duplicate TOD Schedule identifiers." << std::endl;
140 ERR_ED <<
"No editor time-of-day defined" << std::endl;
148 ERR_ED <<
"No editor music defined" << std::endl;
154 WRN_ED <<
"Music track " << track.
id() <<
" not found." << std::endl;
193 if (!
gui().screenshot(screenshot_filename,
true)) {
194 ERR_ED <<
"Screenshot creation failed!\n";
208 message =
_(
"Do you really want to quit?");
209 }
else if (amount == 1) {
210 message =
_(
"Do you really want to quit? Changes to this map since the last save will be lost.");
212 message =
_(
"Do you really want to quit? The following maps were modified and all changes since the last save will be lost:");
213 message +=
"\n" + modified;
222 _(
"No editor time-of-day found."));
228 std::vector<time_of_day> schedule =
context_manager_->get_map_context().get_time_manager()->times();
231 adjust_resetter.
reset();
245 unsigned i =
static_cast<unsigned>(
index);
249 if (i < context_manager_->open_maps()) {
270 return toolkit_->get_palette_manager()->can_scroll_up();
272 return toolkit_->get_palette_manager()->can_scroll_down();
274 return !
gui_->zoom_at_max();
276 return !
gui_->zoom_at_min();
317 units.
find(loc) != units.
end());
350 return toolkit_->get_mouse_action()->supports_brushes();
355 return toolkit_->get_palette_manager()->active_palette().supports_swap();
393 !
context_manager_->get_map_context().get_time_manager()->get_area_ids().empty();
397 !
context_manager_->get_map_context().get_time_manager()->get_area_ids().empty()
480 return context_manager_->is_active_transitions_hotkey(
"editor-auto-update-transitions")
483 return context_manager_->is_active_transitions_hotkey(
"editor-partial-update-transitions")
486 return context_manager_->is_active_transitions_hotkey(
"editor-no-update-transitions")
502 return context_manager_->get_map_context().get_map().everything_selected() ?
548 return static_cast<size_t>(
index) ==
gui_->playing_team()
551 return index ==
context_manager_->get_map_context().get_time_manager()->get_current_time()
554 return index ==
context_manager_->get_map_context().get_time_manager()->get_current_area_time(
562 tods_map::const_iterator it =
tods_.begin();
563 std::advance(it, index);
564 const std::vector<time_of_day>& times1 = it->second.second;
565 const std::vector<time_of_day>& times2 =
context_manager_->get_map_context().get_time_manager()->times();
570 tods_map::const_iterator it =
tods_.begin();
571 std::advance(it, index);
572 const std::vector<time_of_day>& times1 = it->second.second;
574 const std::vector<time_of_day>& times2 =
context_manager_->get_map_context().get_time_manager()->times(active_area);
587 return command_executor::get_action_state(command, index);
608 unsigned i =
static_cast<unsigned>(
index);
609 if (i < context_manager_->
size()) {
622 toolkit_->get_palette_manager()->set_group(index);
625 gui_->set_team(index,
true);
626 gui_->set_playing_team(index);
627 toolkit_->get_palette_manager()->draw_contents();
632 const std::set<map_location>& area =
633 context_manager_->get_map_context().get_time_manager()->get_area_by_index(index);
634 std::vector<map_location> locs(area.begin(), area.end());
636 gui_->scroll_to_tiles(locs.begin(), locs.end());
657 std::vector<std::string>
items;
658 items.push_back(
"editor-playlist");
659 std::shared_ptr<gui::button>
b =
gui_->find_menu_button(
"menu-playlist");
660 show_menu(items, b->location().x +1, b->location().y + b->height() +1,
false, *
gui_);
666 std::advance(iter, index);
676 std::advance(iter, index);
677 context_manager_->get_map_context().replace_local_schedule(iter->second.second);
686 un->anim_comp().set_standing();
694 gui_->set_zoom(zoom_amount);
699 gui_->set_zoom(-zoom_amount);
704 gui_->set_default_zoom();
720 toolkit_->get_palette_manager()->scroll_up();
721 gui_->draw(
true,
false);
724 toolkit_->get_palette_manager()->scroll_down();
725 gui_->draw(
true,
false);
746 toolkit_->get_palette_manager()->active_palette().swap();
749 if (dynamic_cast<const editor_action_chain*>(
context_manager_->get_map_context().last_undo_action()) !=
nullptr) {
766 toolkit_->hotkey_set_mouse_action(command);
781 const std::set<std::string>& recruit_set =
toolkit_->get_palette_manager()->unit_palette_->get_selected_bg_items();
782 std::vector<std::string> recruits(recruit_set.begin(), recruit_set.end());
783 un->set_recruits(recruits);
790 bool unrenamable = un->unrenamable();
791 un->set_unrenamable(!unrenamable);
798 bool canrecruit = un->can_recruit();
799 un->set_can_recruit(!canrecruit);
800 un->anim_comp().set_standing();
810 toolkit_->hotkey_set_mouse_action(command);
816 toolkit_->update_mouse_action_highlights();
820 toolkit_->update_mouse_action_highlights();
824 toolkit_->update_mouse_action_highlights();
828 toolkit_->update_mouse_action_highlights();
941 gui_->set_team(0,
true);
942 gui_->set_playing_team(0);
1004 if (!
context_manager_->get_map().on_board_with_border(
gui().hex_clicked_on(xloc, yloc))) {
1009 std::vector<std::string>
items;
1010 std::vector<std::string>::const_iterator
i = items_arg.begin();
1011 while(i != items_arg.end())
1019 items.push_back(*i);
1023 if (!items.empty() && items.front() ==
"EDITOR-LOAD-MRU-PLACEHOLDER") {
1027 if (!items.empty() && items.front() ==
"editor-switch-map") {
1031 if (!items.empty() && items.front() ==
"editor-palette-groups") {
1033 toolkit_->get_palette_manager()->active_palette().expand_palette_groups_menu(items);
1035 if (!items.empty() && items.front() ==
"editor-switch-side") {
1039 if (!items.empty() && items.front() ==
"editor-switch-area") {
1043 if (!items.empty() && items.front() ==
"editor-switch-time") {
1047 if (!items.empty() && items.front() ==
"editor-assign-local-time") {
1051 if (!items.empty() && items.front() ==
"menu-unit-facings") {
1053 items.erase(items.begin());
1057 if (!items.empty() && items.front() ==
"editor-playlist") {
1059 items.erase(items.begin());
1061 items.push_back(track.title().empty() ? track.id() : track.title());
1064 if (!items.empty() && items.front() ==
"editor-assign-schedule") {
1067 items.erase(items.begin());
1070 iter !=
tods_.end(); ++iter) {
1071 items.push_back(iter->second.first);
1074 if (!items.empty() && items.front() ==
"editor-assign-local-schedule") {
1077 items.erase(items.begin());
1080 iter !=
tods_.end(); ++iter) {
1081 items.push_back(iter->second.first);
1085 command_executor::show_menu(items, xloc, yloc, context_menu, disp);
1090 gui_->video().clear_all_help_strings();
1093 gui_->redraw_everything();
1099 gui_->invalidate_all();
1107 if(un != units.
end()) {
1132 if(un != units.
end()) {
1149 if(un != units.
end()) {
1171 const std::set<map_location>& area =
context_manager_->get_map().selection();
1177 const std::set<map_location>& area =
context_manager_->get_map().selection();
1183 std::stringstream ssx, ssy;
1184 std::set<map_location>::const_iterator
i =
context_manager_->get_map().selection().begin();
1186 ssx <<
"x = " << i->x + 1;
1187 ssy <<
"y = " << i->y + 1;
1190 ssx <<
", " << i->x + 1;
1191 ssy <<
", " << i->y + 1;
1194 ssx <<
"\n" << ssy.str() <<
"\n";
1202 boost::scoped_ptr<editor_action> action_auto(action);
1210 boost::scoped_ptr<editor_action> action_auto(action);
1243 if (mouse_handler_base::mouse_motion_default(x, y, update))
return;
1249 if (
dragging_left_ && (SDL_GetMouseState(
nullptr,
nullptr) & SDL_BUTTON(1)) != 0) {
1250 if (!
context_manager_->get_map().on_board_with_border(hex_clicked))
return;
1251 a =
toolkit_->get_mouse_action()->drag_left(*
gui_, x, y, partial, last_undo);
1252 }
else if (
dragging_right_ && (SDL_GetMouseState(
nullptr,
nullptr) & SDL_BUTTON(3)) != 0) {
1253 if (!
context_manager_->get_map().on_board_with_border(hex_clicked))
return;
1254 a =
toolkit_->get_mouse_action()->drag_right(*
gui_, x, y, partial, last_undo);
1260 boost::scoped_ptr<editor_action> aa(a);
1269 toolkit_->get_mouse_action()->move(*
gui_, hex_clicked);
1281 return toolkit_->get_mouse_action()->has_context_menu();
1286 toolkit_->clear_mouseover_overlay();
1287 if (mouse_handler_base::left_click(x, y, browse))
1290 LOG_ED <<
"Left click, after generic handling\n";
1295 LOG_ED <<
"Left click action " << hex_clicked.
x <<
" " << hex_clicked.
y <<
"\n";
1315 std::shared_ptr<gui::slider>
s =
gui_->find_slider(
"map-zoom-slider");
1316 if (s && s->value_change()) {
1317 if (
gui_->set_zoom(s->value(),
true)) {
1319 toolkit_->get_mouse_action()->set_mouse_overlay(*
gui_);
1328 toolkit_->clear_mouseover_overlay();
1329 if (mouse_handler_base::right_click(x, y, browse))
return true;
1330 LOG_ED <<
"Right click, after generic handling\n";
1332 if (!
context_manager_->get_map().on_board_with_border(hex_clicked))
return true;
1333 LOG_ED <<
"Right click action " << hex_clicked.
x <<
" " << hex_clicked.
y <<
"\n";
1398 return toolkit_->get_palette_manager()->active_palette().action_pressed();
void perform_refresh_delete(editor_action *action, bool drag_part=false)
Peform an action on the current map_context, then refresh the display and delete the pointer...
child_itors child_range(const std::string &key)
Randomize terrain in an area.
bool right_click_show_menu(int x, int y, const bool browse)
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
boost::scoped_ptr< editor_toolkit > toolkit_
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
void set_scroll_up(bool on)
void show_help(CVideo &video, const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
void set_preference_display_settings()
::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()
A map fragment – a collection of locations and information abut them.
void save_map()
Save the map, open dialog if not named yet.
editor_display & gui()
Reference to the used display objects.
Small struct to store and manipulate ToD colors.
bool dragging_right_
RMB drag init flag.
void set_draw_terrain_codes(bool value)
Setter for the terrain code debug overlay on tiles.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void export_selection_coords()
Export the WML-compatible list of selected tiles to the system clipboard.
game_classification * classification
void do_screenshot(const std::string &screenshot_filename="map_screenshot.bmp")
Takes a screenshot.
bool right_click(int x, int y, const bool browse)
Overridden in derived classes, called on a right click (mousedown).
const char * what() const
bool quit_confirm()
Show a quit confirmation dialog and returns true if the user pressed 'yes'.
const mp_game_settings * mp_settings
bool left_click(int x, int y, const bool browse)
Overridden in derived classes, called on a left click (mousedown).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
void custom_tods_dialog()
Display the settings dialog, used to control e.g.
GLuint GLuint GLsizei GLenum type
bool minimap_movement_coding()
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
void show(CVideo &video)
Shows the error in a dialog.
void redo()
Redos an action in the current map context.
void left_drag_end(int x, int y, const bool browse)
Called whenever the left mouse drag has "ended".
void save_area()
Save the current selection to the active area.
static bool show_prompt(const std::string &message)
bool can_execute_command(const hotkey::hotkey_command &command, int index=-1) const
command_executor override
Stores all information related to functions that can be bound to hotkeys.
hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const
command_executor override
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...
void add_area()
Add a new area to the current context, filled with the selection if any.
void play_slice(bool is_delay_enabled=true)
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.
boost::scoped_ptr< font::floating_label_context > floating_label_manager_
GLint GLint GLint GLint GLint GLint y
const std::vector< std::string > items
void play_music_once(const std::string &file)
boost::scoped_ptr< context_manager > context_manager_
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
bool draw_terrain_codes()
void scroll_up(bool on)
Handle hotkeys to scroll map.
Set starting position action.
editor::menu_type active_menu_
Keyboard shortcuts for game actions.
Unit and team statistics.
const std::string & selected_item() const
Return the currently selected item.
GLdouble GLdouble GLdouble b
bool minimap_draw_villages()
Object which defines a time of day with associated bonuses, image, sounds etc.
static const int zoom_amount
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
void scroll_right(bool on)
void scroll_left(bool on)
void right_drag_end(int x, int y, const bool browse)
Called whenever the right mouse drag has "ended".
static UNUSEDNOWARN std::string _(const char *str)
static bool execute(const std::string &title, const std::string &label, std::string &text, CVideo &video)
Executes the dialog.
const map_location & mouseover_hex() const
void toggle_grid()
Grid toggle.
bool allow_mouse_wheel_scroll(int x, int y)
Derived classes can override this to disable mousewheel scrolling under some circumstances, e.g.
std::vector< team > * teams
void terrain_description()
void init_tods(const config &game_config)
init the available time-of-day settings
Implements a quit confirmation dialog.
void show_preferences_dialog(CVideo &video, const config &game_cfg, const DIALOG_OPEN_TO initial_view)
void set_draw_coordinates(bool value)
Setter for the x,y debug overlay on tiles.
GLboolean GLboolean GLboolean GLboolean a
map_location drag_from_hex_
Drag start map location.
void show_unit_list(display &gui)
void preferences()
Show the preferences dialog.
void scroll_down(bool on)
bool draw_hex_coordinates()
virtual hotkey::command_executor * get_hotkey_command_executor()
Get (optionally) a command executor to handle context menu events.
editor_controller(const config &game_config, CVideo &video)
The constructor.
void refresh_image_cache()
Reload images.
Manage the empty-palette in the editor.
void show_menu(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &disp)
controller_base override
void undo()
Undos an action in the current map context.
void invalidate_all()
Function to invalidate all tiles.
boost::scoped_ptr< help::help_manager > help_manager_
const std::string & file_path() const
Paint the same terrain on a number of locations on the map.
bool dragging_left_
LMB drag init flag.
void show_terrain_description(CVideo &video, const terrain_type &t)
const std::string ¶meters float amount
static bool quit()
Shows the quit confirmation if needed.
void set_color_adjustment(int r, int g, int b)
will make all scaled images have these rgb values added to all their pixels.
Encapsulates the map of the game.
void process_keyup_event(const SDL_Event &event)
Process keyup (always).
boost::scoped_ptr< editor_display > gui_
The display object used and owned by the editor.
static void quit_to_desktop()
void init_gui()
init the display object and general set-up
virtual void highlight_hex(map_location hex)
Game configuration data as global variables.
const display_context * get_dummy_display_context()
const t_translation::t_terrain & get_selected_bg_terrain()
const config & game_config_
structure which will hide all current floating labels, and cause floating labels instantiated after i...
Base class for all editor actions.
Internal representation of music tracks.
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.
GLint GLint GLint GLint GLint x
DIRECTION
Valid directions which can be moved in our hexagonal world.
void left_mouse_up(int x, int y, const bool browse)
Called when the left mouse button is up.
void display_redraw_callback(display &)
Callback function passed to display to be called on each redraw_everything run.
std::vector< sound::music_track > music_tracks_
void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc=map_location::null_location())
Called when a mouse motion event takes place.
void perform_delete(editor_action *action)
Perform an action, then delete the action object.
virtual bool execute_command(const hotkey_command &command, int index=-1, bool press=true)
GLuint const GLchar * name
bool do_quit_
Quit main loop flag.
static bool execute(editor::editor_display *display, const std::vector< time_of_day > &tods, CVideo &video)
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.
bool minimap_draw_terrain()
const hotkey::HOTKEY_COMMAND id
the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the objec...
void set_draw_terrain_codes(bool value)
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
Remove a unit from the map.
bool execute_command(const hotkey::hotkey_command &command, int index=-1, bool press=true)
command_executor override
Container associating units to locations.
GLsizei GLenum GLuint GLuint GLsizei char * message
void init_music(const config &game_config)
init background music for the editor
void show_unit_help(CVideo &video, const std::string &show_topic, bool has_variations, bool hidden, int xloc, int yloc)
Open the help browser, show unit with id unit_id.
void set_draw_hex_coordinates(bool value)
unit_iterator find(size_t id)
A config object defines a single node in a WML file, with access to child nodes.
Helper class, don't construct this directly.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
GLsizei const GLcharARB ** string
virtual bool in_context_menu(hotkey::HOTKEY_COMMAND command) const
void right_mouse_up(int x, int y, const bool browse)
Called when the right mouse button is up.
const std::string & id() const
bool minimap_terrain_coding()