undo/redo place 4 town entrances
This commit is contained in:
@@ -719,6 +719,8 @@ void commit_stroke() {
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> entrance_names = {"North", "East", "South", "West"};
|
||||
|
||||
static bool handle_terrain_action(location the_point, bool ctrl_hit) {
|
||||
cArea* cur_area = get_current_area();
|
||||
std::shared_ptr<cAction> undo_action = nullptr;
|
||||
@@ -972,6 +974,10 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) {
|
||||
|
||||
case MODE_PLACE_NORTH_ENTRANCE: case MODE_PLACE_EAST_ENTRANCE:
|
||||
case MODE_PLACE_SOUTH_ENTRANCE: case MODE_PLACE_WEST_ENTRANCE:
|
||||
undo_list.add(action_ptr(new aPlaceTownEntrance(
|
||||
std::string {"Place "} + entrance_names[overall_mode - 10] + " Entrance",
|
||||
overall_mode - 10, town->start_locs[overall_mode - 10], spot_hit)));
|
||||
update_edit_menu();
|
||||
town->start_locs[overall_mode - 10].x = spot_hit.x;
|
||||
town->start_locs[overall_mode - 10].y = spot_hit.y;
|
||||
overall_mode = MODE_DRAWING;
|
||||
|
@@ -598,4 +598,16 @@ bool aImportOutdoors::redo_me() {
|
||||
set_current_out(which);
|
||||
start_out_edit();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aPlaceTownEntrance::undo_me() {
|
||||
town->start_locs[which_entrance].x = old_loc.x;
|
||||
town->start_locs[which_entrance].y = old_loc.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aPlaceTownEntrance::redo_me() {
|
||||
town->start_locs[which_entrance].x = new_loc.x;
|
||||
town->start_locs[which_entrance].y = new_loc.y;
|
||||
return true;
|
||||
}
|
@@ -382,4 +382,16 @@ public:
|
||||
~aImportOutdoors();
|
||||
};
|
||||
|
||||
/// Action which places one of the four entrance locations inside a town
|
||||
class aPlaceTownEntrance : public cTerrainAction {
|
||||
int which_entrance;
|
||||
location old_loc;
|
||||
location new_loc;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aPlaceTownEntrance(std::string name, int which, location old_loc, location new_loc) :
|
||||
cTerrainAction(name, new_loc), which_entrance(which), old_loc(old_loc), new_loc(new_loc) {}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user