undo/redo edit horse or boat
This commit is contained in:
@@ -68,6 +68,7 @@ void cVehicle::readFrom(const cTagFile_Page& page) {
|
||||
}
|
||||
|
||||
bool operator==(const cVehicle& a, const cVehicle& b) {
|
||||
if(a.name != b.name) return false;
|
||||
if(a.which_town != b.which_town)
|
||||
return false;
|
||||
if(a.exists != b.exists) return false;
|
||||
|
@@ -1104,13 +1104,19 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) {
|
||||
break;
|
||||
case MODE_PLACE_BOAT: case MODE_PLACE_HORSE: {
|
||||
bool is_new = false;
|
||||
cVehicle old_vehicle;
|
||||
auto& all = overall_mode == MODE_PLACE_BOAT ? scenario.boats : scenario.horses;
|
||||
auto iter = std::find_if(all.begin(), all.end(), [](const cVehicle& what) {
|
||||
if(editing_town && cur_town != what.which_town) return false;
|
||||
else if(!editing_town && what.sector != cur_out) return false;
|
||||
return what.loc == spot_hit;
|
||||
});
|
||||
if(iter == all.end()) {
|
||||
// Edit existing
|
||||
if(iter != all.end()){
|
||||
old_vehicle = *iter;
|
||||
}
|
||||
// Create new
|
||||
else{
|
||||
iter = std::find_if(all.begin(), all.end(), [](const cVehicle& what) {
|
||||
return what.which_town < 0;
|
||||
});
|
||||
@@ -1132,8 +1138,9 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) {
|
||||
update_edit_menu();
|
||||
}
|
||||
// Edited
|
||||
else{
|
||||
|
||||
else if(old_vehicle != *iter){
|
||||
undo_list.add(action_ptr(new aEditVehicle(overall_mode == MODE_PLACE_BOAT, iter - all.begin(), old_vehicle, *iter)));
|
||||
update_edit_menu();
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
@@ -258,6 +258,18 @@ bool aPlaceEraseVehicle::redo_me() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditVehicle::undo_me() {
|
||||
auto& all = is_boat ? scenario.boats : scenario.horses;
|
||||
all[which] = old_vehicle;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditVehicle::redo_me() {
|
||||
auto& all = is_boat ? scenario.boats : scenario.horses;
|
||||
all[which] = new_vehicle;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditSignText::undo_me() {
|
||||
cArea* cur_area = get_current_area();
|
||||
auto& signs = cur_area->sign_locs;
|
||||
|
@@ -109,6 +109,20 @@ public:
|
||||
is_boat(is_boat), which(which), vehicle(vehicle) {}
|
||||
};
|
||||
|
||||
/// Action which edits vehicle
|
||||
class aEditVehicle : public cTerrainAction {
|
||||
bool is_boat;
|
||||
size_t which;
|
||||
cVehicle old_vehicle;
|
||||
cVehicle new_vehicle;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditVehicle(bool is_boat, size_t which, cVehicle old_vehicle, cVehicle new_vehicle) :
|
||||
cTerrainAction(std::string { "Edit " } + (is_boat ? "Boat" : "Horse"), new_vehicle.loc),
|
||||
is_boat(is_boat), which(which), old_vehicle(old_vehicle), new_vehicle(new_vehicle) {}
|
||||
};
|
||||
|
||||
/// Action which edits sign text
|
||||
class aEditSignText : public cTerrainAction {
|
||||
std::string old_text;
|
||||
|
Reference in New Issue
Block a user