undo/redo for town event timers
This commit is contained in:
@@ -828,10 +828,16 @@ void edit_town_details() {
|
||||
|
||||
static bool save_town_events(cDialog& me, std::string, eKeyMod) {
|
||||
if(!me.toast(true)) return true;
|
||||
auto old_timers = town->timers;
|
||||
bool changed = false;
|
||||
for(int i = 0; i < town->timers.size(); i++) {
|
||||
std::string id = std::to_string(i + 1);
|
||||
town->timers[i].time = me["time" + id].getTextAsNum();
|
||||
town->timers[i].node = me["spec" + id].getTextAsNum();
|
||||
if((town->timers[i].time != old_timers[i].time) || (town->timers[i].node != old_timers[i].node)) changed = true;
|
||||
}
|
||||
if(changed){
|
||||
undo_list.add(action_ptr(new aEditTownTimers(cur_town, old_timers, town->timers)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -960,4 +960,14 @@ bool aEditTownAdvancedDetails::undo_me() {
|
||||
bool aEditTownAdvancedDetails::redo_me() {
|
||||
town_set_advanced(which, *scenario.towns[which], scenario, new_details);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownTimers::undo_me() {
|
||||
scenario.towns[which]->timers = old_timers;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownTimers::redo_me() {
|
||||
scenario.towns[which]->timers = new_timers;
|
||||
return true;
|
||||
}
|
@@ -620,4 +620,15 @@ public:
|
||||
cAction("Edit Town Advanced Details"), which(which), old_details(old_details), new_details(new_details) {}
|
||||
};
|
||||
|
||||
class aEditTownTimers : public cAction {
|
||||
size_t which;
|
||||
std::array<cTimer,8> old_timers;
|
||||
std::array<cTimer,8> new_timers;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditTownTimers(size_t which, std::array<cTimer,8> old_timers, std::array<cTimer,8> new_timers) :
|
||||
cAction("Edit Town Event Timers"), which(which), old_timers(old_timers), new_timers(new_timers) {}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user