Editor: cleaned up a bunch of accessors

Map Context:
* Removed get_team() in favor of non-const local team() overload.
* Removeded get_map() (both overloads) in favor of map() and a local non-const overload of the same.
* Made both overloads of map() return editor_map instead of gamemap (former inherits from the latter).

Context Manager:
* Removed team, unit, and label accessors that only fetched the same info from the current map_context.
  Having more functions of this name only made things a lot more confusing.

Editor Controller:
* Change all instances of the three intermediate accessors mentioned above to data queries directly
  from the current map context via editor_controller::get_current_map_context. The result is the same,
  we just no longer have three levels of indirection.
This commit is contained in:
Charles Dang 2018-01-29 01:41:43 +11:00
parent b0bb9d94f0
commit 69cd6640d0
10 changed files with 120 additions and 126 deletions

View file

@ -62,7 +62,7 @@ std::string editor_action::get_description() const
editor_action* editor_action::perform(map_context& mc) const
{
editor_action_ptr undo(new editor_action_whole_map(mc.get_map()));
editor_action_ptr undo(new editor_action_whole_map(mc.map()));
perform_without_undo(mc);
return undo.release();
}
@ -194,7 +194,7 @@ void editor_action_paste::extend(const editor_map& map, const std::set<map_locat
editor_action_paste* editor_action_paste::perform(map_context& mc) const
{
map_fragment mf(mc.get_map(), paste_.get_offset_area(offset_));
map_fragment mf(mc.map(), paste_.get_offset_area(offset_));
std::unique_ptr<editor_action_paste> undo(new editor_action_paste(mf));
perform_without_undo(mc);
@ -203,7 +203,7 @@ editor_action_paste* editor_action_paste::perform(map_context& mc) const
void editor_action_paste::perform_without_undo(map_context& mc) const
{
paste_.paste_into(mc.get_map(), offset_);
paste_.paste_into(mc.map(), offset_);
mc.add_changed_location(paste_.get_offset_area(offset_));
mc.set_needs_terrain_rebuild();
}
@ -212,7 +212,7 @@ IMPLEMENT_ACTION(paint_area)
editor_action_paste* editor_action_paint_area::perform(map_context& mc) const
{
map_fragment mf(mc.get_map(), area_);
map_fragment mf(mc.map(), area_);
std::unique_ptr<editor_action_paste> undo(new editor_action_paste(mf));
perform_without_undo(mc);
@ -229,9 +229,9 @@ IMPLEMENT_ACTION(fill)
editor_action_paint_area* editor_action_fill::perform(map_context& mc) const
{
std::set<map_location> to_fill = mc.get_map().get_contiguous_terrain_tiles(loc_);
std::set<map_location> to_fill = mc.map().get_contiguous_terrain_tiles(loc_);
std::unique_ptr<editor_action_paint_area> undo(
new editor_action_paint_area(to_fill, mc.get_map().get_terrain(loc_)));
new editor_action_paint_area(to_fill, mc.map().get_terrain(loc_)));
mc.draw_terrain(t_, to_fill, one_layer_);
mc.set_needs_terrain_rebuild();
@ -241,7 +241,7 @@ editor_action_paint_area* editor_action_fill::perform(map_context& mc) const
void editor_action_fill::perform_without_undo(map_context& mc) const
{
std::set<map_location> to_fill = mc.get_map().get_contiguous_terrain_tiles(loc_);
std::set<map_location> to_fill = mc.map().get_contiguous_terrain_tiles(loc_);
mc.draw_terrain(t_, to_fill, one_layer_);
mc.set_needs_terrain_rebuild();
}
@ -252,8 +252,8 @@ editor_action* editor_action_starting_position::perform(map_context& mc) const
{
editor_action_ptr undo;
const std::string* old_loc_id = mc.get_map().is_starting_position(loc_);
map_location old_loc = mc.get_map().special_location(loc_id_);
const std::string* old_loc_id = mc.map().is_starting_position(loc_);
map_location old_loc = mc.map().special_location(loc_id_);
if(old_loc_id != nullptr) {
// If another player was starting at the location, we actually perform two actions, so the undo is an
@ -267,14 +267,14 @@ editor_action* editor_action_starting_position::perform(map_context& mc) const
LOG_ED << "ssp actual: " << *old_loc_id << " to " << map_location() << "\n";
mc.get_map().set_special_location(*old_loc_id, map_location());
mc.map().set_special_location(*old_loc_id, map_location());
} else {
undo.reset(new editor_action_starting_position(old_loc, loc_id_));
}
LOG_ED << "ssp actual: " << loc_id_ << " to " << loc_ << "\n";
mc.get_map().set_special_location(loc_id_, loc_);
mc.map().set_special_location(loc_id_, loc_);
mc.set_needs_labels_reset();
return undo.release();
@ -282,12 +282,12 @@ editor_action* editor_action_starting_position::perform(map_context& mc) const
void editor_action_starting_position::perform_without_undo(map_context& mc) const
{
const std::string* old_id = mc.get_map().is_starting_position(loc_);
const std::string* old_id = mc.map().is_starting_position(loc_);
if(old_id != nullptr) {
mc.get_map().set_special_location(*old_id, map_location());
mc.map().set_special_location(*old_id, map_location());
}
mc.get_map().set_special_location(loc_id_, loc_);
mc.map().set_special_location(loc_id_, loc_);
mc.set_needs_labels_reset();
}
@ -295,7 +295,7 @@ IMPLEMENT_ACTION(resize_map)
void editor_action_resize_map::perform_without_undo(map_context& mc) const
{
mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
mc.map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
mc.set_needs_reload();
}
@ -303,7 +303,7 @@ IMPLEMENT_ACTION(apply_mask)
void editor_action_apply_mask::perform_without_undo(map_context& mc) const
{
mc.get_map().overlay(mask_, config(), {0, 0});
mc.map().overlay(mask_, config(), {0, 0});
mc.set_needs_terrain_rebuild();
}
@ -311,7 +311,7 @@ IMPLEMENT_ACTION(create_mask)
void editor_action_create_mask::perform_without_undo(map_context& mc) const
{
mc.set_map(editor_map(mc.get_map().mask_to(target_)));
mc.set_map(editor_map(mc.map().mask_to(target_)));
mc.set_needs_terrain_rebuild();
}
@ -319,7 +319,7 @@ IMPLEMENT_ACTION(shuffle_area)
editor_action_paste* editor_action_shuffle_area::perform(map_context& mc) const
{
map_fragment mf(mc.get_map(), area_);
map_fragment mf(mc.map(), area_);
std::unique_ptr<editor_action_paste> undo(new editor_action_paste(mf));
perform_without_undo(mc);
@ -337,9 +337,9 @@ void editor_action_shuffle_area::perform_without_undo(map_context& mc) const
std::set<map_location>::const_iterator orig_it = area_.begin();
while(orig_it != area_.end()) {
t_translation::terrain_code tmp = mc.get_map().get_terrain(*orig_it);
t_translation::terrain_code tmp = mc.map().get_terrain(*orig_it);
mc.draw_terrain(mc.get_map().get_terrain(*shuffle_it), *orig_it);
mc.draw_terrain(mc.map().get_terrain(*shuffle_it), *orig_it);
mc.draw_terrain(tmp, *shuffle_it);
++orig_it;

View file

@ -93,7 +93,7 @@ void editor_action_item_replace::perform_without_undo(map_context& /*mc*/) const
// mc.add_changed_location(new_loc_);
//
// /* @todo
// if (mc.get_map().is_village(new_loc_)) {
// if (mc.map().is_village(new_loc_)) {
// (*(resources::gameboard->teams()))[u.side()].get_village(new_loc_);
// }
// */

View file

@ -48,7 +48,7 @@ editor_action* editor_action_select::perform(map_context& mc) const
void editor_action_select::perform_without_undo(map_context& mc) const
{
for(const map_location& loc : area_) {
mc.get_map().add_to_selection(loc);
mc.map().add_to_selection(loc);
mc.add_changed_location(loc);
}
}
@ -70,7 +70,7 @@ editor_action* editor_action_deselect::perform(map_context& mc) const
{
std::set<map_location> undo_locs;
for(const map_location& loc : area_) {
if(mc.get_map().in_selection(loc)) {
if(mc.map().in_selection(loc)) {
undo_locs.insert(loc);
mc.add_changed_location(loc);
}
@ -83,7 +83,7 @@ editor_action* editor_action_deselect::perform(map_context& mc) const
void editor_action_deselect::perform_without_undo(map_context& mc) const
{
for(const map_location& loc : area_) {
mc.get_map().remove_from_selection(loc);
mc.map().remove_from_selection(loc);
mc.add_changed_location(loc);
}
}
@ -92,10 +92,10 @@ IMPLEMENT_ACTION(select_all)
editor_action_select* editor_action_select_all::perform(map_context& mc) const
{
std::set<map_location> current = mc.get_map().selection();
mc.get_map().select_all();
std::set<map_location> current = mc.map().selection();
mc.map().select_all();
std::set<map_location> all = mc.get_map().selection();
std::set<map_location> all = mc.map().selection();
std::set<map_location> undo_locs;
std::set_difference(
@ -107,7 +107,7 @@ editor_action_select* editor_action_select_all::perform(map_context& mc) const
void editor_action_select_all::perform_without_undo(map_context& mc) const
{
mc.get_map().select_all();
mc.map().select_all();
mc.set_everything_changed();
}
@ -115,15 +115,15 @@ IMPLEMENT_ACTION(select_none)
editor_action_select* editor_action_select_none::perform(map_context& mc) const
{
std::set<map_location> current = mc.get_map().selection();
mc.get_map().clear_selection();
std::set<map_location> current = mc.map().selection();
mc.map().clear_selection();
mc.set_everything_changed();
return new editor_action_select(current);
}
void editor_action_select_none::perform_without_undo(map_context& mc) const
{
mc.get_map().clear_selection();
mc.map().clear_selection();
mc.set_everything_changed();
}
@ -137,7 +137,7 @@ editor_action_select_inverse* editor_action_select_inverse::perform(map_context&
void editor_action_select_inverse::perform_without_undo(map_context& mc) const
{
mc.get_map().invert_selection();
mc.map().invert_selection();
mc.set_everything_changed();
}

View file

@ -97,7 +97,7 @@ void editor_action_unit_replace::perform_without_undo(map_context& mc) const
mc.add_changed_location(new_loc_);
/* @todo
if (mc.get_map().is_village(new_loc_)) {
if (mc.map().is_village(new_loc_)) {
(*(resources::gameboard->teams()))[u.side()].get_village(new_loc_);
}
*/

View file

@ -29,11 +29,11 @@ IMPLEMENT_ACTION(village)
editor_action* editor_action_village::perform(map_context& mc) const
{
if(!mc.get_map().is_village(loc_)) {
if(!mc.map().is_village(loc_)) {
return nullptr;
}
std::vector<team>& teams = mc.get_teams();
std::vector<team>& teams = mc.teams();
try {
if(teams.at(side_number_).owns_village(loc_)) {
@ -57,7 +57,7 @@ editor_action* editor_action_village::perform(map_context& mc) const
void editor_action_village::perform_without_undo(map_context& mc) const
{
std::vector<team>& teams = mc.get_teams();
std::vector<team>& teams = mc.teams();
for(team& t : teams) {
if(t.owns_village(loc_)) {
@ -75,7 +75,7 @@ editor_action* editor_action_village_delete::perform(map_context& mc) const
{
editor_action_ptr undo;
for(const team& t : mc.get_teams()) {
for(const team& t : mc.teams()) {
if(t.owns_village(loc_)) {
perform_without_undo(mc);
undo.reset(new editor_action_village(loc_, t.side() - 1));
@ -87,7 +87,7 @@ editor_action* editor_action_village_delete::perform(map_context& mc) const
void editor_action_village_delete::perform_without_undo(map_context& mc) const
{
for(team& t : mc.get_teams()) {
for(team& t : mc.teams()) {
if(t.owns_village(loc_)) {
t.lose_village(loc_);
mc.add_changed_location(loc_);

View file

@ -288,7 +288,7 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
return !get_current_map_context().units().empty();
case HOTKEY_STATUS_TABLE:
return !get_current_map_context().get_teams().empty();
return !get_current_map_context().teams().empty();
case HOTKEY_TERRAIN_DESCRIPTION:
return gui().mouseover_hex().valid();
@ -331,7 +331,7 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
case HOTKEY_EDITOR_SIDE_EDIT:
case HOTKEY_EDITOR_SIDE_REMOVE:
return !get_current_map_context().get_teams().empty();
return !get_current_map_context().teams().empty();
// brushes
case HOTKEY_EDITOR_BRUSH_NEXT:
@ -377,7 +377,7 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
return !get_current_map_context().is_pure_map();
case HOTKEY_EDITOR_TOOL_UNIT:
case HOTKEY_EDITOR_TOOL_VILLAGE:
return !get_current_map_context().get_teams().empty();
return !get_current_map_context().teams().empty();
case HOTKEY_EDITOR_AREA_REMOVE:
case HOTKEY_EDITOR_AREA_RENAME:
@ -388,16 +388,16 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
case HOTKEY_EDITOR_AREA_SAVE:
return !get_current_map_context().is_pure_map() &&
!get_current_map_context().get_time_manager()->get_area_ids().empty()
&& !context_manager_->get_map().selection().empty();
&& !get_current_map_context().map().selection().empty();
case HOTKEY_EDITOR_SELECTION_EXPORT:
case HOTKEY_EDITOR_SELECTION_CUT:
case HOTKEY_EDITOR_SELECTION_COPY:
case HOTKEY_EDITOR_SELECTION_FILL:
return !context_manager_->get_map().selection().empty()
return !get_current_map_context().map().selection().empty()
&& !toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
return (context_manager_->get_map().selection().size() > 1
return (get_current_map_context().map().selection().size() > 1
&& !toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE));
case HOTKEY_EDITOR_SELECTION_ROTATE:
case HOTKEY_EDITOR_SELECTION_FLIP:
@ -415,8 +415,8 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
case HOTKEY_EDITOR_SELECT_NONE:
return !toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
case HOTKEY_EDITOR_SELECT_INVERSE:
return !get_current_map_context().get_map().selection().empty()
&& !get_current_map_context().get_map().everything_selected()
return !get_current_map_context().map().selection().empty()
&& !get_current_map_context().map().everything_selected()
&& !toolkit_->is_mouse_action_set(HOTKEY_EDITOR_CLIPBOARD_PASTE);
case HOTKEY_EDITOR_MAP_RESIZE:
case HOTKEY_EDITOR_MAP_GENERATE:
@ -493,10 +493,10 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case HOTKEY_TOGGLE_GRID:
return preferences::grid() ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_SELECT_ALL:
return get_current_map_context().get_map().everything_selected() ?
return get_current_map_context().map().everything_selected() ?
ACTION_SELECTED : ACTION_DESELECTED;
case HOTKEY_EDITOR_SELECT_NONE:
return get_current_map_context().get_map().selection().empty() ?
return get_current_map_context().map().selection().empty() ?
ACTION_SELECTED : ACTION_DESELECTED;
case HOTKEY_EDITOR_TOOL_FILL:
case HOTKEY_EDITOR_TOOL_LABEL:
@ -852,7 +852,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
export_selection_coords();
return true;
case HOTKEY_EDITOR_SELECT_ALL:
if(!context_manager_->get_map().everything_selected()) {
if(!get_current_map_context().map().everything_selected()) {
context_manager_->perform_refresh(editor_action_select_all());
return true;
}
@ -868,7 +868,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
return true;
case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
context_manager_->perform_refresh(editor_action_shuffle_area(
context_manager_->get_map().selection()));
get_current_map_context().map().selection()));
return true;
case HOTKEY_EDITOR_SCENARIO_EDIT:
@ -999,7 +999,7 @@ void editor_controller::show_help()
void editor_controller::show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp)
{
if(context_menu) {
if(!context_manager_->get_map().on_board_with_border(gui().hex_clicked_on(xloc, yloc))) {
if(!get_current_map_context().map().on_board_with_border(gui().hex_clicked_on(xloc, yloc))) {
return;
}
}
@ -1124,8 +1124,8 @@ void editor_controller::unit_description()
void editor_controller::copy_selection()
{
if (!context_manager_->get_map().selection().empty()) {
context_manager_->get_clipboard() = map_fragment(context_manager_->get_map(), context_manager_->get_map().selection());
if (!get_current_map_context().map().selection().empty()) {
context_manager_->get_clipboard() = map_fragment(get_current_map_context().map(), get_current_map_context().map().selection());
context_manager_->get_clipboard().center_by_mass();
}
}
@ -1173,30 +1173,30 @@ void editor_controller::unit_list()
void editor_controller::cut_selection()
{
copy_selection();
context_manager_->perform_refresh(editor_action_paint_area(context_manager_->get_map().selection(), get_selected_bg_terrain()));
context_manager_->perform_refresh(editor_action_paint_area(get_current_map_context().map().selection(), get_selected_bg_terrain()));
}
void editor_controller::save_area()
{
const std::set<map_location>& area = context_manager_->get_map().selection();
const std::set<map_location>& area = get_current_map_context().map().selection();
get_current_map_context().save_area(area);
}
void editor_controller::add_area()
{
const std::set<map_location>& area = context_manager_->get_map().selection();
const std::set<map_location>& area = get_current_map_context().map().selection();
get_current_map_context().new_area(area);
}
void editor_controller::export_selection_coords()
{
std::stringstream ssx, ssy;
std::set<map_location>::const_iterator i = context_manager_->get_map().selection().begin();
if (i != context_manager_->get_map().selection().end()) {
std::set<map_location>::const_iterator i = get_current_map_context().map().selection().begin();
if (i != get_current_map_context().map().selection().end()) {
ssx << "x = " << i->wml_x();
ssy << "y = " << i->wml_y();
++i;
while (i != context_manager_->get_map().selection().end()) {
while (i != get_current_map_context().map().selection().end()) {
ssx << ", " << i->wml_x();
ssy << ", " << i->wml_y();
++i;
@ -1253,15 +1253,15 @@ void editor_controller::mouse_motion(int x, int y, const bool /*browse*/,
{
if (mouse_handler_base::mouse_motion_default(x, y, update)) return;
map_location hex_clicked = gui().hex_clicked_on(x, y);
if (context_manager_->get_map().on_board_with_border(drag_from_hex_) && is_dragging()) {
if (get_current_map_context().map().on_board_with_border(drag_from_hex_) && is_dragging()) {
editor_action* a = nullptr;
bool partial = false;
editor_action* last_undo = get_current_map_context().last_undo_action();
if (dragging_left_ && (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(1)) != 0) {
if (!context_manager_->get_map().on_board_with_border(hex_clicked)) return;
if (!get_current_map_context().map().on_board_with_border(hex_clicked)) return;
a = get_mouse_action().drag_left(*gui_, x, y, partial, last_undo);
} else if (dragging_right_ && (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(3)) != 0) {
if (!context_manager_->get_map().on_board_with_border(hex_clicked)) return;
if (!get_current_map_context().map().on_board_with_border(hex_clicked)) return;
a = get_mouse_action().drag_right(*gui_, x, y, partial, last_undo);
}
//Partial means that the mouse action has modified the
@ -1284,7 +1284,7 @@ void editor_controller::mouse_motion(int x, int y, const bool /*browse*/,
bool editor_controller::allow_mouse_wheel_scroll(int x, int y)
{
return context_manager_->get_map().on_board_with_border(gui().hex_clicked_on(x,y));
return get_current_map_context().map().on_board_with_border(gui().hex_clicked_on(x,y));
}
bool editor_controller::right_click_show_menu(int /*x*/, int /*y*/, const bool /*browse*/)
@ -1300,7 +1300,7 @@ bool editor_controller::left_click(int x, int y, const bool browse)
LOG_ED << "Left click, after generic handling\n";
map_location hex_clicked = gui().hex_clicked_on(x, y);
if (!context_manager_->get_map().on_board_with_border(hex_clicked))
if (!get_current_map_context().map().on_board_with_border(hex_clicked))
return true;
LOG_ED << "Left click action " << hex_clicked << "\n";
@ -1332,7 +1332,7 @@ bool editor_controller::right_click(int x, int y, const bool browse)
if (mouse_handler_base::right_click(x, y, browse)) return true;
LOG_ED << "Right click, after generic handling\n";
map_location hex_clicked = gui().hex_clicked_on(x, y);
if (!context_manager_->get_map().on_board_with_border(hex_clicked)) return true;
if (!get_current_map_context().map().on_board_with_border(hex_clicked)) return true;
LOG_ED << "Right click action " << hex_clicked << "\n";
editor_action* a = get_mouse_action().click_right(*gui_, x, y);
perform_refresh_delete(a, true);
@ -1361,10 +1361,10 @@ void editor_controller::right_mouse_up(int x, int y, const bool browse)
void editor_controller::terrain_description()
{
const map_location& loc = gui().mouseover_hex();
if (context_manager_->get_map().on_board(loc) == false)
if (get_current_map_context().map().on_board(loc) == false)
return;
const terrain_type& type = context_manager_->get_map().get_terrain_info(loc);
const terrain_type& type = get_current_map_context().map().get_terrain_info(loc);
help::show_terrain_description(type);
}

View file

@ -105,7 +105,7 @@ void context_manager::refresh_on_context_change()
reload_map();
// Enable the labels of the current context;
get_labels().enable(true);
get_map_context().get_labels().enable(true);
set_window_title();
}
@ -205,7 +205,7 @@ void context_manager::load_mru_item(unsigned int index, bool force_same_context
void context_manager::edit_side_dialog(int side_index)
{
team& t = get_map_context().get_teams()[side_index];
team& t = get_map_context().teams()[side_index];
editor_team_info team_info(t);
@ -248,8 +248,10 @@ void context_manager::edit_scenario_dialog()
void context_manager::new_map_dialog()
{
int w = get_map().w();
int h = get_map().h();
const editor_map& map = get_map_context().map();
int w = map.w();
int h = map.h();
if(gui2::dialogs::editor_new_map::execute(_("New Map"), w, h)) {
const t_translation::terrain_code& fill = get_selected_bg_terrain();
@ -259,8 +261,10 @@ void context_manager::new_map_dialog()
void context_manager::new_scenario_dialog()
{
int w = get_map().w();
int h = get_map().h();
const editor_map& map = get_map_context().map();
int w = map.w();
int h = map.h();
if(gui2::dialogs::editor_new_map::execute(_("New Scenario"), w, h)) {
const t_translation::terrain_code& fill = get_selected_bg_terrain();
@ -363,7 +367,7 @@ void context_manager::expand_areas_menu(std::vector<config>& items, int i)
const bool changed =
mci == static_cast<size_t>(get_map_context().get_active_area())
&& tod->get_area_by_index(mci) != get_map_context().get_map().selection();
&& tod->get_area_by_index(mci) != get_map_context().map().selection();
const std::string label = ss.str();
const std::string details = get_menu_marker(changed);
@ -379,9 +383,9 @@ void context_manager::expand_sides_menu(std::vector<config>& items, int i)
auto pos = items.erase(items.begin() + i);
std::vector<config> contexts;
for(size_t mci = 0; mci < get_map_context().get_teams().size(); ++mci) {
for(size_t mci = 0; mci < get_map_context().teams().size(); ++mci) {
const team& t = get_map_context().get_teams()[mci];
const team& t = get_map_context().teams()[mci];
const std::string& teamname = t.user_team_name();
std::stringstream label;
label << "[" << mci+1 << "] ";
@ -449,7 +453,7 @@ void context_manager::apply_mask_dialog()
if(dlg.show()) {
try {
map_context mask(game_config_, dlg.path());
editor_action_apply_mask a(mask.get_map());
editor_action_apply_mask a(mask.map());
perform_refresh(a);
} catch (editor_map_load_exception& e) {
gui2::show_transient_message(_("Error loading mask"), e.what());
@ -492,7 +496,7 @@ void context_manager::create_mask_to_dialog()
if(dlg.show()) {
try {
map_context map(game_config_, dlg.path());
editor_action_create_mask a(map.get_map());
editor_action_create_mask a(map.map());
perform_refresh(a);
} catch (editor_map_load_exception& e) {
gui2::show_transient_message(_("Error loading map"), e.what());
@ -545,8 +549,10 @@ void context_manager::refresh_after_action(bool drag_part)
void context_manager::resize_map_dialog()
{
int w = get_map().w();
int h = get_map().h();
const editor_map& map = get_map_context().map();
int w = map.w();
int h = map.h();
gui2::dialogs::editor_resize_map::EXPAND_DIRECTION dir = gui2::dialogs::editor_resize_map::EXPAND_DIRECTION();
bool copy = false;
@ -555,14 +561,14 @@ void context_manager::resize_map_dialog()
return;
}
if(w != get_map().w() || h != get_map().h()) {
if(w != map.w() || h != map.h()) {
t_translation::terrain_code fill = get_selected_bg_terrain();
if(copy) {
fill = t_translation::NONE_TERRAIN;
}
int x_offset = get_map().w() - w;
int y_offset = get_map().h() - h;
int x_offset = map.w() - w;
int y_offset = map.h() - h;
switch (dir) {
case gui2::dialogs::editor_resize_map::EXPAND_BOTTOM_RIGHT:
@ -716,7 +722,7 @@ bool context_manager::confirm_discard()
void context_manager::fill_selection()
{
perform_refresh(editor_action_paint_area(get_map().selection(), get_selected_bg_terrain()));
perform_refresh(editor_action_paint_area(get_map_context().map().selection(), get_selected_bg_terrain()));
}
void context_manager::save_all_maps(bool auto_save_windows)
@ -1030,7 +1036,7 @@ void context_manager::switch_context(const int index, const bool force)
// Disable the labels of the current context before switching.
// The refresher handles enabling the new ones.
get_labels().enable(false);
get_map_context().get_labels().enable(false);
current_context_index_ = index;

View file

@ -160,17 +160,6 @@ public:
return *map_contexts_[current_context_index_];
}
/** Get the map from the current map context object - const version*/
const editor_map& get_map() const
{
return get_map_context().get_map();
}
map_labels& get_labels()
{
return get_map_context().get_labels();
}
/** Set the default dir (where the filebrowser is pointing at when there is no map file opened) */
void set_default_dir(const std::string& str)
{
@ -226,12 +215,6 @@ public:
*/
void refresh_after_action(bool drag_part = false);
/** Get the map from the current map context object */
editor_map& get_map()
{
return get_map_context().get_map();
}
/** Closes the active map context. Switches to a valid context afterward or creates a dummy one. */
void close_current_context();

View file

@ -237,7 +237,7 @@ void map_context::new_side()
cfg["hidden"] = false;
// TODO: build might be slight overkill here just to set the side...
teams_.back().build(cfg, get_map());
teams_.back().build(cfg, map());
++actions_since_save_;
}

View file

@ -86,16 +86,6 @@ public:
*/
bool select_area(int index);
/**
* Map accessor
*/
editor_map& get_map() { return map_; }
/**
* Map accessor - const version
*/
const editor_map& get_map() const { return map_; }
/** Adds a new side to the map */
void new_side();
@ -117,24 +107,20 @@ public:
void remove_area(int index);
/** Get the team from the current map context object */
std::vector<team>& get_teams() {
return teams_;
}
map_labels& get_labels() {
return labels_;
}
void replace_schedule(const std::vector<time_of_day>& schedule);
// Import symbol from base class.
// Import symbols from base class.
using display_context::units;
using display_context::teams;
using display_context::map;
/**
* Const accessor names needed to implement "display_context" interface
*/
virtual const unit_map & units() const {
/** Const units accessor. */
virtual const unit_map& units() const override
{
return units_;
}
@ -144,13 +130,32 @@ public:
return units_;
}
virtual const std::vector<team>& teams() const {
/** Const teams accessor. */
virtual const std::vector<team>& teams() const override
{
return teams_;
}
virtual const gamemap & map() const {
/** Local non-const overload of @ref teams */
std::vector<team>& teams()
{
return teams_;
}
/** Const map accessor. */
virtual const editor_map& map() const override
{
return map_;
}
virtual const std::vector<std::string>& hidden_label_categories() const {
/** Local non-const overload of @ref map */
editor_map& map()
{
return map_;
}
virtual const std::vector<std::string>& hidden_label_categories() const override
{
return lbl_categories_;
}