undo/redo for town wandering monsters

This commit is contained in:
2025-06-19 18:33:16 -05:00
parent de9b383418
commit 77d7212801
3 changed files with 36 additions and 0 deletions

View File

@@ -1034,13 +1034,22 @@ void edit_advanced_town() {
static bool save_town_wand(cDialog& me, std::string, eKeyMod) {
if(!me.toast(true)) return true;
auto old_wandering = town->wandering;
auto old_wandering_locs = town->wandering_locs;
bool changed = false;
for(int i = 0; i < town->wandering.size(); i++) {
std::string base_id = "group" + std::to_string(i + 1) + "-monst";
for(int j = 0; j < 4; j++) {
std::string id = base_id + std::to_string(j + 1);
town->wandering[i].monst[j] = me[id].getTextAsNum();
if(town->wandering[i].monst[j] != old_wandering[i].monst[j]) changed = true;
}
town->wandering_locs[i] = boost::lexical_cast<location>(me["group" + std::to_string(i+1) + "-loc"].getText());
if(town->wandering_locs[i] != old_wandering_locs[i]) changed = true;
}
if(changed){
undo_list.add(action_ptr(new aEditTownWandering(cur_town, old_wandering, old_wandering_locs, town->wandering, town->wandering_locs)));
update_edit_menu();
}
return true;
}

View File

@@ -938,4 +938,16 @@ bool aEditTownDetails::undo_me() {
bool aEditTownDetails::redo_me() {
town_set_details(*scenario.towns[which], new_details);
return true;
}
bool aEditTownWandering::undo_me() {
scenario.towns[which]->wandering = old_wandering;
scenario.towns[which]->wandering_locs = old_wandering_locs;
return true;
}
bool aEditTownWandering::redo_me() {
scenario.towns[which]->wandering = new_wandering;
scenario.towns[which]->wandering_locs = new_wandering_locs;
return true;
}

View File

@@ -594,4 +594,19 @@ public:
cAction("Edit Town Details"), which(which), old_details(old_details), new_details(new_details) {}
};
class aEditTownWandering : public cAction {
size_t which;
std::array<cTown::cWandering,4> old_wandering;
std::array<location, 4> old_wandering_locs;
std::array<cTown::cWandering,4> new_wandering;
std::array<location, 4> new_wandering_locs;
bool undo_me() override;
bool redo_me() override;
public:
aEditTownWandering(size_t which, std::array<cTown::cWandering,4> old_wandering, std::array<location, 4> old_wandering_locs,
std::array<cTown::cWandering,4> new_wandering, std::array<location, 4> new_wandering_locs) :
cAction("Edit Town Wandering Monsters"), which(which), old_wandering(old_wandering), old_wandering_locs(old_wandering_locs),
new_wandering(new_wandering), new_wandering_locs(new_wandering_locs) {}
};
#endif