undo/redo for town wandering monsters
This commit is contained in:
@@ -1034,13 +1034,22 @@ void edit_advanced_town() {
|
|||||||
|
|
||||||
static bool save_town_wand(cDialog& me, std::string, eKeyMod) {
|
static bool save_town_wand(cDialog& me, std::string, eKeyMod) {
|
||||||
if(!me.toast(true)) return true;
|
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++) {
|
for(int i = 0; i < town->wandering.size(); i++) {
|
||||||
std::string base_id = "group" + std::to_string(i + 1) + "-monst";
|
std::string base_id = "group" + std::to_string(i + 1) + "-monst";
|
||||||
for(int j = 0; j < 4; j++) {
|
for(int j = 0; j < 4; j++) {
|
||||||
std::string id = base_id + std::to_string(j + 1);
|
std::string id = base_id + std::to_string(j + 1);
|
||||||
town->wandering[i].monst[j] = me[id].getTextAsNum();
|
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());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -939,3 +939,15 @@ bool aEditTownDetails::redo_me() {
|
|||||||
town_set_details(*scenario.towns[which], new_details);
|
town_set_details(*scenario.towns[which], new_details);
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
@@ -594,4 +594,19 @@ public:
|
|||||||
cAction("Edit Town Details"), which(which), old_details(old_details), new_details(new_details) {}
|
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
|
#endif
|
||||||
Reference in New Issue
Block a user