# HG changeset patch # User rubidium # Date 2008-05-18 16:51:44 # Node ID 6cd3e74fc38e49bac4f3913934307798d15eb814 # Parent 85dd6a1ab06aa406f54e146891ede70cfd7c5d4b (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData. diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -446,7 +446,7 @@ CommandCost CmdBuildAircraft(TileIndex t } InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); if (IsLocalPlayer()) InvalidateAutoreplaceWindow(v->engine_type, v->group_id); //updates the replace Aircraft window @@ -461,11 +461,10 @@ CommandCost CmdBuildAircraft(TileIndex t static void DoDeleteAircraft(Vehicle *v) { DeleteWindowById(WC_VEHICLE_VIEW, v->index); - RebuildVehicleLists(); InvalidateWindow(WC_COMPANY, v->owner); DeleteDepotHighlightOfVehicle(v); DeleteVehicleChain(v); - InvalidateWindowClasses(WC_AIRCRAFT_LIST); + InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); } /** Sell an aircraft. @@ -656,7 +655,7 @@ CommandCost CmdRefitAircraft(TileIndex t v->cargo_subtype = new_subtype; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); } return cost; diff --git a/src/economy.cpp b/src/economy.cpp --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1781,7 +1781,10 @@ static void DoAcquireCompany(Player *p) p->is_active = false; DeletePlayerWindows(pi); - RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); + InvalidateWindowClassesData(WC_SHIPS_LIST, 0); + InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); + InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); } extern int GetAmountOwnedBy(const Player *p, PlayerID owner); diff --git a/src/group_gui.cpp b/src/group_gui.cpp --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -286,8 +286,8 @@ struct VehicleGroupWindow : public Windo virtual void OnInvalidateData(int data) { - this->vehicles.flags |= VL_REBUILD; - this->groups.flags |= VL_REBUILD; + this->vehicles.flags |= (data == 0 ? VL_REBUILD : VL_RESORT); + this->groups.flags |= (data == 0 ? VL_REBUILD : VL_RESORT); if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) { this->group_sel = ALL_GROUP; HideDropDownMenu(this); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -546,7 +546,7 @@ CommandCost CmdInsertOrder(TileIndex til } /* Make sure to rebuild the whole list */ - RebuildVehicleLists(); + InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); } return CommandCost(); @@ -561,7 +561,7 @@ static CommandCost DecloneOrder(Vehicle if (flags & DC_EXEC) { DeleteVehicleOrders(dst); InvalidateVehicleOrder(dst); - RebuildVehicleLists(); + InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); } return CommandCost(); } @@ -673,7 +673,7 @@ CommandCost CmdDeleteOrder(TileIndex til cur_order_id++; } - RebuildVehicleLists(); + InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); } return CommandCost(); @@ -811,7 +811,7 @@ CommandCost CmdMoveOrder(TileIndex tile, } /* Make sure to rebuild the whole list */ - RebuildVehicleLists(); + InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); } return CommandCost(); @@ -1075,7 +1075,7 @@ CommandCost CmdCloneOrder(TileIndex tile InvalidateVehicleOrder(dst); InvalidateVehicleOrder(src); - RebuildVehicleLists(); + InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); } } break; @@ -1134,7 +1134,7 @@ CommandCost CmdCloneOrder(TileIndex tile InvalidateVehicleOrder(dst); - RebuildVehicleLists(); + InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); } } break; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -280,7 +280,7 @@ CommandCost CmdBuildRoadVeh(TileIndex ti VehiclePositionChanged(v); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); if (IsLocalPlayer()) InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Road window @@ -381,7 +381,7 @@ CommandCost CmdSellRoadVeh(TileIndex til if (flags & DC_EXEC) { // Invalidate depot InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); DeleteWindowById(WC_VEHICLE_VIEW, v->index); DeleteDepotHighlightOfVehicle(v); @@ -574,7 +574,7 @@ static void DeleteLastRoadVeh(Vehicle *v DeleteWindowById(WC_VEHICLE_VIEW, v->index); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v); @@ -2116,7 +2116,7 @@ CommandCost CmdRefitRoadVeh(TileIndex ti v->cargo_subtype = new_subtype; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); } if (only_this) break; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -814,7 +814,7 @@ CommandCost CmdBuildShip(TileIndex tile, VehiclePositionChanged(v); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_SHIPS_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); if (IsLocalPlayer()) InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Ship window @@ -851,7 +851,7 @@ CommandCost CmdSellShip(TileIndex tile, if (flags & DC_EXEC) { InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_SHIPS_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); DeleteWindowById(WC_VEHICLE_VIEW, v->index); DeleteDepotHighlightOfVehicle(v); @@ -997,7 +997,7 @@ CommandCost CmdRefitShip(TileIndex tile, v->cargo_subtype = new_subtype; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_SHIPS_LIST, 0); } return cost; diff --git a/src/station.cpp b/src/station.cpp --- a/src/station.cpp +++ b/src/station.cpp @@ -74,8 +74,7 @@ Station::~Station() } MarkDirty(); - RebuildStationLists(); - InvalidateWindowClasses(WC_STATION_LIST); + InvalidateWindowData(WC_STATION_LIST, this->owner, 0); DeleteWindowById(WC_STATION_VIEW, index); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -650,8 +650,7 @@ static void DeleteStationIfEmpty(Station { if (st->facilities == 0) { st->delete_ctr = 0; - RebuildStationLists(); - InvalidateWindow(WC_STATION_LIST, st->owner); + InvalidateWindowData(WC_STATION_LIST, st->owner, 0); } /* station remains but it probably lost some parts - station sign should stay in the station boundaries */ UpdateStationSignCoord(st); @@ -1051,8 +1050,7 @@ CommandCost CmdBuildRailroadStation(Tile st->MarkTilesDirty(false); UpdateStationVirtCoordDirty(st); UpdateStationAcceptance(st, false); - RebuildStationLists(); - InvalidateWindow(WC_STATION_LIST, st->owner); + InvalidateWindowData(WC_STATION_LIST, st->owner, 0); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS); } @@ -1410,8 +1408,7 @@ CommandCost CmdBuildRoadStop(TileIndex t UpdateStationVirtCoordDirty(st); UpdateStationAcceptance(st, false); - RebuildStationLists(); - InvalidateWindow(WC_STATION_LIST, st->owner); + InvalidateWindowData(WC_STATION_LIST, st->owner, 0); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS); } return cost; @@ -1723,8 +1720,7 @@ CommandCost CmdBuildAirport(TileIndex ti UpdateStationVirtCoordDirty(st); UpdateStationAcceptance(st, false); - RebuildStationLists(); - InvalidateWindow(WC_STATION_LIST, st->owner); + InvalidateWindowData(WC_STATION_LIST, st->owner, 0); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES); } @@ -1820,8 +1816,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, UpdateStationVirtCoordDirty(st); UpdateStationAcceptance(st, false); - RebuildStationLists(); - InvalidateWindow(WC_STATION_LIST, st->owner); + InvalidateWindowData(WC_STATION_LIST, st->owner, 0); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS); } @@ -1979,8 +1974,7 @@ CommandCost CmdBuildDock(TileIndex tile, UpdateStationVirtCoordDirty(st); UpdateStationAcceptance(st, false); - RebuildStationLists(); - InvalidateWindow(WC_STATION_LIST, st->owner); + InvalidateWindowData(WC_STATION_LIST, st->owner, 0); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS); } @@ -2637,7 +2631,7 @@ CommandCost CmdRenameStation(TileIndex t st->name = strdup(_cmd_text); UpdateStationVirtCoord(st); - ResortStationLists(); + InvalidateWindowData(WC_STATION_LIST, st->owner, 1); MarkWholeScreenDirty(); } @@ -2858,8 +2852,7 @@ static void ChangeTileOwner_Station(Tile SetTileOwner(tile, new_player); if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys - RebuildStationLists(); - InvalidateWindowClasses(WC_STATION_LIST); + InvalidateWindowClassesData(WC_STATION_LIST, 0); } else { if (IsDriveThroughStopTile(tile)) { /* Remove the drive-through road stop */ diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -168,39 +168,6 @@ static int CDECL StationRatingMaxSorter( typedef GUIList GUIStationList; /** - * Set the station sort flag for all station-list windows. - * @param sl_flag Sort list flag to set for all station-list windows - */ -static void SetStationListsFlag(SortListFlags sl_flag) -{ - Window *const *wz; - - FOR_ALL_WINDOWS(wz) { - Window *w = *wz; - if (w->window_class == WC_STATION_LIST) { - dynamic_cast(w)->flags |= sl_flag; - w->SetDirty(); - } - } -} - -/** - * Set the 'VL_REBUILD' flag for all station lists - */ -void RebuildStationLists() -{ - SetStationListsFlag(VL_REBUILD); -} - -/** - * Set the 'VL_RESORT' flag for all station lists - */ -void ResortStationLists() -{ - SetStationListsFlag(VL_RESORT); -} - -/** * Rebuild station list if the VL_REBUILD flag is set * * @param sl pointer to plstations_d (station list and flags) @@ -605,6 +572,11 @@ struct PlayerStationsWindow : public Win { this->vscroll.cap += delta.y / 10; } + + virtual void OnInvalidateData(int data) + { + this->flags |= (data == 0 ? VL_REBUILD : VL_RESORT); + } }; Listing PlayerStationsWindow::station_sort = {0, 0}; diff --git a/src/station_gui.h b/src/station_gui.h --- a/src/station_gui.h +++ b/src/station_gui.h @@ -48,10 +48,6 @@ enum StationViewWidgets { SVW_RESIZE, ///< Resize button }; -/* sorter stuff */ -void RebuildStationLists(); -void ResortStationLists(); - enum StationCoverageType { SCT_PASSENGERS_ONLY, SCT_NON_PASSENGERS_ONLY, diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -803,7 +803,7 @@ CommandCost CmdBuildRailVehicle(TileInde } InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); InvalidateWindow(WC_COMPANY, v->owner); if (IsLocalPlayer()) { InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window @@ -1272,7 +1272,7 @@ CommandCost CmdMoveRailVehicle(TileIndex InvalidateWindow(WC_VEHICLE_DEPOT, dst_head->tile); } - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); } return CommandCost(); @@ -1353,7 +1353,7 @@ CommandCost CmdSellRailWagon(TileIndex t DeleteWindowById(WC_VEHICLE_VIEW, first->index); } InvalidateWindow(WC_VEHICLE_DEPOT, first->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); } CommandCost cost(EXPENSES_NEW_VEHICLES); @@ -2001,7 +2001,7 @@ CommandCost CmdRefitRailVehicle(TileInde v->cargo_subtype = new_subtype; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); } } } @@ -2805,7 +2805,7 @@ static void SetVehicleCrashed(Vehicle *v InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); } - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); BEGIN_ENUM_WAGONS(v) v->vehstatus |= VS_CRASHED; @@ -3152,7 +3152,7 @@ static void DeleteLastWagon(Vehicle *v) } } - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); MarkSingleVehicleDirty(v); diff --git a/src/train_gui.cpp b/src/train_gui.cpp --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -18,6 +18,7 @@ #include "order_func.h" #include "engine_func.h" #include "engine_base.h" +#include "window_func.h" #include "table/sprites.h" #include "table/strings.h" @@ -43,7 +44,7 @@ void CcBuildWagon(bool success, TileInde found = GetLastVehicleInChain(found); /* put the new wagon at the end of the loco. */ DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); - RebuildVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); } } diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1733,7 +1733,7 @@ CommandCost CmdNameVehicle(TileIndex til if (flags & DC_EXEC) { free(v->name); v->name = strdup(_cmd_text); - ResortVehicleLists(); + InvalidateWindowClassesData(WC_TRAINS_LIST, 1); MarkWholeScreenDirty(); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -86,47 +86,6 @@ const StringID _vehicle_sort_listing[] = INVALID_STRING_ID }; -/** - * Set sort list flag for all vehicle list windows - * @param sl_flag Sort list flag to set - */ -static void SetVehicleListsFlag(SortListFlags sl_flag) -{ - Window* const *wz; - - FOR_ALL_WINDOWS(wz) { - Window *w = *wz; - - switch (w->window_class) { - case WC_TRAINS_LIST: - case WC_ROADVEH_LIST: - case WC_SHIPS_LIST: - case WC_AIRCRAFT_LIST: - dynamic_cast(w)->vehicles.flags |= sl_flag; - w->SetDirty(); - break; - - default: break; - } - } -} - -/** - * Rebuild all vehicle list windows - */ -void RebuildVehicleLists() -{ - SetVehicleListsFlag(VL_REBUILD); -} - -/** - * Resort all vehicle list windows - */ -void ResortVehicleLists() -{ - SetVehicleListsFlag(VL_RESORT); -} - void BuildVehicleList(VehicleListBase *vl, PlayerID owner, uint16 index, uint16 window_type) { if (!(vl->vehicles.flags & VL_REBUILD)) return; @@ -1187,6 +1146,11 @@ struct VehicleListWindow : public Window this->vscroll.cap += delta.y / (int)this->resize.step_height; this->widget[VLW_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1; } + + virtual void OnInvalidateData(int data) + { + this->vehicles.flags |= (data == 0 ? VL_REBUILD : VL_RESORT); + } }; static const WindowDesc _player_vehicle_list_train_desc = { diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -133,8 +133,6 @@ struct Sorting { extern Sorting _sorting; /* sorter stuff */ -void RebuildVehicleLists(); -void ResortVehicleLists(); void SortVehicleList(VehicleListBase *vl); void BuildVehicleList(VehicleListBase *vl, PlayerID owner, uint16 index, uint16 window_type); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -838,20 +838,21 @@ static void FloodVehicle(Vehicle *v) case VEH_TRAIN: if (IsFrontEngine(v)) pass += 4; // driver v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast + InvalidateWindowClassesData(WC_TRAINS_LIST, 0); break; case VEH_ROAD: if (IsRoadVehFront(v)) pass += 1; // driver v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast + InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); break; case VEH_AIRCRAFT: pass += 2; // driver v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast + InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); break; } - - RebuildVehicleLists(); } else { return; }