(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
authorrubidium
Sun, 18 May 2008 16:51:44 +0000
changeset 9297 1cb8d7bbdc8a
parent 9296 b7375d368dc9
child 9298 c758dcefb1f2
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
src/aircraft_cmd.cpp
src/economy.cpp
src/group_gui.cpp
src/order_cmd.cpp
src/roadveh_cmd.cpp
src/ship_cmd.cpp
src/station.cpp
src/station_cmd.cpp
src/station_gui.cpp
src/station_gui.h
src/train_cmd.cpp
src/train_gui.cpp
src/vehicle.cpp
src/vehicle_gui.cpp
src/vehicle_gui.h
src/water_cmd.cpp
--- a/src/aircraft_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/aircraft_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -446,7 +446,7 @@
 		}
 
 		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 @@
 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 @@
 		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;
--- a/src/economy.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/economy.cpp	Sun May 18 16:51:44 2008 +0000
@@ -1781,7 +1781,10 @@
 	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);
--- a/src/group_gui.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/group_gui.cpp	Sun May 18 16:51:44 2008 +0000
@@ -286,8 +286,8 @@
 
 	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);
--- a/src/order_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/order_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -546,7 +546,7 @@
 		}
 
 		/* Make sure to rebuild the whole list */
-		RebuildVehicleLists();
+		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 	}
 
 	return CommandCost();
@@ -561,7 +561,7 @@
 	if (flags & DC_EXEC) {
 		DeleteVehicleOrders(dst);
 		InvalidateVehicleOrder(dst);
-		RebuildVehicleLists();
+		InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 	}
 	return CommandCost();
 }
@@ -673,7 +673,7 @@
 			cur_order_id++;
 		}
 
-		RebuildVehicleLists();
+		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 	}
 
 	return CommandCost();
@@ -811,7 +811,7 @@
 		}
 
 		/* Make sure to rebuild the whole list */
-		RebuildVehicleLists();
+		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 	}
 
 	return CommandCost();
@@ -1075,7 +1075,7 @@
 				InvalidateVehicleOrder(dst);
 				InvalidateVehicleOrder(src);
 
-				RebuildVehicleLists();
+				InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 			}
 		} break;
 
@@ -1134,7 +1134,7 @@
 
 				InvalidateVehicleOrder(dst);
 
-				RebuildVehicleLists();
+				InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 			}
 		} break;
 
--- a/src/roadveh_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/roadveh_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -280,7 +280,7 @@
 		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 @@
 	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 @@
 
 	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 @@
 			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;
--- a/src/ship_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/ship_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -814,7 +814,7 @@
 		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 @@
 
 	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 @@
 		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;
--- a/src/station.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/station.cpp	Sun May 18 16:51:44 2008 +0000
@@ -74,8 +74,7 @@
 	}
 
 	MarkDirty();
-	RebuildStationLists();
-	InvalidateWindowClasses(WC_STATION_LIST);
+	InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
 
 	DeleteWindowById(WC_STATION_VIEW, index);
 
--- a/src/station_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/station_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -650,8 +650,7 @@
 {
 	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 @@
 		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 @@
 
 		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 @@
 
 		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 @@
 
 		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 @@
 
 		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 @@
 		st->name = strdup(_cmd_text);
 
 		UpdateStationVirtCoord(st);
-		ResortStationLists();
+		InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
 		MarkWholeScreenDirty();
 	}
 
@@ -2858,8 +2852,7 @@
 
 		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 */
--- a/src/station_gui.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/station_gui.cpp	Sun May 18 16:51:44 2008 +0000
@@ -168,39 +168,6 @@
 typedef GUIList<const Station*> 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<GUIStationList*>(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 @@
 	{
 		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};
--- a/src/station_gui.h	Sun May 18 14:12:16 2008 +0000
+++ b/src/station_gui.h	Sun May 18 16:51:44 2008 +0000
@@ -48,10 +48,6 @@
 	SVW_RESIZE,          ///< Resize button
 };
 
-/* sorter stuff */
-void RebuildStationLists();
-void ResortStationLists();
-
 enum StationCoverageType {
 	SCT_PASSENGERS_ONLY,
 	SCT_NON_PASSENGERS_ONLY,
--- a/src/train_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/train_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -803,7 +803,7 @@
 			}
 
 			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 @@
 			InvalidateWindow(WC_VEHICLE_DEPOT, dst_head->tile);
 		}
 
-		RebuildVehicleLists();
+		InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
 	}
 
 	return CommandCost();
@@ -1353,7 +1353,7 @@
 			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 @@
 					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 @@
 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 	}
 
-	RebuildVehicleLists();
+	InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
 
 	BEGIN_ENUM_WAGONS(v)
 		v->vehstatus |= VS_CRASHED;
@@ -3152,7 +3152,7 @@
 		}
 	}
 
-	RebuildVehicleLists();
+	InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
 
 	MarkSingleVehicleDirty(v);
 
--- a/src/train_gui.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/train_gui.cpp	Sun May 18 16:51:44 2008 +0000
@@ -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 @@
 		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);
 	}
 }
 
--- a/src/vehicle.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/vehicle.cpp	Sun May 18 16:51:44 2008 +0000
@@ -1733,7 +1733,7 @@
 	if (flags & DC_EXEC) {
 		free(v->name);
 		v->name = strdup(_cmd_text);
-		ResortVehicleLists();
+		InvalidateWindowClassesData(WC_TRAINS_LIST, 1);
 		MarkWholeScreenDirty();
 	}
 
--- a/src/vehicle_gui.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/vehicle_gui.cpp	Sun May 18 16:51:44 2008 +0000
@@ -86,47 +86,6 @@
 	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<VehicleListBase*>(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 @@
 		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 = {
--- a/src/vehicle_gui.h	Sun May 18 14:12:16 2008 +0000
+++ b/src/vehicle_gui.h	Sun May 18 16:51:44 2008 +0000
@@ -133,8 +133,6 @@
 extern Sorting _sorting;
 
 /* sorter stuff */
-void RebuildVehicleLists();
-void ResortVehicleLists();
 void SortVehicleList(VehicleListBase *vl);
 void BuildVehicleList(VehicleListBase *vl, PlayerID owner, uint16 index, uint16 window_type);
 
--- a/src/water_cmd.cpp	Sun May 18 14:12:16 2008 +0000
+++ b/src/water_cmd.cpp	Sun May 18 16:51:44 2008 +0000
@@ -838,20 +838,21 @@
 				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;
 		}