changeset 4524:2525c13a281a draft

(svn r6350) -Codechange: moved some setup stuff into WE_CREATE in PlayerVehWndProc() This is possible now that the window number is known when running WE_CREATE and it's a nicer solution
author bjarni <bjarni@openttd.org>
date Sat, 02 Sep 2006 21:16:46 +0000
parents 46380e6da3ae
children 5344892535b8
files aircraft_gui.c roadveh_gui.c ship_gui.c train_gui.c vehicle_gui.c
diffstat 5 files changed, 20 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -1039,11 +1039,6 @@
 	}
 
 	if (w != NULL) {
-		vehiclelist_d *vl = &WP(w, vehiclelist_d);
-		vl->flags = VL_REBUILD | (_sorting.aircraft.order << (VL_DESC - 1));
-		vl->sort_type = _sorting.aircraft.criteria;
-
-		w->caption_color = player;
 		w->vscroll.cap = 4;
 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG;
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -968,11 +968,6 @@
 	}
 
 	if (w != NULL) {
-		vehiclelist_d *vl = &WP(w, vehiclelist_d);
-		vl->flags = VL_REBUILD | (_sorting.roadveh.order << (VL_DESC - 1));
-		vl->sort_type = _sorting.roadveh.criteria;
-
-		w->caption_color = player;
 		w->vscroll.cap = 7; // maximum number of vehicles shown
 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -981,11 +981,6 @@
 	}
 
 	if (w != NULL) {
-		vehiclelist_d *vl = &WP(w, vehiclelist_d);
-		vl->flags = VL_REBUILD | (_sorting.ship.order << (VL_DESC - 1));
-		vl->sort_type = _sorting.ship.criteria;
-
-		w->caption_color = player;
 		w->vscroll.cap = 4;
 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG;
--- a/train_gui.c
+++ b/train_gui.c
@@ -1437,11 +1437,6 @@
 	}
 
 	if (w != NULL) {
-		vehiclelist_d *vl = &WP(w, vehiclelist_d);
-		vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
-		vl->sort_type = _sorting.train.criteria;
-
-		w->caption_color = player;
 		w->hscroll.cap = 10 * 29;
 		w->vscroll.cap = 7; // maximum number of vehicles shown
 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -1362,8 +1362,26 @@
 			break;
 
 		case WE_CREATE:
-			/* IMPORTANT: order and criteria needs to be set after the window is created, but before it's used */
-			/* w->window_number is not yet set at this point, so we lack info on what kind of vehicle we are dealing with */
+			w->caption_color = GB(w->window_number, 0, 8); // OwnerID is stored in the last 8 bits of the window number
+			switch (vehicle_type) {
+				case VEH_Train:
+					vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
+					vl->sort_type = _sorting.train.criteria;
+					break;
+				case VEH_Road:
+					vl->flags = VL_REBUILD | (_sorting.roadveh.order << (VL_DESC - 1));
+					vl->sort_type = _sorting.roadveh.criteria;
+					break;
+				case VEH_Ship:
+					vl->flags = VL_REBUILD | (_sorting.ship.order << (VL_DESC - 1));
+					vl->sort_type = _sorting.ship.criteria;
+					break;
+				case VEH_Aircraft:
+					vl->flags = VL_REBUILD | (_sorting.aircraft.order << (VL_DESC - 1));
+					vl->sort_type = _sorting.aircraft.criteria;
+					break;
+				default: NOT_REACHED(); break;
+			}
 			vl->sort_list = NULL;
 			vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;	// Set up resort timer
 			break;