16#define GETTEXT_DOMAIN "wesnoth-editor"
69 std::vector<std::shared_ptr<sound::music_track>> tracks;
71 for(
const config& editor_music : editor_music_range) {
72 for(
const config& music : editor_music.child_range(
"music")) {
74 tracks.push_back(std::move(track));
80 ERR_ED <<
"No editor music defined";
88 std::vector<std::unique_ptr<map_generator>> generators;
90 for(
const config&
i : multiplayer_tag_range) {
91 if(
i[
"map_generation"].empty() &&
i[
"scenario_generation"].empty()) {
95 if(
const auto generator_cfg =
i.optional_child(
"generator")) {
96 generators.emplace_back(
create_map_generator(
i[
"map_generation"].str(
i[
"scenario_generation"]), generator_cfg.value()));
109 , mouse_handler_base()
118 , floating_label_manager_(nullptr)
119 , help_manager_(
help::help_manager::get_instance())
122 , music_tracks_(parse_editor_music(game_config_.child_range(
"editor_music")))
123 , map_generators_(parse_map_generators(game_config_.child_range(
"multiplayer")))
164 ERR_ED <<
"Missing ID attribute in a TOD Schedule.";
169 if (times ==
tods_.end()) {
170 std::pair<tods_map::iterator, bool>
new_times =
174 ERR_ED <<
"Duplicate TOD Schedule identifiers.";
179 times->second.second.emplace_back(
time);
185 ERR_ED <<
"No editor time-of-day defined";
220 ERR_ED <<
"Screenshot creation failed!";
229 std::string modified;
234 message =
_(
"Do you really want to quit?");
236 message =
_(
"Do you really want to quit? Changes to this map since the last save will be lost.");
238 message =
_(
"Do you really want to quit? The following maps were modified and all changes since the last save will be lost:");
239 message +=
"\n" + modified;
271 std::placeholders::_1));
275 static constexpr std::string_view
ts_format =
"%Y-%m-%d_%H-%M-%S";
327 int index = cmd.
index;
331 unsigned i =
static_cast<unsigned>(index);
354 case HOTKEY_EDITOR_PALETTE_GROUPS:
356 case HOTKEY_EDITOR_PALETTE_UPSCROLL:
357 return toolkit_->get_palette_manager()->can_scroll_up();
358 case HOTKEY_EDITOR_PALETTE_DOWNSCROLL:
359 return toolkit_->get_palette_manager()->can_scroll_down();
361 return !
gui_->zoom_at_max();
362 case HOTKEY_ZOOM_OUT:
363 return !
gui_->zoom_at_min();
364 case HOTKEY_ZOOM_DEFAULT:
365 case HOTKEY_FULLSCREEN:
366 case HOTKEY_SCREENSHOT:
367 case HOTKEY_MAP_SCREENSHOT:
368 case HOTKEY_TOGGLE_GRID:
369 case HOTKEY_MOUSE_SCROLL:
370 case HOTKEY_ANIMATE_MAP:
372 case HOTKEY_PREFERENCES:
374 case HOTKEY_QUIT_GAME:
375 case HOTKEY_SCROLL_UP:
376 case HOTKEY_SCROLL_DOWN:
377 case HOTKEY_SCROLL_LEFT:
378 case HOTKEY_SCROLL_RIGHT:
381 case HOTKEY_UNIT_LIST:
386 case HOTKEY_STATUS_TABLE:
391 case HOTKEY_TERRAIN_DESCRIPTION:
395 case HOTKEY_DELETE_UNIT:
396 case HOTKEY_RENAME_UNIT:
397 case HOTKEY_EDITOR_UNIT_CHANGE_ID:
398 case HOTKEY_EDITOR_UNIT_TOGGLE_CANRECRUIT:
399 case HOTKEY_EDITOR_UNIT_TOGGLE_RENAMEABLE:
400 case HOTKEY_EDITOR_UNIT_TOGGLE_LOYAL:
401 case HOTKEY_EDITOR_UNIT_FACING:
402 case HOTKEY_UNIT_DESCRIPTION:
406 return (
toolkit_->is_mouse_action_set(HOTKEY_EDITOR_TOOL_UNIT) &&
411 case HOTKEY_EDITOR_PARTIAL_UNDO:
416 case TITLE_SCREEN__RELOAD_WML:
417 case HOTKEY_QUIT_TO_DESKTOP:
418 case HOTKEY_EDITOR_MAP_NEW:
419 case HOTKEY_EDITOR_SCENARIO_NEW:
420 case HOTKEY_EDITOR_MAP_LOAD:
421 case HOTKEY_EDITOR_MAP_SAVE_AS:
425 case HOTKEY_EDITOR_EDIT_UNIT:
429 case HOTKEY_EDITOR_MAP_TO_SCENARIO:
433 case HOTKEY_EDITOR_CUSTOM_TODS:
434 case HOTKEY_EDITOR_SCENARIO_SAVE_AS:
437 case HOTKEY_EDITOR_PBL:
438 case HOTKEY_EDITOR_CHANGE_ADDON_ID:
439 case HOTKEY_EDITOR_SELECT_ADDON:
440 case HOTKEY_EDITOR_OPEN_ADDON:
443 case HOTKEY_EDITOR_AREA_ADD:
444 case HOTKEY_EDITOR_SIDE_NEW:
447 case HOTKEY_EDITOR_SIDE_EDIT:
448 case HOTKEY_EDITOR_SIDE_REMOVE:
452 case HOTKEY_EDITOR_BRUSH_NEXT:
453 case HOTKEY_EDITOR_BRUSH_1:
454 case HOTKEY_EDITOR_BRUSH_2:
455 case HOTKEY_EDITOR_BRUSH_3:
456 case HOTKEY_EDITOR_BRUSH_NW_SE:
457 case HOTKEY_EDITOR_BRUSH_SW_NE:
460 case HOTKEY_EDITOR_TOOL_NEXT:
462 case HOTKEY_EDITOR_PALETTE_ITEM_SWAP:
463 return toolkit_->get_palette_manager()->active_palette().supports_swap();
464 case HOTKEY_EDITOR_MAP_SAVE:
466 case HOTKEY_EDITOR_MAP_SAVE_ALL:
471 case HOTKEY_EDITOR_PLAYLIST:
472 case HOTKEY_EDITOR_SCHEDULE:
474 case HOTKEY_EDITOR_MAP_SWITCH:
475 case HOTKEY_EDITOR_MAP_CLOSE:
477 case HOTKEY_EDITOR_MAP_REVERT:
483 case HOTKEY_EDITOR_TOOL_PAINT:
484 case HOTKEY_EDITOR_TOOL_FILL:
485 case HOTKEY_EDITOR_TOOL_SELECT:
486 case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
489 case HOTKEY_EDITOR_SCENARIO_EDIT:
490 case HOTKEY_EDITOR_TOOL_LABEL:
491 case HOTKEY_EDITOR_TOOL_ITEM:
493 case HOTKEY_EDITOR_TOOL_UNIT:
494 case HOTKEY_EDITOR_TOOL_VILLAGE:
497 case HOTKEY_EDITOR_AREA_REMOVE:
498 case HOTKEY_EDITOR_AREA_RENAME:
499 case HOTKEY_EDITOR_LOCAL_TIME:
503 case HOTKEY_EDITOR_AREA_SAVE:
508 case HOTKEY_EDITOR_SELECTION_EXPORT:
509 case HOTKEY_EDITOR_SELECTION_CUT:
510 case HOTKEY_EDITOR_SELECTION_COPY:
511 case HOTKEY_EDITOR_SELECTION_FILL:
513 && !
toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
514 case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
516 && !
toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
517 case HOTKEY_EDITOR_SELECTION_ROTATE:
518 case HOTKEY_EDITOR_SELECTION_FLIP:
519 case HOTKEY_EDITOR_CLIPBOARD_PASTE:
521 case HOTKEY_EDITOR_CLIPBOARD_ROTATE_CW:
522 case HOTKEY_EDITOR_CLIPBOARD_ROTATE_CCW:
523 case HOTKEY_EDITOR_CLIPBOARD_FLIP_HORIZONTAL:
524 case HOTKEY_EDITOR_CLIPBOARD_FLIP_VERTICAL:
526 &&
toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
527 case HOTKEY_EDITOR_SELECT_ALL:
528 case HOTKEY_EDITOR_SELECT_NONE:
529 return !
toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
530 case HOTKEY_EDITOR_SELECT_INVERSE:
533 && !
toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
534 case HOTKEY_EDITOR_MAP_RESIZE:
535 case HOTKEY_EDITOR_MAP_GENERATE:
536 case HOTKEY_EDITOR_MAP_APPLY_MASK:
537 case HOTKEY_EDITOR_MAP_CREATE_MASK_TO:
538 case HOTKEY_EDITOR_REFRESH:
539 case HOTKEY_EDITOR_UPDATE_TRANSITIONS:
540 case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
541 case HOTKEY_EDITOR_PARTIAL_UPDATE_TRANSITIONS:
542 case HOTKEY_EDITOR_NO_UPDATE_TRANSITIONS:
543 case HOTKEY_EDITOR_REFRESH_IMAGE_CACHE:
544 case HOTKEY_EDITOR_HELP_TEXT_SHOWN:
545 case HOTKEY_MINIMAP_CODING_TERRAIN:
546 case HOTKEY_MINIMAP_CODING_UNIT:
547 case HOTKEY_MINIMAP_DRAW_UNITS:
548 case HOTKEY_MINIMAP_DRAW_TERRAIN:
549 case HOTKEY_MINIMAP_DRAW_VILLAGES:
550 case HOTKEY_EDITOR_REMOVE_LOCATION:
552 case HOTKEY_EDITOR_DRAW_COORDINATES:
553 case HOTKEY_EDITOR_DRAW_TERRAIN_CODES:
554 case HOTKEY_EDITOR_DRAW_NUM_OF_BITMAPS:
564 int index = cmd.
index;
567 case HOTKEY_EDITOR_UNIT_TOGGLE_LOYAL:
573 case HOTKEY_EDITOR_UNIT_TOGGLE_CANRECRUIT:
579 case HOTKEY_EDITOR_UNIT_TOGGLE_RENAMEABLE:
586 case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
588 case HOTKEY_EDITOR_PARTIAL_UPDATE_TRANSITIONS:
590 case HOTKEY_EDITOR_NO_UPDATE_TRANSITIONS:
592 case HOTKEY_EDITOR_BRUSH_1:
594 case HOTKEY_EDITOR_BRUSH_2:
596 case HOTKEY_EDITOR_BRUSH_3:
598 case HOTKEY_EDITOR_BRUSH_NW_SE:
600 case HOTKEY_EDITOR_BRUSH_SW_NE:
603 case HOTKEY_TOGGLE_GRID:
605 case HOTKEY_EDITOR_SELECT_ALL:
607 case HOTKEY_EDITOR_SELECT_NONE:
609 case HOTKEY_EDITOR_TOOL_FILL:
610 case HOTKEY_EDITOR_TOOL_LABEL:
611 case HOTKEY_EDITOR_TOOL_PAINT:
612 case HOTKEY_EDITOR_TOOL_SELECT:
613 case HOTKEY_EDITOR_CLIPBOARD_PASTE:
614 case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
615 case HOTKEY_EDITOR_TOOL_UNIT:
616 case HOTKEY_EDITOR_TOOL_VILLAGE:
617 case HOTKEY_EDITOR_TOOL_ITEM:
619 case HOTKEY_EDITOR_DRAW_COORDINATES:
621 case HOTKEY_EDITOR_DRAW_TERRAIN_CODES:
623 case HOTKEY_EDITOR_DRAW_NUM_OF_BITMAPS:
625 case HOTKEY_EDITOR_HELP_TEXT_SHOWN:
627 case HOTKEY_MINIMAP_DRAW_VILLAGES:
629 case HOTKEY_MINIMAP_CODING_UNIT:
631 case HOTKEY_MINIMAP_CODING_TERRAIN:
633 case HOTKEY_MINIMAP_DRAW_UNITS:
635 case HOTKEY_MINIMAP_DRAW_TERRAIN:
637 case HOTKEY_ZOOM_DEFAULT:
661 tods_map::const_iterator
it =
tods_.begin();
662 std::advance(
it, index);
663 const std::vector<time_of_day>&
times1 =
it->second.second;
669 tods_map::const_iterator
it =
tods_.begin();
670 std::advance(
it, index);
671 const std::vector<time_of_day>&
times1 =
it->second.second;
687 return command_executor::get_action_state(cmd);
696 int index = cmd.
index;
700 return command_executor::do_execute_command(cmd, press, release);
708 unsigned i =
static_cast<unsigned>(index);
711 toolkit_->hotkey_set_mouse_action(HOTKEY_EDITOR_TOOL_PAINT);
722 toolkit_->get_palette_manager()->set_group(index);
725 gui_->set_viewing_team_index(index,
true);
726 gui_->set_playing_team_index(index);
727 toolkit_->get_palette_manager()->draw_contents();
732 const std::set<map_location>&
area =
759 std::advance(
iter, index);
768 std::advance(
iter, index);
777 un->anim_comp().set_standing();
787 gui_->set_zoom(
true);
791 case HOTKEY_ZOOM_OUT:
792 gui_->set_zoom(
false);
796 case HOTKEY_ZOOM_DEFAULT:
797 gui_->toggle_default_zoom();
803 case HOTKEY_EDITOR_PALETTE_GROUPS:
810 case HOTKEY_EDITOR_PALETTE_UPSCROLL:
811 toolkit_->get_palette_manager()->scroll_up();
813 case HOTKEY_EDITOR_PALETTE_DOWNSCROLL:
814 toolkit_->get_palette_manager()->scroll_down();
817 case HOTKEY_QUIT_GAME:
823 case HOTKEY_QUIT_TO_DESKTOP:
826 case TITLE_SCREEN__RELOAD_WML:
831 case HOTKEY_EDITOR_EDIT_UNIT:
834 case HOTKEY_EDITOR_CUSTOM_TODS:
837 case HOTKEY_EDITOR_PALETTE_ITEM_SWAP:
838 toolkit_->get_palette_manager()->active_palette().swap();
840 case HOTKEY_EDITOR_PARTIAL_UNDO:
850 case HOTKEY_EDITOR_TOOL_PAINT:
851 case HOTKEY_EDITOR_TOOL_FILL:
852 case HOTKEY_EDITOR_TOOL_SELECT:
853 case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
854 case HOTKEY_EDITOR_TOOL_LABEL:
855 case HOTKEY_EDITOR_TOOL_UNIT:
856 case HOTKEY_EDITOR_TOOL_VILLAGE:
857 case HOTKEY_EDITOR_TOOL_ITEM:
858 toolkit_->hotkey_set_mouse_action(command);
861 case HOTKEY_EDITOR_PBL:
867 case HOTKEY_EDITOR_CHANGE_ADDON_ID:
873 case HOTKEY_EDITOR_SELECT_ADDON:
877 case HOTKEY_EDITOR_OPEN_ADDON:
907 case HOTKEY_EDITOR_AREA_ADD:
911 case HOTKEY_EDITOR_UNIT_CHANGE_ID:
915 case HOTKEY_EDITOR_UNIT_TOGGLE_RENAMEABLE:
919 bool unrenamable = un->unrenamable();
920 un->set_unrenamable(!unrenamable);
923 case HOTKEY_EDITOR_UNIT_TOGGLE_CANRECRUIT:
929 un->anim_comp().set_standing();
932 case HOTKEY_EDITOR_UNIT_TOGGLE_LOYAL:
936 bool loyal = un->loyal();
937 un->set_loyal(!loyal);
940 case HOTKEY_DELETE_UNIT:
946 case HOTKEY_EDITOR_CLIPBOARD_PASTE:
947 toolkit_->hotkey_set_mouse_action(command);
951 case HOTKEY_EDITOR_CLIPBOARD_ROTATE_CW:
953 toolkit_->update_mouse_action_highlights();
955 case HOTKEY_EDITOR_CLIPBOARD_ROTATE_CCW:
957 toolkit_->update_mouse_action_highlights();
959 case HOTKEY_EDITOR_CLIPBOARD_FLIP_HORIZONTAL:
961 toolkit_->update_mouse_action_highlights();
963 case HOTKEY_EDITOR_CLIPBOARD_FLIP_VERTICAL:
965 toolkit_->update_mouse_action_highlights();
969 case HOTKEY_EDITOR_BRUSH_NEXT:
972 case HOTKEY_EDITOR_BRUSH_1:
975 case HOTKEY_EDITOR_BRUSH_2:
978 case HOTKEY_EDITOR_BRUSH_3:
981 case HOTKEY_EDITOR_BRUSH_NW_SE:
984 case HOTKEY_EDITOR_BRUSH_SW_NE:
988 case HOTKEY_EDITOR_SELECTION_COPY:
991 case HOTKEY_EDITOR_SELECTION_CUT:
994 case HOTKEY_EDITOR_AREA_RENAME:
997 case HOTKEY_EDITOR_AREA_SAVE:
1000 case HOTKEY_EDITOR_SELECTION_EXPORT:
1003 case HOTKEY_EDITOR_SELECT_ALL:
1009 case HOTKEY_EDITOR_SELECT_INVERSE:
1012 case HOTKEY_EDITOR_SELECT_NONE:
1015 case HOTKEY_EDITOR_SELECTION_FILL:
1018 case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
1023 case HOTKEY_EDITOR_SCENARIO_EDIT:
1027 case HOTKEY_EDITOR_AREA_REMOVE:
1033 case HOTKEY_EDITOR_MAP_CLOSE:
1038 toolkit_->hotkey_set_mouse_action(HOTKEY_EDITOR_TOOL_PAINT);
1040 case HOTKEY_EDITOR_MAP_LOAD:
1043 case HOTKEY_EDITOR_MAP_REVERT:
1046 case HOTKEY_EDITOR_MAP_NEW:
1049 case HOTKEY_EDITOR_SCENARIO_NEW:
1054 case HOTKEY_EDITOR_MAP_SAVE:
1057 case HOTKEY_EDITOR_MAP_SAVE_ALL:
1060 case HOTKEY_EDITOR_MAP_SAVE_AS:
1063 case HOTKEY_EDITOR_MAP_TO_SCENARIO:
1068 case HOTKEY_EDITOR_SCENARIO_SAVE_AS:
1073 case HOTKEY_EDITOR_MAP_GENERATE:
1076 case HOTKEY_EDITOR_MAP_APPLY_MASK:
1079 case HOTKEY_EDITOR_MAP_CREATE_MASK_TO:
1082 case HOTKEY_EDITOR_MAP_RESIZE:
1087 case HOTKEY_EDITOR_SIDE_NEW:
1095 case HOTKEY_EDITOR_SIDE_REMOVE:
1096 gui_->set_viewing_team_index(0,
true);
1097 gui_->set_playing_team_index(0);
1100 case HOTKEY_EDITOR_SIDE_EDIT:
1105 case HOTKEY_EDITOR_PARTIAL_UPDATE_TRANSITIONS:
1108 case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
1111 case HOTKEY_EDITOR_NO_UPDATE_TRANSITIONS:
1114 case HOTKEY_EDITOR_TOGGLE_TRANSITIONS:
1119 case HOTKEY_EDITOR_UPDATE_TRANSITIONS:
1123 case HOTKEY_EDITOR_REFRESH:
1126 case HOTKEY_EDITOR_REFRESH_IMAGE_CACHE:
1130 case HOTKEY_EDITOR_DRAW_COORDINATES:
1135 case HOTKEY_EDITOR_DRAW_TERRAIN_CODES:
1140 case HOTKEY_EDITOR_DRAW_NUM_OF_BITMAPS:
1145 case HOTKEY_EDITOR_HELP_TEXT_SHOWN:
1147 prefs::get().set_editor_help_text_shown(
gui().help_string_enabled());
1149 case HOTKEY_EDITOR_REMOVE_LOCATION: {
1202 std::vector<config> items;
1204 const std::string&
id =
c[
"id"];
1210 items.emplace_back(
"id",
id);
1220 const std::string&
first_id = items.front()[
"id"];
1225 if(
first_id ==
"EDITOR-LOAD-MRU-PLACEHOLDER") {
1230 else if(
first_id ==
"editor-switch-map") {
1235 else if(
first_id ==
"editor-palette-groups") {
1237 toolkit_->get_palette_manager()->active_palette().expand_palette_groups_menu(
generated);
1240 else if(
first_id ==
"editor-switch-side") {
1245 else if(
first_id ==
"editor-switch-area") {
1250 else if(
first_id ==
"editor-switch-time") {
1255 else if(
first_id ==
"editor-assign-local-time") {
1260 else if(
first_id ==
"menu-unit-facings") {
1263 std::generate_n(std::back_inserter(
generated), count, [dir = 0]()
mutable {
1268 else if(
first_id ==
"editor-playlist") {
1271 [](
const std::shared_ptr<sound::music_track>& track) {
1272 return config{
"label", track->title().empty() ? track->id() : track->title()};
1276 else if(first_id ==
"editor-assign-schedule") {
1277 active_menu_ = menu_type::schedule;
1278 std::transform(tods_.begin(), tods_.end(), std::back_inserter(generated),
1279 [](
const tods_map::value_type& tod) { return config{
"label", tod.second.first}; });
1282 else if(first_id ==
"editor-assign-local-schedule") {
1283 active_menu_ = menu_type::local_schedule;
1284 std::transform(tods_.begin(), tods_.end(), std::back_inserter(generated),
1285 [](
const tods_map::value_type& tod) { return config{
"label", tod.second.first}; });
1290 command_executor::show_menu(items, menu_loc, context_menu);
1295 if(items.size() > 1) {
1296 std::move(items.begin() + 1, items.end(), std::back_inserter(generated));
1299 command_executor::show_menu(generated, menu_loc, context_menu);
1302void editor_controller::preferences()
1304 gui_->clear_help_string();
1305 gui2::dialogs::preferences_dialog::display();
1307 gui_->queue_rerender();
1310void editor_controller::toggle_grid()
1313 gui_->invalidate_all();
1316void editor_controller::unit_description()
1319 const unit_map& units = get_current_map_context().units();
1321 if(un != units.
end()) {
1329void editor_controller::copy_selection()
1331 if(get_current_map_context().map().anything_selected()) {
1332 context_manager_->get_clipboard() =
map_fragment(get_current_map_context().map(), get_current_map_context().map().selection());
1333 context_manager_->get_clipboard().center_by_mass();
1337void editor_controller::change_unit_id()
1340 unit_map& units = get_current_map_context().units();
1343 const std::string title(
N_(
"Change Unit ID"));
1344 const std::string
label(
N_(
"ID:"));
1346 if(un != units.
end()) {
1347 std::string
id = un->id();
1348 if (gui2::dialogs::edit_text::execute(title,
label,
id)) {
1354void editor_controller::rename_unit()
1357 unit_map& units = get_current_map_context().units();
1360 const std::string title(
N_(
"Rename Unit"));
1361 const std::string
label(
N_(
"Name:"));
1363 if(un != units.
end()) {
1364 std::string name = un->name();
1365 if(gui2::dialogs::edit_text::execute(title,
label, name)) {
1372void editor_controller::unit_list()
1374 std::vector<unit_const_ptr> unit_list;
1378 if(
i->side() !=
gui().viewing_team().side()) {
1381 unit_list.push_back(
i.get_shared_ptr());
1386 if (unit_dlg->show() && unit_dlg->is_selected()) {
1387 const map_location&
loc = unit_list[unit_dlg->get_selected_index()]->get_location();
1393void editor_controller::cut_selection()
1399void editor_controller::save_area()
1401 const std::set<map_location>& area = get_current_map_context().map().selection();
1402 get_current_map_context().save_area(area);
1405void editor_controller::add_area()
1407 const std::set<map_location>& area = get_current_map_context().map().selection();
1408 get_current_map_context().new_area(area);
1411void editor_controller::export_selection_coords()
1413 std::stringstream ssx, ssy;
1414 auto selection = get_current_map_context().map().selection();
1415 std::set<map_location>::const_iterator
i = selection.begin();
1416 if (
i != selection.end()) {
1417 ssx <<
"x = " <<
i->wml_x();
1418 ssy <<
"y = " <<
i->wml_y();
1420 while (
i != selection.end()) {
1421 ssx <<
", " <<
i->wml_x();
1422 ssy <<
", " <<
i->wml_y();
1425 ssx <<
"\n" << ssy.str() <<
"\n";
1430void editor_controller::perform_delete(std::unique_ptr<editor_action> action)
1433 get_current_map_context().perform_action(*action);
1437void editor_controller::perform_refresh_delete(std::unique_ptr<editor_action> action,
bool drag_part )
1440 context_manager_->perform_refresh(*action, drag_part);
1444void editor_controller::refresh_image_cache()
1447 context_manager_->refresh_all();
1450void editor_controller::display_redraw_callback(
display&)
1453 toolkit_->adjust_size();
1454 get_current_map_context().get_labels().recalculate_labels();
1457void editor_controller::undo()
1459 get_current_map_context().undo();
1460 context_manager_->refresh_after_action();
1463void editor_controller::redo()
1465 get_current_map_context().redo();
1466 context_manager_->refresh_after_action();
1469void editor_controller::mouse_motion(
int x,
int y,
const bool ,
1472 if (mouse_handler_base::mouse_motion_default(x, y, update))
return;
1474 if (get_current_map_context().map().on_board_with_border(drag_from_hex_) && is_dragging()) {
1475 std::unique_ptr<editor_action> a;
1479 auto last_undo = get_current_map_context().last_undo_action();
1481 if (!get_current_map_context().map().on_board_with_border(hex_clicked))
return;
1482 a = get_mouse_action().drag_left(*gui_, x, y,
partial, last_undo);
1484 if (!get_current_map_context().map().on_board_with_border(hex_clicked))
return;
1485 a = get_mouse_action().drag_right(*gui_, x, y,
partial, last_undo);
1492 get_current_map_context().perform_partial_action(*a);
1494 get_current_map_context().perform_action(*a);
1496 context_manager_->refresh_after_action(
true);
1499 get_mouse_action().move(*gui_, hex_clicked);
1501 gui().highlight_hex(hex_clicked);
1504void editor_controller::touch_motion(
int ,
int ,
const bool ,
bool ,
map_location )
1509bool editor_controller::allow_mouse_wheel_scroll(
int x,
int y)
1511 return get_current_map_context().map().on_board_with_border(
gui().hex_clicked_on(x,y));
1514bool editor_controller::right_click_show_menu(
int ,
int ,
const bool )
1516 return get_mouse_action().has_context_menu();
1519bool editor_controller::left_click(
int x,
int y,
const bool browse)
1521 toolkit_->clear_mouseover_overlay();
1522 if (mouse_handler_base::left_click(x, y, browse))
1525 LOG_ED <<
"Left click, after generic handling";
1527 if (!get_current_map_context().map().on_board_with_border(hex_clicked))
1530 LOG_ED <<
"Left click action " << hex_clicked;
1531 auto a = get_mouse_action().click_left(*gui_, x, y);
1533 perform_refresh_delete(std::move(a),
true);
1540void editor_controller::left_drag_end(
int x,
int y,
const bool )
1542 auto a = get_mouse_action().drag_end_left(*gui_, x, y);
1543 perform_delete(std::move(a));
1546void editor_controller::left_mouse_up(
int x,
int y,
const bool )
1548 auto a = get_mouse_action().up_left(*gui_, x, y);
1550 perform_delete(std::move(a));
1553 toolkit_->set_mouseover_overlay();
1554 context_manager_->refresh_after_action();
1557bool editor_controller::right_click(
int x,
int y,
const bool browse)
1559 toolkit_->clear_mouseover_overlay();
1560 if (mouse_handler_base::right_click(x, y, browse))
return true;
1561 LOG_ED <<
"Right click, after generic handling";
1563 if (!get_current_map_context().map().on_board_with_border(hex_clicked))
return true;
1564 LOG_ED <<
"Right click action " << hex_clicked;
1565 auto a = get_mouse_action().click_right(*gui_, x, y);
1567 perform_refresh_delete(std::move(a),
true);
1573void editor_controller::right_drag_end(
int x,
int y,
const bool )
1575 auto a = get_mouse_action().drag_end_right(*gui_, x, y);
1576 perform_delete(std::move(a));
1579void editor_controller::right_mouse_up(
int x,
int y,
const bool browse)
1582 mouse_handler_base::right_mouse_up(x, y, browse);
1584 auto a = get_mouse_action().up_right(*gui_, x, y);
1586 perform_delete(std::move(a));
1589 toolkit_->set_mouseover_overlay();
1590 context_manager_->refresh_after_action();
1593void editor_controller::terrain_description()
1596 if (get_current_map_context().map().on_board(
loc) ==
false)
1599 const terrain_type& type = get_current_map_context().map().get_terrain_info(
loc);
1603void editor_controller::process_keyup_event(
const SDL_Event& event)
1605 auto a = get_mouse_action().key_event(
gui(), event);
1606 perform_refresh_delete(std::move(a));
1607 toolkit_->set_mouseover_overlay();
1614void editor_controller::scroll_up(
bool on)
1619void editor_controller::scroll_down(
bool on)
1624void editor_controller::scroll_left(
bool on)
1629void editor_controller::scroll_right(
bool on)
1634std::vector<std::string> editor_controller::additional_actions_pressed()
1636 return toolkit_->get_palette_manager()->active_palette().action_pressed();
A config object defines a single node in a WML file, with access to child nodes.
void set_scroll_up(bool on)
void set_scroll_left(bool on)
void set_scroll_right(bool on)
const game_config_view & game_config_
void set_scroll_down(bool on)
virtual void play_slice()
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
void toggle_debug_flag(DEBUG_FLAG flag)
void change_display_context(const display_context *dc)
void add_redraw_observer(const std::function< void(display &)> &f)
Adds a redraw observer, a function object to be called when a full rerender is queued.
@ DEBUG_COORDINATES
Overlays x,y coords on tiles.
@ DEBUG_NUM_BITMAPS
Overlays number of bitmaps on tiles.
@ DEBUG_TERRAIN_CODES
Overlays terrain codes on tiles.
void invalidate_all()
Function to invalidate all tiles.
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
void queue_rerender()
Marks everything for rendering including all tiles and sidebar.
void set_debug_flag(DEBUG_FLAG flag, bool value)
const map_location & mouseover_hex() const
Container action wrapping several actions into one.
Paint the same terrain on a number of locations on the map.
Randomize terrain in an area.
The editor_controller class contains the mouse and keyboard event handling routines for the editor.
const std::unique_ptr< context_manager > context_manager_
void refresh_image_cache()
Reload images.
editor_display & gui() override
Reference to the used display objects.
void unit_editor_dialog()
Show Unit Editor dialog.
bool can_execute_command(const hotkey::ui_command &command) const override
command_executor override
bool quit_confirm()
Show a quit confirmation dialog and returns true if the user pressed 'yes'.
void update_map_schedule(const std::vector< time_of_day > &schedule)
Updates schedule and the map display.
void cut_selection()
Cut the selection from the current map to the clipboard.
bool keep_menu_open() const override
command_executor override
void display_redraw_callback(display &)
Callback function passed to display to be called on queue_rerender.
std::unique_ptr< font::floating_label_context > floating_label_manager_
menu_type active_menu_
The currently invoked dropdown menu.
void undo() override
Undos an action in the current map context.
void select_addon()
Show dialog to select active addon or create a new one.
map_context & get_current_map_context() const
void init_tods(const game_config_view &game_config)
init the available time-of-day settings
bool initialize_addon()
Show dialog to select active addon or create a new one if one is not yet initialized.
void status_table() override
std::unique_ptr< editor_toolkit > toolkit_
std::vector< std::shared_ptr< sound::music_track > > music_tracks_
const std::unique_ptr< editor_display > gui_
The display object used and owned by the editor.
bool do_execute_command(const hotkey::ui_command &command, bool press=true, bool release=false) override
command_executor override
void export_selection_coords()
Export the WML-compatible list of selected tiles to the system clipboard.
void perform_delete(std::unique_ptr< editor_action > action)
Perform an action, then delete the action object.
std::vector< std::unique_ptr< map_generator > > map_generators_
Available random map generators.
EXIT_STATUS main_loop()
Editor main loop.
editor_controller(const editor_controller &)=delete
void custom_tods_dialog()
Display the settings dialog, used to control e.g.
void do_screenshot(const std::string &screenshot_filename="map_screenshot.png")
Takes a screenshot.
void save_area()
Save the current selection to the active area.
void copy_selection()
Copy the selection on the current map to the clipboard.
void show_help() override
void init_gui()
init the display object and general set-up
hotkey::action_state get_action_state(const hotkey::ui_command &command) const override
command_executor override
void show_menu(const std::vector< config > &items_arg, const point &menu_loc, bool context_menu) override
command_executor override
static std::string current_addon_id_
void add_area()
Add a new area to the current context, filled with the selection if any.
const mouse_action & get_mouse_action() const
Get the current mouse action.
bool do_quit_
Quit main loop flag.
void save_map() override
Save the map, open dialog if not named yet.
void set_help_string_enabled(bool value)
Sets whether the help text should be shown.
bool everything_selected() const
bool anything_selected() const
std::size_t num_selected() const
List of starting locations and location ids.
void remove_side()
removes the last side from the scenario
void set_active_area(int index)
void set_local_starting_time(int time)
int get_active_area() const
map_labels & get_labels()
void toggle_track(const std::shared_ptr< sound::music_track > &track)
Remove the given track from the current playlist if present, else appends it.
void new_side()
Adds a new side to the map.
const std::string & get_filename() const
void set_starting_time(int time)
virtual const editor_map & map() const override
Const map accessor.
virtual const unit_map & units() const override
Const units accessor.
void replace_schedule(const std::vector< time_of_day > &schedule)
void remove_area(int index)
const tod_manager * get_time_manager() const
void select_area(int index)
Select the nth tod area.
void replace_local_schedule(const std::vector< time_of_day > &schedule)
Replace the [time]s of the currently active area.
void partial_undo()
Un-does a single step from a undo action chain.
virtual const std::vector< team > & teams() const override
Const teams accessor.
void set_starting_position_labels(display &disp)
void save_schedule(const std::string &schedule_id, const std::string &schedule_name)
Save custom time of day schedule in the utils directory.
A map fragment – a collection of locations and information abut them.
virtual bool supports_brushes() const
Whether we need the brush bar, is used to grey it out.
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Dialog that allows user to create custom unit types.
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
std::string path() const
Gets the current file selection.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
@ auto_close
Enables auto close.
static std::unique_ptr< units_dialog > build_unit_list_dialog(std::vector< unit_const_ptr > &units_list)
virtual bool do_execute_command(const hotkey::ui_command &command, bool press=true, bool release=false)
virtual bool in_context_menu(const hotkey::ui_command &) const
Determines whether the command should be in the context menu or not.
void recalculate_labels()
Implements a quit confirmation dialog.
static bool show_prompt(const std::string &message)
static bool quit()
Shows the quit confirmation if needed.
static void quit_to_desktop()
static std::shared_ptr< music_track > create(const config &cfg)
const std::vector< time_of_day > & times() const
std::vector< std::string > get_area_ids() const
const std::set< map_location > & get_area_by_index(int index) const
int get_current_time() const
Container associating units to locations.
unit_iterator find(std::size_t id)
std::vector< std::reference_wrapper< const config > > config_array_view
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)
auto format_local_timestamp(const std::chrono::system_clock::time_point &time, std::string_view format="%F %T")
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void copy_to_clipboard(const std::string &text)
Copies text to the clipboard.
constexpr bool open_object_is_supported()
Returns whether open_object() is supported/implemented for the current platform.
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
Manage the empty-palette in the editor.
const t_translation::terrain_code & get_selected_bg_terrain()
std::string initialize_addon()
bool is_cfg(const std::string &filename)
Returns true if the file ends with the wmlfile extension.
bool is_map(const std::string &filename)
Returns true if the file ends with the mapfile extension.
std::string get_current_editor_dir(const std::string &addon_id)
Game configuration data as global variables.
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.
void show_terrain_description(const terrain_type &t)
void show_unit_description(const unit &u)
void show_help(const std::string &show_topic)
Open the help browser.
Keyboard shortcuts for game actions.
action_state on_if(bool condition)
Returns action_state::on if condition is true, else action_state::off.
action_state selected_if(bool condition)
Returns action_state::selected if condition is true, else action_state::deselected.
void flush_cache()
Purges all image caches.
save_result save_image(const locator &i_locator, const std::string &filename)
Unit and team statistics.
::tod_manager * tod_manager
game_classification * classification
filter_context * filter_con
uint32_t get_mouse_button_mask()
Returns the current mouse button mask.
void play_music_once(const std::string &file)
Desktop environment interaction functions.
@ partial
There are still moves and/or attacks possible, but the unit doesn't fit in the "unmoved" status.
#define ON_SCOPE_EXIT(...)
Run some arbitrary code (a lambda) when the current scope exits The lambda body follows this header,...
structure which will hide all current floating labels, and cause floating labels instantiated after i...
Used as the main parameter for can_execute_command/do_execute_command These functions are used to exe...
hotkey::HOTKEY_COMMAND hotkey_command
The hotkey::HOTKEY_COMMAND associated with this action, HOTKEY_NULL for actions that don't allow hotk...
int index
When this action was the result of a menu click, this is the index of the clicked item in the menu.
Encapsulates the map of the game.
direction
Valid directions which can be moved in our hexagonal world.
static std::string write_translated_direction(direction dir)
Helper class, don't construct this directly.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...