The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
context_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
16 #include "resources.hpp"
17 #include "team.hpp"
18 
19 #include "display.hpp"
22 #include "filesystem.hpp"
23 #include "formula/string_utils.hpp"
24 #include "game_board.hpp"
27 #include "gettext.hpp"
28 
29 #include "editor/action/action.hpp"
31 #include "preferences/editor.hpp"
32 
38 #include "gui/dialogs/message.hpp"
40 #include "gui/widgets/window.hpp"
41 
44 
45 #include "terrain/translation.hpp"
46 
47 #include <memory>
48 
49 namespace editor {
50 
51 static std::vector<std::string> saved_windows_;
52 
53 static const std::string get_menu_marker(const bool changed)
54 {
55  std::ostringstream ss;
56  ss << "[<span ";
57 
58  if(changed) {
59  ss << "color='#f00' ";
60  }
61 
62  ss << "size='large'>" << font::unicode_bullet << "</span>]";
63  return ss.str();
64 }
65 
66 /**
67  * Utility class to properly refresh the display when the map context object is replaced
68  * without duplicating code.
69  */
71 {
72 public:
74  : context_manager_(ec)
75  , refreshed_(false)
76  {
77  }
78 
80  {
81  if(!refreshed_) refresh();
82  }
83 
84  void refresh()
85  {
87 
88  // TODO register the tod_manager with the gui?
92 
94 
96 
98 
100 
101  // Enable the labels of the current context;
103 
104  refreshed_ = true;
105  }
106 
107 private:
110 };
111 
112 
114  : gui_(gui)
115  , game_config_(game_config)
116  , default_dir_(preferences::editor::default_dir())
117  , map_generators_()
118  , last_map_generator_(nullptr)
119  , current_context_index_(0)
120  , auto_update_transitions_(preferences::editor::auto_update_transitions())
121  , map_contexts_()
122  , clipboard_()
123 {
124  if(default_dir_.empty()) {
126  }
127 
129  init_map_generators(game_config);
130 }
131 
133 {
134  // Restore default window title
136 }
137 
139 {
140  gui_.rebuild_all();
146 }
147 
149 {
150  gui_.reload_map();
153  refresh_all();
154 }
155 
157 {
158  switch (auto_update_transitions_) {
160  return (item == "editor-auto-update-transitions");
162  return (item == "editor-partial-update-transitions");
164  return (item == "editor-no-update-transitions");
165  }
166 
167  return true; //should not be reached
168 }
169 
171 {
174 
176  return true;
177  }
178 
179  return false;
180 }
181 
183 {
184  std::vector<std::string> modified;
185  for(auto& mc : map_contexts_) {
186  if(mc->modified()) {
187  if(!mc->get_name().empty()) {
188  modified.push_back(mc->get_name());
189  } else if(!mc->get_filename().empty()) {
190  modified.push_back(mc->get_filename());
191  } else {
192  modified.push_back(mc->get_default_context_name());
193  }
194  }
195  }
196 
197  for(std::string& str : modified) {
198  message += "\n" + font::unicode_bullet + " " + str;
199  }
200 
201  return modified.size();
202 }
203 
204 void context_manager::load_map_dialog(bool force_same_context /* = false */)
205 {
207  if(fn.empty()) {
208  fn = default_dir_;
209  }
210 
212 
213  dlg.set_title(_("Load Map"))
214  .set_path(fn);
215 
216  if(dlg.show()) {
217  load_map(dlg.path(), !force_same_context);
218  }
219 }
220 
221 void context_manager::load_mru_item(unsigned int index, bool force_same_context /* = false */)
222 {
223  const std::vector<std::string>& mru = preferences::editor::recent_files();
224  if(mru.empty() || index >= mru.size()) {
225  return;
226  }
227 
228  load_map(mru[index], !force_same_context);
229 }
230 
232 {
233  team& t = get_map_context().get_teams()[side_index];
234 
235  editor_team_info team_info(t);
236 
237  if(gui2::dialogs::editor_edit_side::execute(team_info)) {
238  get_map_context().set_side_setup(team_info);
239  }
240 }
241 
243 {
244  map_context& context = get_map_context();
245 
246  // TODO
247  //std::string fn = filesystem::directory_name(context.get_filename());
248 
249  std::string id = context.get_id();
250  std::string name = context.get_name();
251  std::string description = context.get_description();
252 
253  int turns = context.get_time_manager()->number_of_turns();
254  int xp_mod = context.get_xp_mod();
255 
256  bool victory = context.victory_defeated();
257  bool random = context.random_start_time();
258 
259  const bool ok = gui2::dialogs::editor_edit_scenario::execute(
260  id, name, description, turns, xp_mod, victory, random
261  );
262 
263  if(!ok) {
264  return;
265  }
266 
267  context.set_scenario_setup(id, name, description, turns, xp_mod, victory, random);
268 
269  if(!name.empty()) {
271  }
272 }
273 
275 {
276  int w = get_map().w();
277  int h = get_map().h();
278 
279  if(gui2::dialogs::editor_new_map::execute(_("New Map"), w, h)) {
281  new_map(w, h, fill, true);
282  }
283 }
284 
286 {
287  int w = get_map().w();
288  int h = get_map().h();
289 
290  if(gui2::dialogs::editor_new_map::execute(_("New Scenario"), w, h)) {
292  new_scenario(w, h, fill, true);
293  }
294 }
295 
296 void context_manager::expand_open_maps_menu(std::vector<config>& items, int i)
297 {
298  auto pos = items.erase(items.begin() + i);
299  std::vector<config> contexts;
300 
301  for(size_t mci = 0; mci < map_contexts_.size(); ++mci) {
302  map_context& mc = *map_contexts_[mci];
303 
304  std::string filename;
305  if(mc.is_pure_map()) {
306  filename = filesystem::base_name(mc.get_filename());
307  } else {
308  filename = mc.get_name();
309  }
310 
311  if(filename.empty()) {
312  filename = mc.get_default_context_name();
313  }
314 
315  std::ostringstream ss;
316  ss << "[" << mci + 1 << "] ";
317 
318  const bool changed = mc.modified();
319 
320  if(changed) {
321  ss << "<i>" << filename << "</i>";
322  } else {
323  ss << filename;
324  }
325 
326  if(mc.is_embedded()) {
327  ss << " (E)";
328  }
329 
330  const std::string label = ss.str();
331  const std::string details = get_menu_marker(changed);
332 
333  contexts.emplace_back(config {"label", label, "details", details});
334  }
335 
336  items.insert(pos, contexts.begin(), contexts.end());
337 }
338 
339 void context_manager::expand_load_mru_menu(std::vector<config>& items, int i)
340 {
341  std::vector<std::string> mru = preferences::editor::recent_files();
342 
343  auto pos = items.erase(items.begin() + i);
344 
345  if(mru.empty()) {
346  items.insert(pos, config {"label", _("No Recent Files")});
347  return;
348  }
349 
350  for(std::string& path : mru) {
351  // TODO: add proper leading ellipsization instead, since otherwise
352  // it'll be impossible to tell apart files with identical names and
353  // different parent paths.
355  }
356 
357  std::vector<config> temp;
358  std::transform(mru.begin(), mru.end(), std::back_inserter(temp), [](const std::string& str) {
359  return config {"label", str};
360  });
361 
362  items.insert(pos, temp.begin(), temp.end());
363 }
364 
365 void context_manager::expand_areas_menu(std::vector<config>& items, int i)
366 {
368  if(!tod) {
369  return;
370  }
371 
372  auto pos = items.erase(items.begin() + i);
373  std::vector<config> area_entries;
374 
375  std::vector<std::string> area_ids = tod->get_area_ids();
376 
377  for(size_t mci = 0; mci < area_ids.size(); ++mci) {
378  const std::string& area = area_ids[mci];
379 
380  std::stringstream ss;
381  ss << "[" << mci + 1 << "] ";\
382 
383  if(area.empty()) {
384  ss << "<i>" << _("Unnamed Area") << "</i>";
385  } else {
386  ss << area;
387  }
388 
389  const bool changed =
390  mci == static_cast<size_t>(get_map_context().get_active_area())
391  && tod->get_area_by_index(mci) != get_map_context().get_map().selection();
392 
393  const std::string label = ss.str();
394  const std::string details = get_menu_marker(changed);
395 
396  area_entries.emplace_back(config {"label", label, "details", details});
397  }
398 
399  items.insert(pos, area_entries.begin(), area_entries.end());
400 }
401 
402 void context_manager::expand_sides_menu(std::vector<config>& items, int i)
403 {
404  auto pos = items.erase(items.begin() + i);
405  std::vector<config> contexts;
406 
407  for(size_t mci = 0; mci < get_map_context().get_teams().size(); ++mci) {
408 
409  const team& t = get_map_context().get_teams()[mci];
410  const std::string& teamname = t.user_team_name();
411  std::stringstream label;
412  label << "[" << mci+1 << "] ";
413 
414  if(teamname.empty()) {
415  label << "<i>" << _("New Side") << "</i>";
416  } else {
417  label << teamname;
418  }
419 
420  contexts.emplace_back(config {"label", label.str()});
421  }
422 
423  items.insert(pos, contexts.begin(), contexts.end());
424 }
425 
426 void context_manager::expand_time_menu(std::vector<config>& items, int i)
427 {
428  auto pos = items.erase(items.begin() + i);
429  std::vector<config> times;
430 
432 
433  assert(tod_m != nullptr);
434 
435  for(const time_of_day& time : tod_m->times()) {
436  times.emplace_back(config {
437  "details", time.name, // Use 'details' field here since the image will take the first column
438  "image", time.image,
439  });
440  }
441 
442  items.insert(pos, times.begin(), times.end());
443 }
444 
445 void context_manager::expand_local_time_menu(std::vector<config>& items, int i)
446 {
447  auto pos = items.erase(items.begin() + i);
448  std::vector<config> times;
449 
451 
452  for(const time_of_day& time : tod_m->times(get_map_context().get_active_area())) {
453  times.emplace_back(config {
454  "details", time.name, // Use 'details' field here since the image will take the first column
455  "image", time.image,
456  });
457  }
458 
459  items.insert(pos, times.begin(), times.end());
460 }
461 
463 {
465  if(fn.empty()) {
466  fn = default_dir_;
467  }
468 
470 
471  dlg.set_title(_("Apply Mask"))
472  .set_path(fn);
473 
474  if(dlg.show()) {
475  try {
476  map_context mask(game_config_, dlg.path());
477  editor_action_apply_mask a(mask.get_map());
479  } catch (editor_map_load_exception& e) {
480  gui2::show_transient_message(_("Error loading mask"), e.what());
481  return;
482  } catch (editor_action_exception& e) {
484  return;
485  }
486  }
487 }
488 
489 void context_manager::perform_refresh(const editor_action& action, bool drag_part /* =false */)
490 {
492  refresh_after_action(drag_part);
493 }
494 
496 {
497  int active_area = get_map_context().get_active_area();
499 
500  if(gui2::dialogs::edit_text::execute(N_("Rename Area"), N_("Identifier:"), name)) {
501  get_map_context().get_time_manager()->set_area_id(active_area, name);
502  }
503 }
504 
506 {
508  if(fn.empty()) {
509  fn = default_dir_;
510  }
511 
513 
514  dlg.set_title(_("Choose Target Map"))
515  .set_path(fn);
516 
517  if(dlg.show()) {
518  try {
519  map_context map(game_config_, dlg.path());
520  editor_action_create_mask a(map.get_map());
522  } catch (editor_map_load_exception& e) {
523  gui2::show_transient_message(_("Error loading map"), e.what());
524  return;
525  } catch (editor_action_exception& e) {
527  return;
528  }
529  }
530 }
531 
533 {
534  if(get_map_context().needs_reload()) {
535  reload_map();
536  return;
537  }
538 
539  const std::set<map_location>& changed_locs = get_map_context().changed_locations();
540 
541  if(get_map_context().needs_terrain_rebuild()) {
544  && (!drag_part || get_map_context().everything_changed())))
545  {
546  gui_.rebuild_all();
549  } else {
550  for(const map_location& loc : changed_locs) {
551  gui_.rebuild_terrain(loc);
552  }
553  gui_.invalidate(changed_locs);
554  }
555  } else {
556  if(get_map_context().everything_changed()) {
558  } else {
559  gui_.invalidate(changed_locs);
560  }
561  }
562 
563  if(get_map_context().needs_labels_reset()) {
565  }
566 
569 }
570 
572 {
573  int w = get_map().w();
574  int h = get_map().h();
575 
577  bool copy = false;
578 
579  if(!gui2::dialogs::editor_resize_map::execute(w, h, dir, copy)) {
580  return;
581  }
582 
583  if(w != get_map().w() || h != get_map().h()) {
585  if(copy) {
587  }
588 
589  int x_offset = get_map().w() - w;
590  int y_offset = get_map().h() - h;
591 
592  switch (dir) {
596  y_offset = 0;
597  break;
601  y_offset /= 2;
602  break;
606  break;
607  default:
608  y_offset = 0;
609  WRN_ED << "Unknown resize expand direction" << std::endl;
610  break;
611  }
612 
613  switch (dir) {
617  x_offset = 0;
618  break;
622  x_offset /= 2;
623  break;
627  break;
628  default:
629  x_offset = 0;
630  break;
631  }
632 
633  editor_action_resize_map a(w, h, x_offset, y_offset, fill);
634  perform_refresh(a);
635  }
636 }
637 
639 {
640  std::string input_name = get_map_context().get_filename();
641  if(input_name.empty()) {
642  input_name = filesystem::get_dir(default_dir_ + "/maps");
643  }
644 
646 
647  dlg.set_title(_("Save Map As"))
648  .set_save_mode(true)
649  .set_path(input_name)
650  .set_extension(".map");
651 
652  if(!dlg.show()) {
653  return;
654  }
655 
656  save_map_as(dlg.path());
657 }
658 
660 {
661  std::string input_name = get_map_context().get_filename();
662  if(input_name.empty()) {
663  input_name = filesystem::get_dir(default_dir_ + "/scenarios");
664  }
665 
667 
668  dlg.set_title(_("Save Scenario As"))
669  .set_save_mode(true)
670  .set_path(input_name)
671  .set_extension(".cfg");
672 
673  if(!dlg.show()) {
674  return;
675  }
676 
677  save_scenario_as(dlg.path());
678 }
679 
681 {
682  for(const config& i : game_config.child_range("multiplayer")) {
683  if(i["map_generation"].empty() && i["scenario_generation"].empty()) {
684  continue;
685  }
686 
687  const config& generator_cfg = i.child("generator");
688  if(!generator_cfg) {
689  ERR_ED << "Scenario \"" << i["name"] << "\" with id " << i["id"]
690  << " has map_generation= but no [generator] tag" << std::endl;
691  } else {
692  map_generators_.emplace_back(create_map_generator(i["map_generation"], generator_cfg));
693  }
694  }
695 }
696 
698 {
699  if(map_generators_.empty()) {
700  gui2::show_error_message(_("No random map generators found."));
701  return;
702  }
703 
706  dialog.show();
707 
708  if(dialog.get_retval() == gui2::window::OK) {
709  std::string map_string;
711  try {
712  map_string = map_generator->create_map(dialog.get_seed());
713  } catch (mapgen_exception& e) {
714  gui2::show_transient_message(_("Map creation failed."), e.what());
715  return;
716  }
717 
718  if(map_string.empty()) {
719  gui2::show_transient_message("", _("Map creation failed."));
720  } else {
721  editor_map new_map(game_config_, map_string);
722  editor_action_whole_map a(new_map);
723  get_map_context().set_needs_labels_reset(); // Ensure Player Start labels are updated together with newly generated map
724  perform_refresh(a);
725  }
726 
727  last_map_generator_ = map_generator;
728  }
729 }
730 
732 {
733  if(get_map_context().modified()) {
734  const int res = gui2::show_message(_("Unsaved Changes"),
735  _("Do you want to discard all changes made to the map since the last save?"), gui2::dialogs::message::yes_no_buttons);
736  return gui2::window::CANCEL != res;
737  }
738 
739  return true;
740 }
741 
743 {
745 }
746 
747 void context_manager::save_all_maps(bool auto_save_windows)
748 {
749  int current = current_context_index_;
750  saved_windows_.clear();
751  for(size_t i = 0; i < map_contexts_.size(); ++i) {
752  switch_context(i);
754  if(auto_save_windows) {
755  if(name.empty() || filesystem::is_directory(name)) {
756  std::ostringstream s;
757  s << default_dir_ << "/" << "window_" << i + 1;
758  name = s.str();
760  }
761  }
762  saved_windows_.push_back(name);
763  save_map();
764  }
765 
766  switch_context(current);
767 }
768 
770 {
772  if(name.empty() || filesystem::is_directory(name)) {
773  if(get_map_context().is_pure_map()) {
775  } else {
777  }
778  } else {
779  if(get_map_context().is_pure_map()) {
780  write_map();
781  } else {
782  write_scenario();
783  }
784  }
785 }
786 
788 {
789  size_t is_open = check_open_map(filename);
790  if(is_open < map_contexts_.size() && is_open != static_cast<unsigned>(current_context_index_)) {
791  gui2::show_transient_message(_("This scenario is already open."), filename);
792  return false;
793  }
794 
795  std::string old_filename = get_map_context().get_filename();
796  bool embedded = get_map_context().is_embedded();
797 
798  get_map_context().set_filename(filename);
799  get_map_context().set_embedded(false);
800 
801  if(!write_scenario(true)) {
802  get_map_context().set_filename(old_filename);
803  get_map_context().set_embedded(embedded);
804  return false;
805  }
806 
807  return true;
808 }
809 
811 {
812  size_t is_open = check_open_map(filename);
813  if(is_open < map_contexts_.size() && is_open != static_cast<unsigned>(current_context_index_)) {
814  gui2::show_transient_message(_("This map is already open."), filename);
815  return false;
816  }
817 
818  std::string old_filename = get_map_context().get_filename();
819  bool embedded = get_map_context().is_embedded();
820 
821  get_map_context().set_filename(filename);
822  get_map_context().set_embedded(false);
823 
824  if(!write_map(true)) {
825  get_map_context().set_filename(old_filename);
826  get_map_context().set_embedded(embedded);
827  return false;
828  }
829 
830  return true;
831 }
832 
833 bool context_manager::write_scenario(bool display_confirmation)
834 {
835  try {
837  if(display_confirmation) {
838  gui2::show_transient_message("", _("Scenario saved."));
839  }
840  } catch (editor_map_save_exception& e) {
842  return false;
843  }
844 
845  return true;
846 }
847 
848 bool context_manager::write_map(bool display_confirmation)
849 {
850  try {
852  if(display_confirmation) {
853  gui2::show_transient_message("", _("Map saved."));
854  }
855  } catch (editor_map_save_exception& e) {
857  return false;
858  }
859 
860  return true;
861 }
862 
864 {
865  size_t i = 0;
866  while(i < map_contexts_.size() && map_contexts_[i]->get_filename() != fn) {
867  ++i;
868  }
869 
870  return i;
871 }
872 
874 {
875  size_t i = check_open_map(fn);
876  if(i < map_contexts_.size()) {
877  gui2::show_transient_message(_("This map is already open."), fn);
878  switch_context(i);
879  return true;
880  }
881 
882  return false;
883 }
884 
885 void context_manager::load_map(const std::string& filename, bool new_context)
886 {
887  if(new_context && check_switch_open_map(filename)) {
888  return;
889  }
890 
891  LOG_ED << "Load map: " << filename << (new_context ? " (new)" : " (same)") << "\n";
892  try {
893  {
894  context_ptr mc(new map_context(game_config_, filename));
895  if(mc->get_filename() != filename) {
896  if(new_context && check_switch_open_map(mc->get_filename())) {
897  return;
898  }
899  }
900 
901  if(new_context) {
902  int new_id = add_map_context_of(std::move(mc));
903  switch_context(new_id);
904  } else {
905  replace_map_context_with(std::move(mc));
906  }
907  }
908 
909  if(get_map_context().is_embedded()) {
910  const std::string& msg = _("Loaded embedded map data");
911  gui2::show_transient_message(_("Map loaded from scenario"), msg);
912  } else {
913  if(get_map_context().get_filename() != filename) {
914  if(get_map_context().get_map_data_key().empty()) {
915  ERR_ED << "Internal error, map context filename changed: "
916  << filename << " -> " << get_map_context().get_filename()
917  << " with no apparent scenario load\n";
918  } else {
919  utils::string_map symbols;
920  symbols["old"] = filename;
921  const std::string& msg = _("Loaded referenced map file:\n$new");
922  symbols["new"] = get_map_context().get_filename();
923  symbols["map_data"] = get_map_context().get_map_data_key();
924  gui2::show_transient_message(_("Map loaded from scenario"),
925  //TODO: msg is already translated does vgettext make sense?
926  vgettext(msg.c_str(), symbols));
927  }
928  }
929  }
930  } catch (editor_map_load_exception& e) {
931  gui2::show_transient_message(_("Error loading map"), e.what());
932  return;
933  }
934 }
935 
937 {
938  if(!confirm_discard()) {
939  return;
940  }
941 
943  if(filename.empty()) {
944  ERR_ED << "Empty filename in map revert" << std::endl;
945  return;
946  }
947 
948  load_map(filename, false);
949 }
950 
951 void context_manager::new_map(int width, int height, const t_translation::terrain_code& fill, bool new_context)
952 {
953  const config& default_schedule = game_config_.find_child("editor_times", "id", "default");
954  editor_map m(game_config_, width, height, fill);
955 
956  if(new_context) {
957  int new_id = add_map_context(m, true, default_schedule);
958  switch_context(new_id);
959  } else {
960  replace_map_context(m, true, default_schedule);
961  }
962 }
963 
964 void context_manager::new_scenario(int width, int height, const t_translation::terrain_code& fill, bool new_context)
965 {
966  const config& default_schedule = game_config_.find_child("editor_times", "id", "default");
967  editor_map m(game_config_, width, height, fill);
968 
969  if(new_context) {
970  int new_id = add_map_context(m, false, default_schedule);
971  switch_context(new_id);
972  } else {
973  replace_map_context(m, false, default_schedule);
974  }
975 
976  // Give the new scenario an initial side.
978  gui_.init_flags();
979 }
980 
981 //
982 // Context manipulation
983 //
984 
985 template<typename... T>
986 int context_manager::add_map_context(const T&... args)
987 {
988  map_contexts_.emplace_back(new map_context(args...));
989  return map_contexts_.size() - 1;
990 }
991 
993 {
994  map_contexts_.emplace_back(std::move(mc));
995  return map_contexts_.size() - 1;
996 }
997 
998 template<typename... T>
1000 {
1001  context_ptr new_mc(new map_context(args...));
1002  replace_map_context_with(std::move(new_mc));
1003 }
1004 
1006 {
1007  map_context_refresher mcr(*this);
1009 
1010  set_window_title();
1011 }
1012 
1014 {
1015  if(saved_windows_.empty()) {
1018 
1019  const config& default_schedule = game_config_.find_child("editor_times", "id", "default");
1020  add_map_context(editor_map(game_config_, 44, 33, default_terrain), true, default_schedule);
1021  } else {
1022  for(const std::string& filename : saved_windows_) {
1023  add_map_context(game_config_, filename);
1024  }
1025 
1026  saved_windows_.clear();
1027  }
1028 }
1029 
1031 {
1032  if(!confirm_discard()) return;
1033 
1034  if(map_contexts_.size() == 1) {
1036  map_contexts_.erase(map_contexts_.begin());
1037  } else if(current_context_index_ == static_cast<int>(map_contexts_.size()) - 1) {
1038  map_contexts_.pop_back();
1040  } else {
1042  }
1043 
1044  map_context_refresher(*this);
1045  set_window_title();
1046 }
1047 
1048 void context_manager::switch_context(const int index, const bool force)
1049 {
1050  if(index < 0 || static_cast<size_t>(index) >= map_contexts_.size()) {
1051  WRN_ED << "Invalid index in switch map context: " << index << std::endl;
1052  return;
1053  }
1054 
1055  if(index == current_context_index_ && !force) {
1056  return;
1057  }
1058 
1059  // Disable the labels of the current context before switching.
1060  // The refresher handles enabling the new ones.
1061  get_labels().enable(false);
1062 
1063  map_context_refresher mcr(*this);
1065 
1066  set_window_title();
1067 }
1068 
1070 {
1072 
1073  if(name.empty()) {
1075  }
1076 
1077  if(name.empty()){
1079  }
1080 
1081  const std::string& wm_title_string = name + " - " + game_config::get_default_title_string();
1082  CVideo::get_singleton().set_window_title(wm_title_string);
1083 }
1084 
1085 } //Namespace editor
int auto_update_transitions()
Definition: editor.cpp:25
bool write_scenario(bool display_confirmation=false)
void set_side_setup(editor_team_info &info)
TODO.
bool victory_defeated() const
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.
Definition: message.cpp:152
Dialog is closed with ok button.
Definition: window.hpp:111
boost::optional< uint32_t > get_seed()
::tod_manager * tod_manager
Definition: resources.cpp:30
const char * what() const NOEXCEPT
Definition: exceptions.hpp:37
void apply_mask_dialog()
Display an apply mask dialog and process user input.
std::vector< char_t > string
bool check_switch_open_map(const std::string &fn)
Check if a map is already open.
std::unique_ptr< map_context > context_ptr
size_t index(const utf8::string &str, const size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
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.
Definition: editor.cpp:119
const terrain_code NONE_TERRAIN
Definition: translation.hpp:64
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.
Definition: display.cpp:3023
file_dialog & set_extension(const std::string &value)
Sets the default file extension for file names in save mode.
game_classification * classification
Definition: resources.cpp:36
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
void change_display_context(const display_context *dc)
Definition: display.cpp:505
void replace_map_context_with(context_ptr &&mc)
std::vector< context_ptr > map_contexts_
The currently opened map context object.
config & find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Definition: config.cpp:763
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.
#define a
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.
Definition: display.cpp:286
This file contains the window object, this object is a top level container which has the event manage...
child_itors child_range(config_key_type key)
Definition: config.cpp:343
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, const bool restore_background)
Shows a transient message to the user.
void set_area_id(int area_index, const std::string &id)
context_manager(editor_display &gui, const config &game_config)
void save_map()
Save the map, open dialog if not named yet.
bool modified() const
#define LOG_ED
General purpose widgets.
std::string default_dir_
Default directory for map load/save as dialogs.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:55
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 CVideo & get_singleton()
Definition: video.hpp:43
#define h
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:110
size_t check_open_map(const std::string &fn) const
Check if a map is already open.
std::string path() const
Gets the current file selection.
const std::string & get_filename() const
const std::vector< std::string > items
Replace contents of the entire map, Useful as a fallback undo method when something else would be imp...
Definition: action.hpp:37
-file sdl_utils.hpp
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.
const std::string & get_description() const
int get_xp_mod() const
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.
void revert_map()
Revert the map by reloading it from disk.
const std::set< map_location > changed_locations() const
const editor_map & get_map() const
Get the map from the current map context object - const version.
void expand_areas_menu(std::vector< config > &items, int i)
Menu expanding for the map's defined areas.
std::string default_dir()
Definition: editor.cpp:33
#define WRN_ED
overlay_map & get_overlays()
const t_string get_default_context_name() const
game_classification & get_classification()
void set_window_title(const std::string &title)
Sets the title of the main window.
Definition: video.cpp:358
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:44
int add_map_context(const T &...args)
Add a map context.
void close_current_context()
Closes the active map context.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
const std::string & get_name() const
tod_manager * get_time_manager()
bool is_pure_map() const
void load_map_dialog(bool force_same_context=false)
Display a load map dialog and process user input.
const t_string & user_team_name() const
Definition: team.hpp:295
std::string get_user_data_dir()
void reset_starting_position_labels(display &disp)
void recalculate_minimap()
Schedule the minimap for recalculation.
Definition: display.hpp:610
void select_map_generator(map_generator *mg)
filter_context * filter_con
Definition: resources.cpp:23
void replace_map_context(const T &...args)
Replace the current map context and refresh accordingly.
void set_embedded(bool v)
int w() const
Effective map width.
Definition: map.hpp:90
editor_map & get_map()
Map accessor.
Definition: map_context.hpp:92
void set_auto_update_transitions(int value)
Definition: editor.cpp:29
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.
Editor action classes.
bool save_map()
Saves the map under the current filename.
void enable(bool is_enabled)
Definition: label.cpp:253
std::string path
Definition: game_config.cpp:56
Modify, read and display user preferences.
Shows a yes and no button.
Definition: message.hpp:79
map_display and display: classes which take care of displaying the map and game-data on the screen...
if(win_locale=="af") win_locale
void create_buttons()
Definition: display.cpp:900
Manage the empty-palette in the editor.
Definition: action.cpp:29
std::string default_terrain
Definition: game_config.cpp:86
void perform_action(const editor_action &action)
Performs an action (thus modifying the map).
void invalidate_all()
Function to invalidate all tiles.
Definition: display.cpp:3013
bool is_active_transitions_hotkey(const std::string &item)
Utility class to properly refresh the display when the map context object is replaced without duplica...
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.
std::string get_dir(const std::string &dir)
Paint the same terrain on a number of locations on the map.
Definition: action.hpp:284
void new_map(int width, int height, const t_translation::terrain_code &fill, bool new_context)
Create a new map.
void load_map(const std::string &filename, bool new_context)
Load a map given the filename.
virtual std::string create_map(boost::optional< uint32_t > randomseed=boost::none)=0
Creates a new map and returns it.
map_generator * create_map_generator(const std::string &name, const config &cfg)
Definition: map_create.cpp:29
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
Encapsulates the map of the game.
Definition: location.hpp:40
void clear_changed_locations()
std::vector< team > & get_teams()
Get the team from the current map context object.
std::vector< std::string > get_area_ids() const
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:69
int h() const
Effective map height.
Definition: map.hpp:93
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.
Definition: build_info.cpp:53
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)
unit_map & get_units()
Get the unit map from the current map context object.
static map_location::DIRECTION s
editor_display & gui()
Base class for all editor actions.
Definition: action_base.hpp:40
const std::string & get_map_data_key() const
const std::set< map_location > & get_area_by_index(int index) const
size_t i
Definition: function.cpp:933
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...
size_t modified_maps(std::string &modified)
void create_mask_to_dialog()
Display an apply mask dialog and process user input.
Declarations for File-IO.
bool random_start_time() const
int w
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
#define N_(String)
Definition: gettext.hpp:97
const std::string unicode_bullet
Definition: constants.cpp:42
const std::set< map_location > & selection() const
Return the selection set.
Definition: editor_map.hpp:149
map_context_refresher(context_manager &ec)
std::string vgettext(const char *msgid, const utils::string_map &symbols)
std::string base_name(const std::string &file, const bool remove_extension=false)
Returns the base filename of a file, with directory name stripped.
void expand_sides_menu(std::vector< config > &items, int i)
Menu expanding for the map's player sides.
static std::string get_filename(const std::string &file_code)
map_generator * last_map_generator_
int turns()
Definition: game.cpp:560
void edit_side_dialog(int side_index)
Display a side edit dialog and process user input.
double t
Definition: astarsearch.cpp:64
void reload_map()
Updates internals that cache map size.
Definition: display.cpp:499
#define ERR_ED
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
std::vector< std::unique_ptr< map_generator > > map_generators_
Available random map generators.
void set_filename(const std::string &fn)
int get_active_area() const
void expand_load_mru_menu(std::vector< config > &items, int i)
Menu expanding for most recent loaded list.
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
Definition: message.cpp:205
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.
#define e
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.
Definition: config.hpp:93
void init_map_generators(const config &game_config)
init available random map generators
void load_mru_item(unsigned index, bool force_same_context=false)
Open the specified entry from the recent files list.
static std::vector< std::string > saved_windows_
static const std::string get_menu_marker(const bool changed)
Dialog is closed with the cancel button.
Definition: window.hpp:112
bool is_embedded() const
unit_map * units
Definition: resources.cpp:34
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.
terrain_code read_terrain_code(const std::string &str, const ter_layer filler)
Reads a single terrain from a string.
void rebuild_all()
Rebuild all dynamic terrain.
Definition: display.cpp:494
int number_of_turns() const
void replace_overlay_map(overlay_map *overlays)
Definition: display.hpp:1061
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.
Definition: file_dialog.hpp:56
const std::string & get_id() const