undo/redo create/delete quest/shop

This commit is contained in:
2025-06-12 13:59:39 -05:00
parent 46c00579d1
commit b089770efd
4 changed files with 107 additions and 7 deletions

View File

@@ -639,16 +639,35 @@ static bool handle_rb_action(location the_point, bool option_hit) {
case RB_QUEST:
size_before = scenario.quests.size();
if(option_hit) {
if(j == scenario.quests.size() - 1)
// Delete last quest
if(j == scenario.quests.size() - 1){
undo_list.add(action_ptr(new aCreateDeleteQuest(false, scenario.quests.back())));
update_edit_menu();
scenario.quests.pop_back();
}
// Clear quest (it can't be deleted fully)
else {
scenario.quests[j] = cQuest();
scenario.quests[j].name = "Unused Quest";
}
} else {
if(!edit_quest(j) && j == size_before && scenario.quests[j].name == "New Quest")
bool is_new = (j == scenario.quests.size());
if(edit_quest(j)){
// Create new confirmed
if(is_new){
undo_list.add(action_ptr(new aCreateDeleteQuest(true, scenario.quests.back())));
update_edit_menu();
}
// Quest edited
else{
// TODO undo action
}
}
// Create new canceled
else if(is_new){
scenario.quests.pop_back();
}
}
if(size_before > scenario.quests.size())
pos_before--;
right_sbar->setPosition(pos_before);
@@ -656,13 +675,32 @@ static bool handle_rb_action(location the_point, bool option_hit) {
case RB_SHOP:
size_before = scenario.shops.size();
if(option_hit) {
if(j == scenario.shops.size() - 1)
// Delete last shop
if(j == scenario.shops.size() - 1){
undo_list.add(action_ptr(new aCreateDeleteShop(false, scenario.shops.back())));
update_edit_menu();
scenario.shops.pop_back();
}
// Clear shop (it can't be fully deleted)
else scenario.shops[j] = cShop("Unused Shop");
} else {
if(!edit_shop(j) && j == size_before && scenario.shops[j].getName() == "New Shop")
bool is_new = (j == scenario.shops.size());
if(edit_shop(j)){
// Create new confirmed
if(is_new){
undo_list.add(action_ptr(new aCreateDeleteShop(true, scenario.shops.back())));
update_edit_menu();
}
// Shop edited
else{
// TODO undo action
}
}
// Create new canceled
else if(is_new){
scenario.shops.pop_back();
}
}
start_shops_editing();
if(size_before > scenario.shops.size())
pos_before--;

View File

@@ -2667,8 +2667,7 @@ static bool add_shop_entry(cDialog& me, std::string type, cShop& shop, size_t wh
bool edit_shop(size_t which_shop, cDialog* parent) {
using namespace std::placeholders;
if(which_shop == scenario.shops.size())
scenario.shops.emplace_back("New Shop");
if(which_shop == scenario.shops.size()) scenario.shops.emplace_back("New Shop");
cShop shop = scenario.shops[which_shop];
if(shop.size() == 0 && (shop.getName() == "New Shop" || shop.getName() == "Unused Shop")) {
cChoiceDlog new_shop_dlg("new-shop", {"magic", "heal", "custom", "cancel"});

View File

@@ -400,3 +400,43 @@ bool aCreateDeleteSpecialItem::redo_me() {
scenario.special_items.push_back(item);
return true;
}
bool aCreateDeleteQuest::undo_me() {
// If not editing quests, show it
if(overall_mode != MODE_EDIT_QUESTS){
start_quest_editing();
// TODO Go to scroll maximum
}
scenario.quests.pop_back();
return true;
}
bool aCreateDeleteQuest::redo_me() {
// If not editing quests, show it
if(overall_mode != MODE_EDIT_QUESTS){
start_quest_editing();
// TODO Go to scroll maximum
}
scenario.quests.push_back(quest);
return true;
}
bool aCreateDeleteShop::undo_me() {
// If not editing shops, show it
if(overall_mode != MODE_EDIT_SHOPS){
start_shops_editing();
// TODO Go to scroll maximum
}
scenario.shops.pop_back();
return true;
}
bool aCreateDeleteShop::redo_me() {
// If not editing shops, show it
if(overall_mode != MODE_EDIT_SHOPS){
start_shops_editing();
// TODO Go to scroll maximum
}
scenario.shops.push_back(shop);
return true;
}

View File

@@ -6,6 +6,7 @@
#include "scenario/town.hpp"
#include "scenario/scenario.hpp"
#include "scenario/item.hpp"
#include "scenario/quest.hpp"
#include "scenario/monster.hpp"
#include "scenario/vehicle.hpp"
@@ -245,6 +246,28 @@ public:
item(item) {}
};
/// Action which adds new quest to the end of the list, or deletes from the end of the list
class aCreateDeleteQuest : public cAction {
cQuest quest;
bool undo_me() override;
bool redo_me() override;
public:
aCreateDeleteQuest(bool create, cQuest quest) :
cAction(create ? "Create Quest" : "Delete Quest", !create),
quest(quest) {}
};
/// Action which adds new shop to the end of the list, or deletes from the end of the list
class aCreateDeleteShop : public cAction {
cShop shop;
bool undo_me() override;
bool redo_me() override;
public:
aCreateDeleteShop(bool create, cShop shop) :
cAction(create ? "Create Shop" : "Delete Shop", !create),
shop(shop) {}
};
/// Action which edits or clears a terrain type
class aEditClearTerrain : public cAction {
ter_num_t which;