undo/redo for setting special number
This commit is contained in:
@@ -2807,7 +2807,12 @@ void set_special(location spot_hit) {
|
||||
// Edit the node of the encounter already on the space
|
||||
if(specials[x] == spot_hit && specials[x].spec >= 0) {
|
||||
int spec = edit_special_num(editing_town ? 2 : 1,specials[x].spec);
|
||||
if(spec >= 0) specials[x].spec = spec;
|
||||
if(spec >= 0 && spec != specials[x].spec){
|
||||
undo_list.add(action_ptr(new aSetSpecial(spot_hit, specials[x].spec, spec)));
|
||||
// TODO if create/edit was used, add those actions
|
||||
update_edit_menu();
|
||||
specials[x].spec = spec;
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(short x = 0; x <= specials.size(); x++) {
|
||||
|
@@ -90,6 +90,24 @@ bool aPlaceEraseSpecial::redo_me() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aSetSpecial::undo_me() {
|
||||
cArea* cur_area = get_current_area();
|
||||
auto& specials = cur_area->special_locs;
|
||||
for(spec_loc_t& special : specials){
|
||||
if(special == area.where) special.spec = old_num;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aSetSpecial::redo_me() {
|
||||
cArea* cur_area = get_current_area();
|
||||
auto& specials = cur_area->special_locs;
|
||||
for(spec_loc_t& special : specials){
|
||||
if(special == area.where) special.spec = new_num;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
aCreateDeleteTown::aCreateDeleteTown(bool create, cTown* t)
|
||||
: cAction(create ? "Create Town" : "Delete Last Town", !create)
|
||||
, theTown(t)
|
||||
|
@@ -76,6 +76,17 @@ private:
|
||||
bool editing_town;
|
||||
};
|
||||
|
||||
/// Action that sets the number of an existing special encounter
|
||||
class aSetSpecial : public cTerrainAction {
|
||||
short old_num;
|
||||
short new_num;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aSetSpecial(location where, short old_num, short new_num) :
|
||||
cTerrainAction("Edit Special Encounter", where), old_num(old_num), new_num(new_num) {}
|
||||
};
|
||||
|
||||
/// Action which modifies terrain tiles (i.e. paintbrush, pencil, eraser)
|
||||
class aDrawTerrain : public cTerrainAction {
|
||||
public:
|
||||
|
Reference in New Issue
Block a user