diff --git a/rsrc/dialogs/no-items.xml b/rsrc/dialogs/no-items.xml new file mode 100644 index 00000000..c7629954 --- /dev/null +++ b/rsrc/dialogs/no-items.xml @@ -0,0 +1,8 @@ + + + + + + + There are no items in this town. + diff --git a/src/scenario/town.cpp b/src/scenario/town.cpp index 330d9f84..5e1515f5 100644 --- a/src/scenario/town.cpp +++ b/src/scenario/town.cpp @@ -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; +} \ No newline at end of file diff --git a/src/scenario/town.hpp b/src/scenario/town.hpp index 34c2e8cf..808b0a48 100644 --- a/src/scenario/town.hpp +++ b/src/scenario/town.hpp @@ -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); diff --git a/src/scenedit/scen.main.cpp b/src/scenedit/scen.main.cpp index 2a770eab..286f1ad2 100644 --- a/src/scenedit/scen.main.cpp +++ b/src/scenedit/scen.main.cpp @@ -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);