undo/redo for town bounds and saved item rects
This commit is contained in:
@@ -903,6 +903,8 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) {
|
||||
change_made = true;
|
||||
}
|
||||
else if(overall_mode == MODE_SET_TOWN_RECT) {
|
||||
undo_list.add(action_ptr(new aEditTownBounds(false, town->in_town_rect, working_rect)));
|
||||
update_edit_menu();
|
||||
town->in_town_rect = working_rect;
|
||||
change_made = true;
|
||||
}
|
||||
@@ -924,6 +926,8 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) {
|
||||
change_made = true;
|
||||
}
|
||||
else if(overall_mode == MODE_STORAGE_RECT) {
|
||||
undo_list.add(action_ptr(new aEditTownBounds(true, scenario.store_item_rects[cur_town], working_rect)));
|
||||
update_edit_menu();
|
||||
scenario.store_item_rects[cur_town] = working_rect;
|
||||
change_made = true;
|
||||
}
|
||||
|
||||
@@ -1212,4 +1212,23 @@ bool aEditSpecial::redo_me() {
|
||||
}
|
||||
start_special_editing(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownBounds::undo_me() {
|
||||
if(for_saved_items){
|
||||
if(old_rect.empty()) scenario.store_item_rects.erase(area.town_num);
|
||||
else scenario.store_item_rects[area.town_num] = old_rect;
|
||||
}else{
|
||||
scenario.towns[area.town_num]->in_town_rect = old_rect;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownBounds::redo_me() {
|
||||
if(for_saved_items){
|
||||
scenario.store_item_rects[area.town_num] = new_rect;
|
||||
}else{
|
||||
scenario.towns[area.town_num]->in_town_rect = new_rect;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -813,4 +813,20 @@ public:
|
||||
cAction("Clear Special Node"), mode(mode), which(which), old_spec(old_spec), new_spec(cSpecial()), which_town(cur_town), which_out(cur_out) {}
|
||||
};
|
||||
|
||||
class aEditTownBounds : public cTerrainAction {
|
||||
rectangle old_rect;
|
||||
rectangle new_rect;
|
||||
bool for_saved_items;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditTownBounds(bool saved_items, rectangle old_rect, rectangle new_rect) :
|
||||
cTerrainAction((saved_items ?
|
||||
(old_rect.empty() ?
|
||||
"Create Saved Item Area"
|
||||
: "Edit Saved Item Area")
|
||||
:"Edit Town Boundaries"), new_rect.topLeft()),
|
||||
for_saved_items(saved_items), old_rect(old_rect), new_rect(new_rect) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user