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

@@ -9,13 +9,11 @@
<text size='large' top='6' left='50' width='175' height='17'>Importing a town</text>
<text name='prompt' top='143' left='50' width='162' height='27'>What town do you wish to import? (0 - {{max-num}})</text>
<text top='27' left='50' width='301' height='54'>
Enter a town number and hit OK, and you will be asked to select a scenario file.
The town with that number in the selected scenario will then be loaded in over the current town.
The town with this number in the selected scenario be imported.
</text>
<button name='cancel' type='regular' top='181' left='212'>Cancel</button>
<text top='83' left='50' width='301' height='54'>
Warning: This will write over the town currently in memory.
Also, the town you select must be the same size (large/medium/small) as the town currently in memory.
Warning: This will overwrite over the town currently in memory.
</text>
<button name='choose' type='regular' top='146' left='281'>Choose</button>
</dialog>

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;
}