undo/redo paste terrain

This commit is contained in:
2025-06-03 11:28:17 -05:00
parent da988afb28
commit 6240d0a657
2 changed files with 59 additions and 50 deletions

View File

@@ -957,7 +957,12 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) {
} else if(auto patch = boost::get<vector2d<ter_num_t>>(&clipboard)) {
for(int x = 0; x < patch->width(); x++)
for(int y = 0; y < patch->height(); y++)
cur_area->terrain(spot_hit.x + x, spot_hit.y + y) = (*patch)[x][y];
set_terrain(loc(spot_hit.x + x, spot_hit.y + y), (*patch)[x][y], current_stroke_changes, false);
if(!current_stroke_changes.empty()){
undo_list.add(action_ptr(new aDrawTerrain("Paste Terrain", current_stroke_changes)));
update_edit_menu();
current_stroke_changes.clear();
}
} else {
showError("Nothing to paste. Try copying something first.");
}
@@ -2190,7 +2195,7 @@ static const std::array<location,5> trim_diffs = {{
loc(0,0), loc(-1,0), loc(1,0), loc(0,-1), loc(0,1)
}};
void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_changes) {
void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_changes, bool handle_special) {
cArea* cur_area = get_current_area();
if(!cur_area->is_on_map(l)) return;
@@ -2222,6 +2227,7 @@ void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_
cur_area->terrain(l.x,l.y) = terrain_type;
location l2 = l;
if(handle_special){
// Large objects (eg rubble)
if(scenario.ter_types[terrain_type].obj_num > 0){
int q = scenario.ter_types[terrain_type].obj_num;
@@ -2276,6 +2282,7 @@ void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_
if(!cur_area->is_on_map(l3)) continue;
adjust_space(l3, stroke_changes);
}
}
cTerrain& ter = scenario.ter_types[terrain_type];
// Handle placing special terrains:
@@ -2288,6 +2295,7 @@ void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_
mouse_button_held = false;
return;
}
if(!handle_special) return;
auto& signs = cur_area->sign_locs;
auto iter = std::find(signs.begin(), signs.end(), l);
if(iter == signs.end()) {
@@ -2313,6 +2321,7 @@ void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_
}
// Town entrances in the outdoors:
else if(ter.special == eTerSpec::TOWN_ENTRANCE && !editing_town){
if(!handle_special) return;
// Let the designer know the terrain was placed:
draw_terrain();
redraw_screen();

View File

@@ -23,7 +23,7 @@ void change_rect_terrain(rectangle r,ter_num_t terrain_type,short probability,bo
void flood_fill_terrain(location start, ter_num_t terrain_type);
void frill_up_terrain();
void unfrill_terrain();
void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_changes);
void set_terrain(location l,ter_num_t terrain_type,stroke_ter_changes_t& stroke_changes,bool handle_special=true);
void adjust_space(location l,stroke_ter_changes_t& stroke_changes);
void commit_stroke();
bool is_lava(short x,short y);