Safely import towns of different size. fix #760

This commit is contained in:
2025-06-14 10:03:16 -05:00
parent 3f8eed39c7
commit 978af61054
4 changed files with 16 additions and 4 deletions

View File

@@ -97,6 +97,8 @@ rectangle search_field_rect;
extern void set_up_apple_events();
extern void clamp_view_center(cTown* town);
// TODO: these should be members of some global entity instead of being here
std::unordered_map<std::string, std::shared_ptr <iEventListener>> event_listeners;
cDrawableManager drawable_mgr;
@@ -654,6 +656,7 @@ void handle_menu_choice(eMenu item_hit) {
scenario.towns[cur_town] = town;
::town = town;
change_made = true;
clamp_view_center(town);
redraw_screen();
}
break;

View File

@@ -1896,3 +1896,9 @@ cOutdoors* pick_import_out() {
temp_scenario.outdoors[sector.x][sector.y] = nullptr;
return out;
}
// after importing a town, the view center might be out-of-bounds
void clamp_view_center(cTown* town) {
cen_x = min(cen_x, town->max_dim - 5);
cen_y = min(cen_y, town->max_dim - 5);
}

View File

@@ -20,6 +20,7 @@ extern eScenMode overall_mode;
extern eDrawMode draw_mode;
extern void apply_outdoor_shift(rectangle mod);
extern void clamp_current_section();
extern void clamp_view_center(cTown* town);
cTerrainAction::cTerrainAction(std::string name, short town_num, location where, bool reversed) : cAction(name, reversed) {
area.is_town = true;
@@ -556,12 +557,16 @@ aImportTown::~aImportTown() {
bool aImportTown::undo_me() {
scenario.towns[which] = old_town;
clamp_view_center(old_town);
set_current_town(which);
start_town_edit();
return true;
}
bool aImportTown::redo_me() {
scenario.towns[which] = new_town;
clamp_view_center(new_town);
set_current_town(which);
start_town_edit();
return true;
}