# HG changeset patch # User rubidium # Date 2009-01-02 20:59:04 # Node ID 99ad5205b347f019610cd87321163814976fbaac # Parent adb65148b086be4fdd5334fb24302741b902f54a (svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view. diff --git a/src/station.cpp b/src/station.cpp --- a/src/station.cpp +++ b/src/station.cpp @@ -33,6 +33,7 @@ #include "order_func.h" #include "news_func.h" #include "aircraft.h" +#include "vehicle_gui.h" #include "table/sprites.h" #include "table/strings.h" @@ -87,6 +88,11 @@ Station::~Station() InvalidateWindowData(WC_STATION_LIST, this->owner, 0); DeleteWindowById(WC_STATION_VIEW, index); + WindowNumber wno = (index << 16) | VLW_STATION_LIST | this->owner; + DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); + DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); + DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); + DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11)); /* Now delete all orders that go to the station */ RemoveOrderFromAllVehicles(OT_GOTO_STATION, index); diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -700,10 +700,10 @@ struct StationViewWindow : public Window WindowNumber wno = (this->window_number << 16) | VLW_STATION_LIST | GetStation(this->window_number)->owner; - DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); - DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); - DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); - DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11)); + DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11), false); + DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11), false); + DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11), false); + DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11), false); } virtual void OnPaint() diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1293,6 +1293,10 @@ CommandCost CmdMoveRailVehicle(TileIndex if (IsFrontEngine(src)) { /* the vehicle was previously a loco. need to free the order list and delete vehicle windows etc. */ DeleteWindowById(WC_VEHICLE_VIEW, src->index); + DeleteWindowById(WC_VEHICLE_ORDERS, src->index); + DeleteWindowById(WC_VEHICLE_REFIT, src->index); + DeleteWindowById(WC_VEHICLE_DETAILS, src->index); + DeleteWindowById(WC_VEHICLE_TIMETABLE, src->index); DeleteVehicleOrders(src); RemoveVehicleFromGroup(src); } @@ -1402,6 +1406,10 @@ CommandCost CmdSellRailWagon(TileIndex t if (flags & DC_EXEC) { if (v == first && IsFrontEngine(first)) { DeleteWindowById(WC_VEHICLE_VIEW, first->index); + DeleteWindowById(WC_VEHICLE_ORDERS, first->index); + DeleteWindowById(WC_VEHICLE_REFIT, first->index); + DeleteWindowById(WC_VEHICLE_DETAILS, first->index); + DeleteWindowById(WC_VEHICLE_TIMETABLE, first->index); } InvalidateWindow(WC_VEHICLE_DEPOT, first->tile); InvalidateWindowClassesData(WC_TRAINS_LIST, 0); diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -672,8 +672,10 @@ void Vehicle::PreDestructor() if (this->IsPrimaryVehicle()) { DeleteWindowById(WC_VEHICLE_VIEW, this->index); + DeleteWindowById(WC_VEHICLE_ORDERS, this->index); + DeleteWindowById(WC_VEHICLE_REFIT, this->index); DeleteWindowById(WC_VEHICLE_DETAILS, this->index); - DeleteWindowById(WC_VEHICLE_ORDERS, this->index); + DeleteWindowById(WC_VEHICLE_TIMETABLE, this->index); InvalidateWindow(WC_COMPANY, this->owner); } InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1817,10 +1817,10 @@ struct VehicleViewWindow : Window { ~VehicleViewWindow() { - DeleteWindowById(WC_VEHICLE_ORDERS, this->window_number); - DeleteWindowById(WC_VEHICLE_REFIT, this->window_number); - DeleteWindowById(WC_VEHICLE_DETAILS, this->window_number); - DeleteWindowById(WC_VEHICLE_TIMETABLE, this->window_number); + DeleteWindowById(WC_VEHICLE_ORDERS, this->window_number, false); + DeleteWindowById(WC_VEHICLE_REFIT, this->window_number, false); + DeleteWindowById(WC_VEHICLE_DETAILS, this->window_number, false); + DeleteWindowById(WC_VEHICLE_TIMETABLE, this->window_number, false); } virtual void OnPaint() diff --git a/src/window.cpp b/src/window.cpp --- a/src/window.cpp +++ b/src/window.cpp @@ -492,10 +492,16 @@ Window *FindWindowById(WindowClass cls, * Delete a window by its class and window number (if it is open). * @param cls Window class * @param number Number of the window within the window class + * @param force force deletion; if false don't delete when stickied */ -void DeleteWindowById(WindowClass cls, WindowNumber number) +void DeleteWindowById(WindowClass cls, WindowNumber number, bool force) { - delete FindWindowById(cls, number); + Window *w = FindWindowById(cls, number); + if (force || w == NULL || + (w->desc_flags & WDF_STICKY_BUTTON) == 0 || + (w->flags4 & WF_STICKY) == 0) { + delete w; + } } /** diff --git a/src/window_func.h b/src/window_func.h --- a/src/window_func.h +++ b/src/window_func.h @@ -35,7 +35,7 @@ void InvalidateWindowWidget(WindowClass void InvalidateWindow(WindowClass cls, WindowNumber number); void InvalidateWindowClasses(WindowClass cls); -void DeleteWindowById(WindowClass cls, WindowNumber number); +void DeleteWindowById(WindowClass cls, WindowNumber number, bool force = true); void DeleteWindowByClass(WindowClass cls); #endif /* WINDOW_FUNC_H */