undo/redo create/delete special item

This commit is contained in:
2025-06-12 10:47:05 -05:00
parent 6d7711dd22
commit 07b6044d36
3 changed files with 47 additions and 2 deletions

View File

@@ -475,21 +475,44 @@ static bool handle_rb_action(location the_point, bool option_hit) {
case RB_SPEC_ITEM:
size_before = scenario.special_items.size();
if(option_hit) {
if(j == size_before - 1)
// Delete last special item
if(j == size_before - 1){
undo_list.add(action_ptr(new aCreateDeleteSpecialItem(false, scenario.special_items.back())));
update_edit_menu();
scenario.special_items.pop_back();
}
else if(j == size_before)
break;
// Clear special item (it can't be deleted fully)
else {
// TODO undo action
scenario.special_items[j] = cSpecItem();
scenario.special_items[j].name = "Unused Special Item";
}
} else {
bool is_new = false;
// Create new special item
if(j == size_before) {
is_new = true;
scenario.special_items.emplace_back();
scenario.special_items.back().name = "New Special Item";
}
if(!edit_spec_item(j) && j == size_before)
if(edit_spec_item(j)){
// Create new confirmed
if(is_new){
undo_list.add(action_ptr(new aCreateDeleteSpecialItem(true, scenario.special_items.back())));
update_edit_menu();
}
// Special item edited
else{
// TODO undo action
}
}
// Create new canceled
else if(is_new){
scenario.special_items.pop_back();
}
}
if(size_before > scenario.special_items.size())
pos_before--;

View File

@@ -329,4 +329,15 @@ bool aEditPlacedCreature::undo_me() {
bool aEditPlacedCreature::redo_me() {
town->creatures[which] = new_creature;
return true;
}
bool aCreateDeleteSpecialItem::undo_me() {
scenario.special_items.pop_back();
return true;
}
bool aCreateDeleteSpecialItem::redo_me() {
scenario.special_items.push_back(item);
return true;
}

View File

@@ -234,6 +234,17 @@ public:
items(items) {}
};
/// Action which adds new special item to the end of the list, or deletes from the end of the list
class aCreateDeleteSpecialItem : public cAction {
cSpecItem item;
bool undo_me() override;
bool redo_me() override;
public:
aCreateDeleteSpecialItem(bool create, cSpecItem item) :
cAction(create ? "Create Special Item" : "Delete Special Item", !create),
item(item) {}
};
/// Action which edits or clears a terrain type
class aEditClearTerrain : public cAction {
ter_num_t which;