src/train_gui.cpp
branchNewGRF_ports
changeset 6868 7eb395287b3d
parent 6743 cabfaa4a0295
child 6870 ca3fd1fbe311
--- a/src/train_gui.cpp	Mon Aug 27 16:28:33 2007 +0000
+++ b/src/train_gui.cpp	Sun Sep 02 11:58:58 2007 +0000
@@ -56,12 +56,7 @@
 		_backup_orders_tile = 0;
 		RestoreVehicleOrders(v, _backup_orders_data);
 	}
-	ShowTrainViewWindow(v);
-}
-
-void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2)
-{
-	if (success) ShowTrainViewWindow(GetVehicle(_new_vehicle_id));
+	ShowVehicleViewWindow(v);
 }
 
 /**
@@ -105,7 +100,7 @@
 		}
 		dx += width;
 
-		v = v->next;
+		v = v->Next();
 	} while (dx < count && v != NULL);
 
 	if (highlight_l != highlight_r) {
@@ -117,215 +112,6 @@
 	_cur_dpi = old_dpi;
 }
 
-static const Widget _train_view_widgets[] = {
-{   WWT_CLOSEBOX,  RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },
-{    WWT_CAPTION, RESIZE_RIGHT, 14,  11, 237,   0,  13, STR_882E,                STR_018C_WINDOW_TITLE_DRAG_THIS },
-{  WWT_STICKYBOX,    RESIZE_LR, 14, 238, 249,   0,  13, 0x0,                     STR_STICKY_BUTTON },
-{      WWT_PANEL,    RESIZE_RB, 14,   0, 231,  14, 121, 0x0,                     STR_NULL },
-{      WWT_INSET,    RESIZE_RB, 14,   2, 229,  16, 119, 0x0,                     STR_NULL },
-{    WWT_PUSHBTN,   RESIZE_RTB, 14,   0, 237, 122, 133, 0x0,                     STR_8846_CURRENT_TRAIN_ACTION_CLICK },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  14,  31, SPR_CENTRE_VIEW_VEHICLE, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  32,  49, SPR_SEND_TRAIN_TODEPOT,  STR_8849_SEND_TRAIN_TO_DEPOT },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  50,  67, SPR_IGNORE_SIGNALS,      STR_884A_FORCE_TRAIN_TO_PROCEED },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  68,  85, SPR_FORCE_VEHICLE_TURN,  STR_884B_REVERSE_DIRECTION_OF_TRAIN },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  86, 103, SPR_SHOW_ORDERS,         STR_8847_SHOW_TRAIN_S_ORDERS },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249, 104, 121, SPR_SHOW_VEHICLE_DETAILS,STR_884C_SHOW_TRAIN_DETAILS },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  68,  85, SPR_REFIT_VEHICLE,       STR_RAIL_REFIT_VEHICLE_TO_CARRY },
-{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  32,  49, SPR_CLONE_TRAIN,         STR_CLONE_TRAIN_INFO },
-{      WWT_PANEL,   RESIZE_LRB, 14, 232, 249, 122, 121, 0x0,                     STR_NULL },
-{  WWT_RESIZEBOX,  RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0,                     STR_NULL },
-{ WIDGETS_END }
-};
-
-static void ShowTrainDetailsWindow(const Vehicle *v);
-
-static void TrainViewWndProc(Window *w, WindowEvent *e)
-{
-	switch (e->event) {
-	case WE_PAINT: {
-		const Vehicle *v, *u;
-		StringID str;
-		bool is_localplayer;
-
-		v = GetVehicle(w->window_number);
-
-		is_localplayer = v->owner == _local_player;
-		SetWindowWidgetDisabledState(w,  7, !is_localplayer);
-		SetWindowWidgetDisabledState(w,  8, !is_localplayer);
-		SetWindowWidgetDisabledState(w,  9, !is_localplayer);
-		SetWindowWidgetDisabledState(w, 13, !is_localplayer);
-
-		/* Disable cargo refit button, until we know we can enable it below. */
-		DisableWindowWidget(w, 12);
-
-		if (is_localplayer) {
-			/* See if any vehicle can be refitted */
-			for (u = v; u != NULL; u = u->next) {
-				if (EngInfo(u->engine_type)->refit_mask != 0 ||
-						(RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON && v->cargo_cap != 0)) {
-					EnableWindowWidget(w, 12);
-					/* We have a refittable carriage, bail out */
-					break;
-				}
-			}
-		}
-
-		/* draw widgets & caption */
-		SetDParam(0, v->index);
-		DrawWindowWidgets(w);
-
-		if (v->u.rail.crash_anim_pos != 0) {
-			str = STR_8863_CRASHED;
-		} else if (v->breakdown_ctr == 1) {
-			str = STR_885C_BROKEN_DOWN;
-		} else if (v->vehstatus & VS_STOPPED) {
-			if (v->u.rail.last_speed == 0) {
-				if (v->u.rail.cached_power == 0) {
-					str = STR_TRAIN_NO_POWER;
-				} else {
-					str = STR_8861_STOPPED;
-				}
-			} else {
-				SetDParam(0, v->u.rail.last_speed * 10 / 16);
-				str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
-			}
-		} else {
-			switch (v->current_order.type) {
-			case OT_GOTO_STATION: {
-				str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
-				SetDParam(0, v->current_order.dest);
-				SetDParam(1, v->u.rail.last_speed * 10 / 16);
-			} break;
-
-			case OT_GOTO_DEPOT: {
-				Depot *dep = GetDepot(v->current_order.dest);
-				SetDParam(0, dep->town_index);
-				if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
-					str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed;
-				} else {
-					str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed;
-				}
-				SetDParam(1, v->u.rail.last_speed * 10 / 16);
-			} break;
-
-			case OT_LOADING:
-			case OT_LEAVESTATION:
-				str = STR_882F_LOADING_UNLOADING;
-				break;
-
-			case OT_GOTO_WAYPOINT: {
-				SetDParam(0, v->current_order.dest);
-				str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
-				SetDParam(1, v->u.rail.last_speed * 10 / 16);
-				break;
-			}
-
-			default:
-				if (v->num_orders == 0) {
-					str = STR_NO_ORDERS + _patches.vehicle_speed;
-					SetDParam(0, v->u.rail.last_speed * 10 / 16);
-				} else {
-					str = STR_EMPTY;
-				}
-				break;
-			}
-		}
-
-		/* draw the flag plus orders */
-		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, 2, w->widget[5].top + 1);
-		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
-		DrawWindowViewport(w);
-	} break;
-
-	case WE_CLICK: {
-		int wid = e->we.click.widget;
-		Vehicle *v = GetVehicle(w->window_number);
-
-		switch (wid) {
-		case 5: /* start/stop train */
-			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
-			break;
-		case 6: /* center main view */
-			ScrollMainWindowTo(v->x_pos, v->y_pos);
-			break;
-		case 7: /* goto depot */
-			/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
-			DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_TRAIN_TO_DEPOT | CMD_NO_TEST_IF_IN_NETWORK | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT));
-			break;
-		case 8: /* force proceed */
-			DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
-			break;
-		case 9: /* reverse direction */
-			DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION));
-			break;
-		case 10: /* show train orders */
-			ShowOrdersWindow(v);
-			break;
-		case 11: /* show train details */
-			ShowTrainDetailsWindow(v);
-			break;
-		case 12:
-			ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
-			break;
-		case 13:
-			DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
-			break;
-		}
-	} break;
-
-	case WE_RESIZE:
-		w->viewport->width          += e->we.sizing.diff.x;
-		w->viewport->height         += e->we.sizing.diff.y;
-		w->viewport->virtual_width  += e->we.sizing.diff.x;
-		w->viewport->virtual_height += e->we.sizing.diff.y;
-		break;
-
-	case WE_DESTROY:
-		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
-		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
-		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
-		DeleteWindowById(WC_VEHICLE_TIMETABLE, w->window_number);
-		break;
-
-	case WE_MOUSELOOP: {
-		const Vehicle *v = GetVehicle(w->window_number);
-		bool train_stopped = CheckTrainStoppedInDepot(v)  >= 0;
-
-		/* Widget 7 (send to depot) must be hidden if the train is already stopped in hangar.
-		 * Widget 13 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
-		 * This sytem allows to have two buttons, on top of each other.
-		 * The same system applies to widget 9 and 12, reverse direction and refit*/
-		if (train_stopped != IsWindowWidgetHidden(w, 7) || train_stopped == IsWindowWidgetHidden(w, 13)) {
-			SetWindowWidgetHiddenState(w,  7, train_stopped);  // send to depot
-			SetWindowWidgetHiddenState(w,  9, train_stopped);  // reverse direction
-			SetWindowWidgetHiddenState(w, 12, !train_stopped); // refit
-			SetWindowWidgetHiddenState(w, 13, !train_stopped); // clone
-			SetWindowDirty(w);
-		}
-		break;
-	}
-
-	}
-}
-
-static const WindowDesc _train_view_desc = {
-	WDP_AUTO, WDP_AUTO, 250, 134, 250, 134,
-	WC_VEHICLE_VIEW, WC_NONE,
-	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
-	_train_view_widgets,
-	TrainViewWndProc
-};
-
-void ShowTrainViewWindow(const Vehicle *v)
-{
-	Window *w = AllocateWindowDescFront(&_train_view_desc,v->index);
-
-	if (w != NULL) {
-		w->caption_color = v->owner;
-		AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), ZOOM_LVL_TRAIN);
-	}
-}
-
 static void TrainDetailsCargoTab(const Vehicle *v, int x, int y)
 {
 	if (v->cargo_cap != 0) {
@@ -390,7 +176,7 @@
 		do {
 			act_cargo[u->cargo_type] += u->cargo.Count();
 			max_cargo[u->cargo_type] += u->cargo_cap;
-		} while ((u = u->next) != NULL);
+		} while ((u = u->Next()) != NULL);
 
 		/* Set scroll-amount seperately from counting, as to not compute num double
 		 * for more carriages of the same type
@@ -402,7 +188,7 @@
 	} else {
 		do {
 			if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++;
-		} while ((u = u->next) != NULL);
+		} while ((u = u->Next()) != NULL);
 	}
 
 	SetVScrollCount(w, num);
@@ -423,10 +209,10 @@
 
 	SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
 	SetDParam(2, v->max_age / 366);
-	SetDParam(3, GetTrainRunningCost(v) >> 8);
+	SetDParam(3, v->GetDisplayRunningCost());
 	DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
 
-	SetDParam(2, v->u.rail.cached_max_speed * 10 / 16);
+	SetDParam(2, v->GetDisplayMaxSpeed());
 	SetDParam(1, v->u.rail.cached_power);
 	SetDParam(0, v->u.rail.cached_weight);
 	SetDParam(3, v->u.rail.cached_max_te / 1000);
@@ -463,7 +249,7 @@
 					SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 					DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
 					dx += u->u.rail.cached_veh_length;
-					u = u->next;
+					u = u->Next();
 				} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
 
 				px = x + WagonLengthToPixels(dx) + 2;
@@ -485,7 +271,7 @@
 			} else {
 				/* Move to the next line */
 				do {
-					v = v->next;
+					v = v->Next();
 				} while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0);
 			}
 			if (v == NULL) return;
@@ -600,7 +386,7 @@
 };
 
 
-static void ShowTrainDetailsWindow(const Vehicle *v)
+void ShowTrainDetailsWindow(const Vehicle *v)
 {
 	Window *w;
 	VehicleID veh = v->index;