undo/redo for town details
This commit is contained in:
@@ -752,20 +752,29 @@ void edit_out_wand(short mode) {
|
||||
|
||||
static bool save_town_details(cDialog& me, std::string, eKeyMod) {
|
||||
if(!me.toast(true)) return true;
|
||||
town->name = me["name"].getText();
|
||||
town->town_chop_time = me["chop"].getTextAsNum();
|
||||
town->town_chop_key = me["key"].getTextAsNum();
|
||||
town->max_num_monst = me["population"].getTextAsNum();
|
||||
town->difficulty = me["difficulty"].getTextAsNum();
|
||||
town_details_t old_details = details_from_town(*town);
|
||||
town_details_t new_details = old_details;
|
||||
|
||||
new_details.name = me["name"].getText();
|
||||
new_details.town_chop_time = me["chop"].getTextAsNum();
|
||||
new_details.town_chop_key = me["key"].getTextAsNum();
|
||||
new_details.max_num_monst = me["population"].getTextAsNum();
|
||||
new_details.difficulty = me["difficulty"].getTextAsNum();
|
||||
std::string lighting = dynamic_cast<cLedGroup&>(me["lighting"]).getSelected();
|
||||
if(lighting == "lit") town->lighting_type = LIGHT_NORMAL;
|
||||
else if(lighting == "dark") town->lighting_type = LIGHT_DARK;
|
||||
else if(lighting == "drains") town->lighting_type = LIGHT_DRAINS;
|
||||
else if(lighting == "no-light") town->lighting_type = LIGHT_NONE;
|
||||
if(lighting == "lit") new_details.lighting_type = LIGHT_NORMAL;
|
||||
else if(lighting == "dark") new_details.lighting_type = LIGHT_DARK;
|
||||
else if(lighting == "drains") new_details.lighting_type = LIGHT_DRAINS;
|
||||
else if(lighting == "no-light") new_details.lighting_type = LIGHT_NONE;
|
||||
cStack& comments = dynamic_cast<cStack&>(me["cmt"]);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
comments.setPage(i);
|
||||
town->comment[i] = comments["comment"].getText();
|
||||
new_details.comment[i] = comments["comment"].getText();
|
||||
}
|
||||
|
||||
if(new_details != old_details){
|
||||
town_set_details(*town, new_details);
|
||||
undo_list.add(action_ptr(new aEditTownDetails(cur_town, old_details, new_details)));
|
||||
update_edit_menu();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -928,4 +928,14 @@ bool aEditItemShortcut::undo_me() {
|
||||
bool aEditItemShortcut::redo_me() {
|
||||
scenario.storage_shortcuts[which] = new_shortcut;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownDetails::undo_me() {
|
||||
town_set_details(*scenario.towns[which], old_details);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownDetails::redo_me() {
|
||||
town_set_details(*scenario.towns[which], new_details);
|
||||
return true;
|
||||
}
|
@@ -583,4 +583,15 @@ public:
|
||||
cAction("Edit Item Placement Shortcut"), which(which), old_shortcut(old_shortcut), new_shortcut(new_shortcut) {}
|
||||
};
|
||||
|
||||
class aEditTownDetails : public cAction {
|
||||
size_t which;
|
||||
town_details_t old_details;
|
||||
town_details_t new_details;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditTownDetails(size_t which, town_details_t old_details, town_details_t new_details) :
|
||||
cAction("Edit Town Details"), which(which), old_details(old_details), new_details(new_details) {}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user