diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index 291730771..1020f8c5f 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -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; } diff --git a/src/scenedit/scen.undo.cpp b/src/scenedit/scen.undo.cpp index d67348947..dc8f1e1c0 100644 --- a/src/scenedit/scen.undo.cpp +++ b/src/scenedit/scen.undo.cpp @@ -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; } \ No newline at end of file diff --git a/src/scenedit/scen.undo.hpp b/src/scenedit/scen.undo.hpp index e05ea167c..082259495 100644 --- a/src/scenedit/scen.undo.hpp +++ b/src/scenedit/scen.undo.hpp @@ -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 \ No newline at end of file