undo/redo for town variable entry
This commit is contained in:
@@ -100,6 +100,7 @@ public:
|
||||
bool has_feature_flag(std::string flag);
|
||||
std::string get_feature_flag(std::string flag);
|
||||
|
||||
// Varying town entrances
|
||||
std::array<spec_loc_t,10> town_mods;
|
||||
std::map<short, rectangle> store_item_rects;
|
||||
std::vector<cSpecItem> special_items;
|
||||
|
@@ -2901,6 +2901,9 @@ bool edit_vehicle(cVehicle& what, int num, bool is_boat) {
|
||||
|
||||
static bool save_add_town(cDialog& me) {
|
||||
cTilemap& grid = dynamic_cast<cTilemap&>(me["varying"]);
|
||||
auto old_town_mods = scenario.town_mods;
|
||||
auto new_town_mods = scenario.town_mods;
|
||||
bool changed = false;
|
||||
for(short i = 0; i < scenario.town_mods.size(); i++) {
|
||||
int town = grid.getChild("town", 0, i).getTextAsNum();
|
||||
if(cre(town,
|
||||
@@ -2911,9 +2914,17 @@ static bool save_add_town(cDialog& me) {
|
||||
int sdf_col = grid.getChild("flag-col", 0, i).getTextAsNum();
|
||||
if(cre(sdf_col,0,SDF_COLUMNS - 1,"Second part of flag must be from 0 to " + std::to_string(SDF_COLUMNS - 1) + ".","",&me))
|
||||
return false;
|
||||
scenario.town_mods[i].spec = town;
|
||||
scenario.town_mods[i].x = sdf_col;
|
||||
scenario.town_mods[i].y = sdf_row;
|
||||
if(town != old_town_mods[i].spec) changed = true;
|
||||
if(sdf_col != old_town_mods[i].x) changed = true;
|
||||
if(sdf_row != old_town_mods[i].y) changed = true;
|
||||
new_town_mods[i].spec = town;
|
||||
new_town_mods[i].x = sdf_col;
|
||||
new_town_mods[i].y = sdf_row;
|
||||
}
|
||||
if(changed){
|
||||
scenario.town_mods = new_town_mods;
|
||||
undo_list.add(action_ptr(new aEditTownVarying(old_town_mods, new_town_mods)));
|
||||
update_edit_menu();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -898,4 +898,14 @@ bool aEditAdvancedDetails::undo_me() {
|
||||
bool aEditAdvancedDetails::redo_me() {
|
||||
scen_set_advanced(scenario, new_advanced);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownVarying::undo_me() {
|
||||
scenario.town_mods = old_varying;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditTownVarying::redo_me() {
|
||||
scenario.town_mods = new_varying;
|
||||
return true;
|
||||
}
|
@@ -552,4 +552,14 @@ public:
|
||||
cAction("Edit Advanced Details"), old_advanced(old_advanced), new_advanced(new_advanced) {}
|
||||
};
|
||||
|
||||
class aEditTownVarying : public cAction {
|
||||
std::array<spec_loc_t,10> old_varying;
|
||||
std::array<spec_loc_t,10> new_varying;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditTownVarying(std::array<spec_loc_t,10> old_varying, std::array<spec_loc_t,10> new_varying) :
|
||||
cAction("Edit Town Varying Entrances"), old_varying(old_varying), new_varying(new_varying) {}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user