undo/redo setting all items not property

This commit is contained in:
2025-06-11 17:46:38 -05:00
parent c50f42ffde
commit 4a8d58926a
4 changed files with 50 additions and 6 deletions

View File

@@ -0,0 +1,8 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<!-- NOTE: This file should be updated to use relative positioning the next time it changes. -->
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<dialog defbtn='okay' escbtn='okay'>
<button name='okay' type='regular' top='37' left='256'>OK</button>
<pict type='dlog' num='16' top='6' left='6'/>
<text top='6' left='49' width='272' height='28'>Nothing changed. No items in this town were marked as property.</text>
</dialog>

View File

@@ -693,17 +693,28 @@ void handle_menu_choice(eMenu item_hit) {
place_items_in_town();
change_made = true;
break;
case eMenu::TOWN_ITEMS_NOT_PROPERTY:
case eMenu::TOWN_ITEMS_NOT_PROPERTY:{
if(!town->any_items()){
cChoiceDlog("no-items").show();
break;
}
for(int i = 0; i < town->preset_items.size(); i++)
town->preset_items[i].property = 0;
cChoiceDlog("set-not-owned").show();
std::vector<bool> old_property;
bool any_were = false;
for(cTown::cItem& item: town->preset_items){
if(item.property) any_were = true;
old_property.push_back(item.property);
item.property = false;
}
if(any_were){
undo_list.add(action_ptr(new aClearProperty(old_property)));
update_edit_menu();
cChoiceDlog("set-not-owned").show();
}else{
cChoiceDlog("no-items-property").show();
}
draw_terrain();
change_made = true;
break;
}break;
case eMenu::TOWN_ITEMS_CLEAR:{
if(!town->any_items()){
cChoiceDlog("no-items").show();

View File

@@ -6,7 +6,7 @@
extern bool editing_town;
extern short cur_town;
extern short cur_town;
extern cTown* town;
extern location cur_out;
extern short cen_x;
extern short cen_y;
@@ -295,4 +295,18 @@ bool aEditTownEntrance::undo_me() {
bool aEditTownEntrance::redo_me() {
set_town_entrance(area.where, new_town);
return true;
}
bool aClearProperty::undo_me() {
for(size_t i = 0; i < town->preset_items.size(); ++i){
town->preset_items[i].property = old_property[i];
}
return true;
}
bool aClearProperty::redo_me() {
for(cTown::cItem& item : town->preset_items){
item.property = false;
}
return true;
}

View File

@@ -10,6 +10,7 @@
#include "scenario/vehicle.hpp"
extern cScenario scenario;
extern cTown* town;
struct area_ref_t {
bool is_town;
@@ -49,6 +50,16 @@ protected:
area_ref_t area;
};
/// Action that clears the 'not yours' flag from every item in town
class aClearProperty : public cTerrainAction {
std::vector<bool> old_property;
bool undo_me() override;
bool redo_me() override;
public:
aClearProperty(std::vector<bool> old_property) : cTerrainAction("Set All Items Not Property", town->preset_items[0].loc),
old_property(old_property) {}
};
/// Action that erased a special encounter from a spot
class aEraseSpecial : public cTerrainAction {
public: