undo clear items

This commit is contained in:
2025-06-02 21:30:15 -05:00
parent c662477c43
commit bdf1b8a4a8
4 changed files with 36 additions and 3 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'>There are no items in this town.</text>
</dialog>

View File

@@ -268,3 +268,10 @@ void cTown::set_item_taken(size_t i, bool val) {
if(i >= item_taken.size()) item_taken.resize(i + 1);
item_taken.set(i, val);
}
bool cTown::any_items() const {
for(cItem item: preset_items){
if(item.code >= 0) return true;
}
return false;
}

View File

@@ -115,6 +115,7 @@ public:
void set_up_lights();
short light_obscurity(short x,short y) const; // Obscurity function used for calculating lighting
bool is_cleaned_out() const;
bool any_items() const;
explicit cTown(cScenario& scenario, size_t dim);
void import_legacy(legacy::town_record_type& old);

View File

@@ -694,19 +694,36 @@ void handle_menu_choice(eMenu item_hit) {
change_made = true;
break;
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();
draw_terrain();
change_made = true;
break;
case eMenu::TOWN_ITEMS_CLEAR:
case eMenu::TOWN_ITEMS_CLEAR:{
if(!town->any_items()){
cChoiceDlog("no-items").show();
break;
}
if(cChoiceDlog("clear-items-confirm", {"okay", "cancel"}).show() == "cancel")
break;
town->preset_items.clear();
item_changes_t changes;
auto& town_items = town->preset_items;
for(size_t i = 0; i < town_items.size(); ++i){
if(town_items[i].code < 0) continue;
changes[i] = town_items[i];
town_items[i].code = -1;
}
undo_list.add(action_ptr(new aPlaceEraseItem("Clear Items", false, changes)));
update_edit_menu();
draw_terrain();
change_made = true;
break;
}break;
case eMenu::TOWN_SPECIALS:
right_sbar->setPosition(0);
start_special_editing(2,0);