diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 2ca0d4f90e..446f246062 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -153,6 +153,13 @@ public: this->owner = v->owner; } + ~CargoTypeOrdersWindow() + { + if (!FocusWindowById(WC_VEHICLE_ORDERS, this->window_number)) { + MarkAllRouteStepsDirty(this); + } + } + virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget == WID_CTO_HEADER) { @@ -241,6 +248,22 @@ public: SetDParam(2, this->vehicle->GetOrder(this->order_id)->GetDestination()); } } + + virtual void OnFocus(Window *previously_focused_window) OVERRIDE + { + if (HasFocusedVehicleChanged(this->window_number, previously_focused_window)) { + MarkAllRoutePathsDirty(this->vehicle); + MarkAllRouteStepsDirty(this); + } + } + + virtual void OnFocusLost(Window *newly_focused_window) OVERRIDE + { + if (HasFocusedVehicleChanged(this->window_number, newly_focused_window)) { + MarkAllRoutePathsDirty(this->vehicle); + MarkAllRouteStepsDirty(this); + } + } }; /** @@ -1289,6 +1312,8 @@ public: ~OrdersWindow() { + DeleteWindowById(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS, this->window_number, false); + DeleteWindowById(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS, this->window_number, false); if (!FocusWindowById(WC_VEHICLE_VIEW, this->window_number)) { MarkAllRouteStepsDirty(this); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index dcdef4af9a..9dc4ba1e48 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -877,6 +877,8 @@ void Vehicle::PreDestructor() DeleteWindowById(WC_VEHICLE_REFIT, this->index); DeleteWindowById(WC_VEHICLE_DETAILS, this->index); DeleteWindowById(WC_VEHICLE_TIMETABLE, this->index); + DeleteWindowById(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS, this->index); + DeleteWindowById(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS, this->index); SetWindowDirty(WC_COMPANY, this->owner); OrderBackup::ClearVehicle(this); } diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 7d131c4dbc..895a14b2c7 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -126,6 +126,8 @@ static inline bool HasFocusedVehicleChanged(const VehicleID vid, Window *ref_win case WC_VEHICLE_ORDERS: case WC_VEHICLE_TIMETABLE: case WC_VEHICLE_VIEW: + case WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS: + case WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS: return ((uint32) wn != vid); } } diff --git a/src/viewport.cpp b/src/viewport.cpp index 2ddbee3365..a998844ffd 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1714,6 +1714,8 @@ static inline Vehicle *GetVehicleFromWindow(Window *w) case WC_VEHICLE_TIMETABLE: case WC_VEHICLE_DETAILS: case WC_VEHICLE_REFIT: + case WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS: + case WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS: if (wn != INVALID_VEHICLE) return Vehicle::Get(wn); break; default: