train_gui.c
changeset 867 dffd33233237
parent 842 efc3546bc313
child 877 ce8cb2c09578
equal deleted inserted replaced
866:d242235e6485 867:dffd33233237
    45 }
    45 }
    46 
    46 
    47 void Set_DPARAM_Train_Car_Build_Window(Window *w, uint16 engine_number)
    47 void Set_DPARAM_Train_Car_Build_Window(Window *w, uint16 engine_number)
    48 {
    48 {
    49 	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
    49 	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
    50 	
    50 
    51 	SetDParam(0, DoCommandByTile(w->window_number, engine_number, 0, DC_QUERY_COST, CMD_BUILD_RAIL_VEHICLE) );
    51 	SetDParam(0, DoCommandByTile(w->window_number, engine_number, 0, DC_QUERY_COST, CMD_BUILD_RAIL_VEHICLE) );
    52 	SetDParam(4, rvi->capacity);
    52 	SetDParam(4, rvi->capacity);
    53 	SetDParam(1, rvi->weight);
    53 	SetDParam(1, rvi->weight);
    54 	SetDParam(3, _cargoc.names_long_p[rvi->cargo_type]);
    54 	SetDParam(3, _cargoc.names_long_p[rvi->cargo_type]);
    55 	SetDParam(2, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
    55 	SetDParam(2, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
    97 	}
    97 	}
    98 	ShowTrainViewWindow(v);
    98 	ShowTrainViewWindow(v);
    99 }
    99 }
   100 
   100 
   101 static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
   101 static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
   102 	int *selected_id, byte railtype, bool is_engine)
   102 	int *selected_id, byte railtype, byte show_max, bool is_engine)
   103 {
   103 {
   104 	int i;
   104 	int i;
   105 
   105 
   106 	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
   106 	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
   107 		const Engine *e = DEREF_ENGINE(i);
   107 		const Engine *e = DEREF_ENGINE(i);
   109 
   109 
   110 		if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
   110 		if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
   111 				!HASBIT(e->player_avail, _local_player))
   111 				!HASBIT(e->player_avail, _local_player))
   112 			continue;
   112 			continue;
   113 
   113 
   114 		if (*sel == 0) *selected_id = i;
   114 		if (*sel == 0)
   115 
   115 			*selected_id = i;
   116 		if (IS_INT_INSIDE(--*pos, -8, 0)) {
   116 
   117 			DrawString(*x + 59, *y + 2, GetCustomEngineName(i),
   117 		if (IS_INT_INSIDE(--*pos, -show_max, 0)) {
   118 				*sel == 0 ? 0xC : 0x10);
   118 			DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10);
   119 			DrawTrainEngine(*x + 29, *y + 6 + _traininfo_vehicle_pitch, i,
   119 			DrawTrainEngine(*x + 29, *y + 6 + _traininfo_vehicle_pitch, i,
   120 				SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
   120 				SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
   121 			*y += 14;
   121 			*y += 14;
   122 		}
   122 		}
   123 		--*sel;
   123 		--*sel;
   160 			/* Ensure that custom engines which substituted wagons
   160 			/* Ensure that custom engines which substituted wagons
   161 			 * are sorted correctly.
   161 			 * are sorted correctly.
   162 			 * XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
   162 			 * XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
   163 			 * engines to get more types.. Stays here until we have our own format
   163 			 * engines to get more types.. Stays here until we have our own format
   164 			 * then it is exit!!! */
   164 			 * then it is exit!!! */
   165 			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, true); // True engines
   165 			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, true); // True engines
   166 			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, false); // Feeble wagons
   166 			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, false); // Feeble wagons
   167 
   167 
   168 			WP(w,buildtrain_d).sel_engine = selected_id;
   168 			WP(w,buildtrain_d).sel_engine = selected_id;
   169 
   169 
   170 			if (selected_id != -1) {
   170 			if (selected_id != -1) {
   171 				const RailVehicleInfo *rvi = RailVehInfo(selected_id);
   171 				const RailVehicleInfo *rvi = RailVehInfo(selected_id);
   172 
   172 
   173 				if (!(rvi->flags & RVI_WAGON)) {
   173 				if (!(rvi->flags & RVI_WAGON)) {
   174 					/* it's an engine */
   174 					/* it's an engine */
   175 					Set_DPARAM_Train_Engine_Build_Window(selected_id);
   175 					Set_DPARAM_Train_Engine_Build_Window(selected_id);
   176 
   176 
   177 					DrawString(2, 0x7F, STR_8817_COST_WEIGHT_T_SPEED_POWER, 0);
   177 					DrawString(2, w->widget[4].top + 1, STR_8817_COST_WEIGHT_T_SPEED_POWER, 0);
   178 				} else {
   178 				} else {
   179 					/* it's a wagon */
   179 					/* it's a wagon */
   180 					Set_DPARAM_Train_Car_Build_Window(w, selected_id);
   180 					Set_DPARAM_Train_Car_Build_Window(w, selected_id);
   181 					
   181 
   182 					DrawString(2, 0x7F, STR_8821_COST_WEIGHT_T_T_CAPACITY, 0);
   182 					DrawString(2, w->widget[4].top + 1, STR_8821_COST_WEIGHT_T_T_CAPACITY, 0);
   183 				}
   183 				}
   184 			}
   184 			}
   185 		}
   185 		}
   186 	break;
   186 	break;
   187 
   187 
   188 	case WE_CLICK: {
   188 	case WE_CLICK: {
   189 		switch(e->click.widget) {
   189 		switch(e->click.widget) {
   190 		case 2: {
   190 		case 2: {
   191 			uint i = (e->click.pt.y - 14) / 14;
   191 			uint i = (e->click.pt.y - 14) / 14;
   192 			if (i < 8) {
   192 			if (i < w->vscroll.cap) {
   193 				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
   193 				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
   194 				SetWindowDirty(w);
   194 				SetWindowDirty(w);
   195 			}
   195 			}
   196 		} break;
   196 		} break;
   197 		case 5: {
   197 		case 5: {
   225 			return;
   225 			return;
   226 
   226 
   227 		memcpy(_decode_parameters, b, 32);
   227 		memcpy(_decode_parameters, b, 32);
   228 		DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
   228 		DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
   229 	} break;
   229 	} break;
       
   230 
       
   231 	case WE_RESIZE: {
       
   232 		if (e->sizing.diff.y == 0)
       
   233 			break;
       
   234 
       
   235 		w->vscroll.cap += e->sizing.diff.y / 14;
       
   236 		w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
       
   237 	} break;
   230 	}
   238 	}
   231 }
   239 }
   232 
   240 
   233 static const Widget _new_rail_vehicle_widgets[] = {
   241 static const Widget _new_rail_vehicle_widgets[] = {
   234 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,	STR_018B_CLOSE_WINDOW},
   242 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,									STR_018B_CLOSE_WINDOW},
   235 {    WWT_CAPTION,    14,    11,   227,     0,    13, STR_0315,	STR_018C_WINDOW_TITLE_DRAG_THIS},
   243 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   227,     0,    13, STR_0315,									STR_018C_WINDOW_TITLE_DRAG_THIS},
   236 {     WWT_MATRIX,    14,     0,   216,    14,   125, 0x801,			STR_8843_TRAIN_VEHICLE_SELECTION},
   244 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   216,    14,   125, 0x801,										STR_8843_TRAIN_VEHICLE_SELECTION},
   237 {  WWT_SCROLLBAR,    14,   217,   227,    14,   125, 0x0,				STR_0190_SCROLL_BAR_SCROLLS_LIST},
   245 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   217,   227,    14,   125, 0x0,											STR_0190_SCROLL_BAR_SCROLLS_LIST},
   238 {      WWT_PANEL,    14,     0,   227,   126,   187, 0x0,				STR_NULL},
   246 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   187, 0x0,											STR_NULL},
   239 { WWT_PUSHTXTBTN,    14,     0,   113,   188,   199, STR_881F_BUILD_VEHICLE,	STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN},
   247 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   107,   188,   199, STR_881F_BUILD_VEHICLE,		STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN},
   240 { WWT_PUSHTXTBTN,    14,   114,   227,   188,   199, STR_8820_RENAME,					STR_8845_RENAME_TRAIN_VEHICLE_TYPE},
   248 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   108,   215,   188,   199, STR_8820_RENAME,					STR_8845_RENAME_TRAIN_VEHICLE_TYPE},
       
   249 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   217,   227,   188,   199, 0x0,											STR_RESIZE_BUTTON},
   241 {   WIDGETS_END},
   250 {   WIDGETS_END},
   242 };
   251 };
   243 
   252 
   244 static const WindowDesc _new_rail_vehicle_desc = {
   253 static const WindowDesc _new_rail_vehicle_desc = {
   245 	-1, -1, 228, 200,
   254 	-1, -1, 228, 200,
   246 	WC_BUILD_VEHICLE,0,
   255 	WC_BUILD_VEHICLE,0,
   247 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   256 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
   248 	_new_rail_vehicle_widgets,
   257 	_new_rail_vehicle_widgets,
   249 	NewRailVehicleWndProc
   258 	NewRailVehicleWndProc
   250 };
   259 };
   251 
   260 
   252 static void ShowBuildTrainWindow(uint tile)
   261 static void ShowBuildTrainWindow(uint tile)
   256 	DeleteWindowById(WC_BUILD_VEHICLE, tile);
   265 	DeleteWindowById(WC_BUILD_VEHICLE, tile);
   257 
   266 
   258 	w = AllocateWindowDesc(&_new_rail_vehicle_desc);
   267 	w = AllocateWindowDesc(&_new_rail_vehicle_desc);
   259 	w->window_number = tile;
   268 	w->window_number = tile;
   260 	w->vscroll.cap = 8;
   269 	w->vscroll.cap = 8;
       
   270 	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
       
   271 
       
   272 	w->resize.step_height = 14;
       
   273 	w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
   261 
   274 
   262 	if (tile != 0) {
   275 	if (tile != 0) {
   263 		w->caption_color = _map_owner[tile];
   276 		w->caption_color = _map_owner[tile];
   264 		WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
   277 		WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
   265 	} else {
   278 	} else {
   294 	Depot *d;
   307 	Depot *d;
   295 
   308 
   296 	tile = w->window_number;
   309 	tile = w->window_number;
   297 
   310 
   298 	/* setup disabled buttons */
   311 	/* setup disabled buttons */
   299 	w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<5)|(1<<7));
   312 	w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<5)|(1<<6)|(1<<8));
   300 
   313 
   301 	/* determine amount of items for scroller */
   314 	/* determine amount of items for scroller */
   302 	num = 1;
   315 	num = 0;
   303 	hnum = 0;
   316 	hnum = 1;
   304 	FOR_ALL_VEHICLES(v) {
   317 	FOR_ALL_VEHICLES(v) {
   305 		if (v->type == VEH_Train &&
   318 		if (v->type == VEH_Train &&
   306 				  (v->subtype == 0 || v->subtype == 4) &&
   319 				  (v->subtype == 0 || v->subtype == 4) &&
   307 				v->tile == (TileIndex)tile &&
   320 				v->tile == (TileIndex)tile &&
   308 				v->u.rail.track == 0x80) {
   321 				v->u.rail.track == 0x80) {
   309 					num++;
   322 					num++;
   310 					// determine number of items in the X direction.
   323 					// determine number of items in the X direction.
   311 					if (v->subtype == 0) {
   324 					if (v->subtype == 0) {
   312 						i = -1;
   325 						i = 0;
   313 						u = v;
   326 						u = v;
   314 						do i++; while ( (u=u->next) != NULL);
   327 						do i++; while ( (u=u->next) != NULL);
   315 						if (i > hnum) hnum = i;
   328 						if (i > hnum) hnum = i;
   316 					}
   329 					}
   317 		}
   330 		}
   320 	SetHScrollCount(w, hnum);
   333 	SetHScrollCount(w, hnum);
   321 
   334 
   322 	/* locate the depot struct */
   335 	/* locate the depot struct */
   323 	for(d=_depots; d->xy != (TileIndex)tile; d++) {}
   336 	for(d=_depots; d->xy != (TileIndex)tile; d++) {}
   324 
   337 
   325 	SetDParam(0,d->town_index);
   338 	SetDParam(0, d->town_index);
   326 	DrawWindowWidgets(w);
   339 	DrawWindowWidgets(w);
   327 
   340 
   328 	x = 2;
   341 	x = 2;
   329 	y = 15;
   342 	y = 15;
   330 	num = w->vscroll.pos;
   343 	num = w->vscroll.pos;
   333 	FOR_ALL_VEHICLES(v) {
   346 	FOR_ALL_VEHICLES(v) {
   334 		if (v->type == VEH_Train &&
   347 		if (v->type == VEH_Train &&
   335 				v->subtype == 0 &&
   348 				v->subtype == 0 &&
   336 				v->tile == (TileIndex)tile &&
   349 				v->tile == (TileIndex)tile &&
   337 				v->u.rail.track == 0x80 &&
   350 				v->u.rail.track == 0x80 &&
   338 				--num < 0 && num >= -6) {
   351 				--num < 0 && num >= -w->vscroll.cap) {
   339 
   352 
   340 			DrawTrainImage(v, x+21, y, 10, w->hscroll.pos, WP(w,traindepot_d).sel);
   353 			DrawTrainImage(v, x+21, y, w->hscroll.cap, w->hscroll.pos, WP(w,traindepot_d).sel);
   341 			/* Draw the train number */
   354 			/* Draw the train number */
   342 			SetDParam(0, v->unitnumber);
   355 			SetDParam(0, v->unitnumber);
   343 			DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0);
   356 			DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0);
   344 			/* Draw the pretty flag */
   357 			/* Draw the pretty flag */
   345 			DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y);
   358 			DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y);
   352 	FOR_ALL_VEHICLES(v) {
   365 	FOR_ALL_VEHICLES(v) {
   353 		if (v->type == VEH_Train &&
   366 		if (v->type == VEH_Train &&
   354 				v->subtype == 4 &&
   367 				v->subtype == 4 &&
   355 				v->tile == (TileIndex)tile &&
   368 				v->tile == (TileIndex)tile &&
   356 				v->u.rail.track == 0x80 &&
   369 				v->u.rail.track == 0x80 &&
   357 				--num < 0 && num >= -6) {
   370 				--num < 0 && num >= -w->vscroll.cap) {
   358 
   371 
   359 			DrawTrainImage(v, x+50, y, 9, 0, WP(w,traindepot_d).sel);
   372 			DrawTrainImage(v, x+50, y, w->hscroll.cap - 1, 0, WP(w,traindepot_d).sel);
   360 			DrawString(x, y+2, STR_8816, 0);
   373 			DrawString(x, y+2, STR_8816, 0);
   361 			y += 14;
   374 			y += 14;
   362 		}
   375 		}
   363 	}
   376 	}
   364 }
   377 }
   502 		DrawTrainDepotWindow(w);
   515 		DrawTrainDepotWindow(w);
   503 		break;
   516 		break;
   504 
   517 
   505 	case WE_CLICK: {
   518 	case WE_CLICK: {
   506 		switch(e->click.widget) {
   519 		switch(e->click.widget) {
   507 		case 7:
   520 		case 8:
   508 			ShowBuildTrainWindow(w->window_number);
   521 			ShowBuildTrainWindow(w->window_number);
   509 			break;
   522 			break;
   510 		case 8:
   523 		case 9:
   511 			ScrollMainWindowToTile(w->window_number);
   524 			ScrollMainWindowToTile(w->window_number);
   512 			break;
   525 			break;
   513 		case 3:
   526 		case 3:
   514 			TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y);
   527 			TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y);
   515 			break;
   528 			break;
   520 		DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
   533 		DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
   521 		break;
   534 		break;
   522 
   535 
   523 	case WE_DRAGDROP: {
   536 	case WE_DRAGDROP: {
   524 		switch(e->click.widget) {
   537 		switch(e->click.widget) {
   525 		case 4:
   538 		case 5:
   526 		case 5: {
   539 		case 6: {
   527 			Vehicle *v;
   540 			Vehicle *v;
   528 			int sell_cmd;
   541 			int sell_cmd;
   529 
   542 
   530 			/* sell vehicle */
   543 			/* sell vehicle */
   531 			if (w->disabled_state & (1 << e->click.widget))
   544 			if (w->disabled_state & (1 << e->click.widget))
   539 			WP(w,traindepot_d).sel = INVALID_VEHICLE;
   552 			WP(w,traindepot_d).sel = INVALID_VEHICLE;
   540 			SetWindowDirty(w);
   553 			SetWindowDirty(w);
   541 
   554 
   542 			HandleButtonClick(w, e->click.widget);
   555 			HandleButtonClick(w, e->click.widget);
   543 
   556 
   544 			sell_cmd = (e->click.widget == 5 || _ctrl_pressed) ? 1 : 0;
   557 			sell_cmd = (e->click.widget == 6 || _ctrl_pressed) ? 1 : 0;
   545 
   558 
   546 			if (v->subtype != 0) {
   559 			if (v->subtype != 0) {
   547 				DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE));
   560 				DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE));
   548 			} else {
   561 			} else {
   549 				_backup_orders_tile = v->tile;
   562 				_backup_orders_tile = v->tile;
   574 			WP(w,traindepot_d).sel = INVALID_VEHICLE;
   587 			WP(w,traindepot_d).sel = INVALID_VEHICLE;
   575 			SetWindowDirty(w);
   588 			SetWindowDirty(w);
   576 			break;
   589 			break;
   577 		}
   590 		}
   578 		} break;
   591 		} break;
   579 	}
   592 	case WE_RESIZE: {
   580 }
   593 		/* Update the scroll + matrix */
   581 
   594 		w->vscroll.cap += e->sizing.diff.y / 14;
       
   595 		w->hscroll.cap += e->sizing.diff.x / 29;
       
   596 		w->widget[3].unkA = (w->vscroll.cap << 8) + 1;
       
   597 	} break;
       
   598 	}
       
   599 }
   582 
   600 
   583 static const Widget _train_depot_widgets[] = {
   601 static const Widget _train_depot_widgets[] = {
   584 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
   602 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
   585 {    WWT_CAPTION,    14,    11,   336,     0,    13, STR_8800_TRAIN_DEPOT,	STR_018C_WINDOW_TITLE_DRAG_THIS},
   603 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   336,     0,    13, STR_8800_TRAIN_DEPOT,	STR_018C_WINDOW_TITLE_DRAG_THIS},
   586 {  WWT_STICKYBOX,    14,   337,   348,     0,    13, 0x0,                   STR_STICKY_BUTTON},
   604 {  WWT_STICKYBOX,     RESIZE_LR,    14,   337,   348,     0,    13, 0x0,                   STR_STICKY_BUTTON},
   587 {     WWT_MATRIX,    14,     0,   313,    14,    97, 0x601,									STR_883F_TRAINS_CLICK_ON_TRAIN_FOR},
   605 {     WWT_MATRIX,     RESIZE_RB,    14,     0,   313,    14,    97, 0x601,									STR_883F_TRAINS_CLICK_ON_TRAIN_FOR},
   588 {      WWT_PANEL,    14,   314,   337,    14,    54, 0x2A9,									STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE},
   606 {      WWT_PANEL,    RESIZE_LRB,    14,   314,   337,    14,    13, 0x0,										STR_NULL},
   589 {      WWT_PANEL,    14,   314,   337,    55,   108, 0x2BF,									STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP},
   607 {      WWT_PANEL,   RESIZE_LRTB,    14,   314,   337,    14,    54, 0x2A9,									STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE},
   590 
   608 {      WWT_PANEL,   RESIZE_LRTB,    14,   314,   337,    55,   108, 0x2BF,									STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP},
   591 {  WWT_SCROLLBAR,    14,   338,   348,    14,   108, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
   609 
   592 { WWT_PUSHTXTBTN,    14,     0,   173,    109,  120, STR_8815_NEW_VEHICLES,	STR_8840_BUILD_NEW_TRAIN_VEHICLE},
   610 {  WWT_SCROLLBAR,    RESIZE_LRB,    14,   338,   348,    14,   108, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
   593 { WWT_PUSHTXTBTN,    14,   174,   348,    109,  120, STR_00E4_LOCATION,			STR_8842_CENTER_MAIN_VIEW_ON_TRAIN},
   611 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   167,   109,   120, STR_8815_NEW_VEHICLES,	STR_8840_BUILD_NEW_TRAIN_VEHICLE},
   594 { WWT_HSCROLLBAR,    14,     0,   313,    98,   108, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
   612 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   168,   336,   109,   120, STR_00E4_LOCATION,			STR_8842_CENTER_MAIN_VIEW_ON_TRAIN},
       
   613 { WWT_HSCROLLBAR,    RESIZE_RTB,    14,     0,   313,    98,   108, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
   614 {      WWT_PANEL,    RESIZE_RTB,    14,   337,   336,   109,   120, 0x0,										STR_NULL},
       
   615 {  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   338,   348,   109,   120, 0x0,										STR_RESIZE_BUTTON},
   595 {   WIDGETS_END},
   616 {   WIDGETS_END},
   596 };
   617 };
   597 
   618 
   598 static const WindowDesc _train_depot_desc = {
   619 static const WindowDesc _train_depot_desc = {
   599 	-1, -1, 349, 121,
   620 	-1, -1, 349, 121,
   600 	WC_VEHICLE_DEPOT,0,
   621 	WC_VEHICLE_DEPOT,0,
   601 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   622 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   602 	_train_depot_widgets,
   623 	_train_depot_widgets,
   603 	TrainDepotWndProc
   624 	TrainDepotWndProc
   604 };
   625 };
   605 
   626 
   606 
   627 
   610 
   631 
   611 	w = AllocateWindowDescFront(&_train_depot_desc, tile);
   632 	w = AllocateWindowDescFront(&_train_depot_desc, tile);
   612 	if (w) {
   633 	if (w) {
   613 		w->caption_color = _map_owner[w->window_number];
   634 		w->caption_color = _map_owner[w->window_number];
   614 		w->vscroll.cap = 6;
   635 		w->vscroll.cap = 6;
   615 		w->hscroll.cap = 9;
   636 		w->hscroll.cap = 10;
       
   637 		w->resize.step_width = 29;
       
   638 		w->resize.step_height = 14;
   616 		WP(w,traindepot_d).sel = INVALID_VEHICLE;
   639 		WP(w,traindepot_d).sel = INVALID_VEHICLE;
   617 		_backup_orders_tile = 0;
   640 		_backup_orders_tile = 0;
   618 	}
   641 	}
   619 }
   642 }
   620 
   643 
   715 	}
   738 	}
   716 }
   739 }
   717 
   740 
   718 
   741 
   719 static const Widget _rail_vehicle_refit_widgets[] = {
   742 static const Widget _rail_vehicle_refit_widgets[] = {
   720 {    WWT_TEXTBTN,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
   743 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
   721 {    WWT_CAPTION,    14,    11,   239,     0,    13, STR_983B_REFIT,				STR_018C_WINDOW_TITLE_DRAG_THIS},
   744 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   239,     0,    13, STR_983B_REFIT,				STR_018C_WINDOW_TITLE_DRAG_THIS},
   722 {     WWT_IMGBTN,    14,     0,   239,    14,   135, 0x0,										STR_RAIL_SELECT_TYPE_OF_CARGO_FOR},
   745 {     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   239,    14,   135, 0x0,										STR_RAIL_SELECT_TYPE_OF_CARGO_FOR},
   723 {     WWT_IMGBTN,    14,     0,   239,   136,   157, 0x0,										STR_NULL},
   746 {     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   239,   136,   157, 0x0,										STR_NULL},
   724 { WWT_PUSHTXTBTN,    14,     0,   239,   158,   169, STR_RAIL_REFIT_VEHICLE,STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED},
   747 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   239,   158,   169, STR_RAIL_REFIT_VEHICLE,STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED},
   725 {   WIDGETS_END},
   748 {   WIDGETS_END},
   726 };
   749 };
   727 
   750 
   728 static const WindowDesc _rail_vehicle_refit_desc = {
   751 static const WindowDesc _rail_vehicle_refit_desc = {
   729 	-1,-1, 240, 170,
   752 	-1,-1, 240, 170,
   743 	w->caption_color = v->owner;
   766 	w->caption_color = v->owner;
   744 	WP(w,refit_d).sel = -1;
   767 	WP(w,refit_d).sel = -1;
   745 }
   768 }
   746 
   769 
   747 static Widget _train_view_widgets[] = {
   770 static Widget _train_view_widgets[] = {
   748 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,STR_018B_CLOSE_WINDOW},
   771 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,STR_018B_CLOSE_WINDOW},
   749 {    WWT_CAPTION,    14,    11,   237,     0,    13, STR_882E,STR_018C_WINDOW_TITLE_DRAG_THIS},
   772 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   237,     0,    13, STR_882E,STR_018C_WINDOW_TITLE_DRAG_THIS},
   750 {  WWT_STICKYBOX,    14,   238,   249,     0,    13, 0x0,     STR_STICKY_BUTTON},
   773 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   238,   249,     0,    13, 0x0,     STR_STICKY_BUTTON},
   751 {      WWT_PANEL,    14,     0,   231,    14,   121, 0x0,			STR_NULL},
   774 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   231,    14,   121, 0x0,			STR_NULL},
   752 {          WWT_6,    14,     2,   229,    16,   119, 0x0,			STR_NULL},
   775 {          WWT_6,   RESIZE_NONE,    14,     2,   229,    16,   119, 0x0,			STR_NULL},
   753 { WWT_PUSHIMGBTN,    14,     0,   249,   122,   133, 0x0,			STR_8846_CURRENT_TRAIN_ACTION_CLICK},
   776 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,     0,   249,   122,   133, 0x0,			STR_8846_CURRENT_TRAIN_ACTION_CLICK},
   754 { WWT_PUSHIMGBTN,    14,   232,   249,    14,    31, 0x2AB,		STR_8848_CENTER_MAIN_VIEW_ON_TRAIN},
   777 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,    14,    31, 0x2AB,		STR_8848_CENTER_MAIN_VIEW_ON_TRAIN},
   755 { WWT_PUSHIMGBTN,    14,   232,   249,    32,    49, 0x2AD,		STR_8849_SEND_TRAIN_TO_DEPOT},
   778 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,    32,    49, 0x2AD,		STR_8849_SEND_TRAIN_TO_DEPOT},
   756 { WWT_PUSHIMGBTN,    14,   232,   249,    50,    67, 0x2B1,		STR_884A_FORCE_TRAIN_TO_PROCEED},
   779 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,    50,    67, 0x2B1,		STR_884A_FORCE_TRAIN_TO_PROCEED},
   757 { WWT_PUSHIMGBTN,    14,   232,   249,    68,    85, 0x2CB,		STR_884B_REVERSE_DIRECTION_OF_TRAIN},
   780 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,    68,    85, 0x2CB,		STR_884B_REVERSE_DIRECTION_OF_TRAIN},
   758 { WWT_PUSHIMGBTN,    14,   232,   249,    86,   103, 0x2B2,		STR_8847_SHOW_TRAIN_S_ORDERS},
   781 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,    86,   103, 0x2B2,		STR_8847_SHOW_TRAIN_S_ORDERS},
   759 { WWT_PUSHIMGBTN,    14,   232,   249,   104,   121, 0x2B3,		STR_884C_SHOW_TRAIN_DETAILS},
   782 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,   104,   121, 0x2B3,		STR_884C_SHOW_TRAIN_DETAILS},
   760 { WWT_PUSHIMGBTN,    14,   232,   249,    68,    85, 0x2B4,		STR_RAIL_REFIT_VEHICLE_TO_CARRY},
   783 { WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   232,   249,    68,    85, 0x2B4,		STR_RAIL_REFIT_VEHICLE_TO_CARRY},
   761 {   WIDGETS_END},
   784 {   WIDGETS_END},
   762 };
   785 };
   763 
   786 
   764 static void TrainViewWndProc(Window *w, WindowEvent *e)
   787 static void TrainViewWndProc(Window *w, WindowEvent *e)
   765 {
   788 {
  1137 	} break;
  1160 	} break;
  1138 	}
  1161 	}
  1139 }
  1162 }
  1140 
  1163 
  1141 static const Widget _train_details_widgets[] = {
  1164 static const Widget _train_details_widgets[] = {
  1142 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,				STR_018B_CLOSE_WINDOW},
  1165 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,				STR_018B_CLOSE_WINDOW},
  1143 {    WWT_CAPTION,    14,    11,   329,     0,    13, STR_8802_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS},
  1166 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   329,     0,    13, STR_8802_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS},
  1144 { WWT_PUSHTXTBTN,    14,   330,   369,     0,    13, STR_01AA_NAME,		STR_8867_NAME_TRAIN},
  1167 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   330,   369,     0,    13, STR_01AA_NAME,		STR_8867_NAME_TRAIN},
  1145 {      WWT_PANEL,    14,     0,   369,    14,    55, 0x0,							STR_NULL},
  1168 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   369,    14,    55, 0x0,							STR_NULL},
  1146 {     WWT_MATRIX,    14,     0,   358,    56,   139, 0x601,						STR_NULL},
  1169 {     WWT_MATRIX,   RESIZE_NONE,    14,     0,   358,    56,   139, 0x601,						STR_NULL},
  1147 {  WWT_SCROLLBAR,    14,   359,   369,    56,   139, 0x0,							STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1170 {  WWT_SCROLLBAR,   RESIZE_NONE,    14,   359,   369,    56,   139, 0x0,							STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1148 { WWT_PUSHTXTBTN,    14,     0,    10,   140,   145, STR_0188,				STR_884D_INCREASE_SERVICING_INTERVAL},
  1171 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   140,   145, STR_0188,				STR_884D_INCREASE_SERVICING_INTERVAL},
  1149 { WWT_PUSHTXTBTN,    14,     0,    10,   146,   151, STR_0189,				STR_884E_DECREASE_SERVICING_INTERVAL},
  1172 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   146,   151, STR_0189,				STR_884E_DECREASE_SERVICING_INTERVAL},
  1150 {      WWT_PANEL,    14,    11,   369,   140,   151, 0x0,							STR_NULL},
  1173 {      WWT_PANEL,   RESIZE_NONE,    14,    11,   369,   140,   151, 0x0,							STR_NULL},
  1151 { WWT_PUSHTXTBTN,    14,     0,    92,   152,   163, STR_013C_CARGO,	STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
  1174 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    92,   152,   163, STR_013C_CARGO,	STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
  1152 { WWT_PUSHTXTBTN,    14,    93,   184,   152,   163, STR_013D_INFORMATION,	STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
  1175 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    93,   184,   152,   163, STR_013D_INFORMATION,	STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
  1153 { WWT_PUSHTXTBTN,    14,   185,   277,   152,   163, STR_013E_CAPACITIES,		STR_8851_SHOW_CAPACITIES_OF_EACH},
  1176 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   185,   277,   152,   163, STR_013E_CAPACITIES,		STR_8851_SHOW_CAPACITIES_OF_EACH},
  1154 { WWT_PUSHTXTBTN,    14,   278,   369,   152,   163, STR_013E_TOTAL_CARGO,	STR_8852_SHOW_TOTAL_CARGO},
  1177 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   278,   369,   152,   163, STR_013E_TOTAL_CARGO,	STR_8852_SHOW_TOTAL_CARGO},
  1155 {   WIDGETS_END},
  1178 {   WIDGETS_END},
  1156 };
  1179 };
  1157 
  1180 
  1158 
  1181 
  1159 static const WindowDesc _train_details_desc = {
  1182 static const WindowDesc _train_details_desc = {
  1180 	w->caption_color = v->owner;
  1203 	w->caption_color = v->owner;
  1181 	w->vscroll.cap = 6;
  1204 	w->vscroll.cap = 6;
  1182 	WP(w,traindetails_d).tab = 0;
  1205 	WP(w,traindetails_d).tab = 0;
  1183 }
  1206 }
  1184 
  1207 
  1185 
  1208 static const Widget _player_trains_widgets[] = {
  1186 static Widget _player_trains_widgets[] = {
  1209 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
  1187 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
  1210 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   312,     0,    13, STR_881B_TRAINS,				STR_018C_WINDOW_TITLE_DRAG_THIS},
  1188 {    WWT_CAPTION,    14,    11,   312,     0,    13, STR_881B_TRAINS,				STR_018C_WINDOW_TITLE_DRAG_THIS},
  1211 {  WWT_STICKYBOX,     RESIZE_LR,    14,   313,   324,     0,    13, 0x0,										STR_STICKY_BUTTON},
  1189 {  WWT_STICKYBOX,    14,   313,   324,     0,    13, 0x0,                   STR_STICKY_BUTTON},
  1212 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, SRT_SORT_BY,						STR_SORT_ORDER_TIP},
  1190 { WWT_PUSHTXTBTN,    14,     0,    80,    14,    25, SRT_SORT_BY,           STR_SORT_ORDER_TIP},
  1213 {      WWT_PANEL,   RESIZE_NONE,    14,    81,   232,    14,    25, 0x0,										STR_SORT_CRITERIA_TIP},
  1191 {      WWT_PANEL,    14,    81,   232,    14,    25, 0x0,			              STR_SORT_CRITERIA_TIP},
  1214 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,   233,   243,    14,    25, STR_0225,							STR_SORT_CRITERIA_TIP},
  1192 {   WWT_CLOSEBOX,    14,   233,   243,    14,    25, STR_0225,              STR_SORT_CRITERIA_TIP},
  1215 {      WWT_PANEL,  RESIZE_RIGHT,    14,   244,   324,    14,    25, 0x0,										STR_NULL},
  1193 {      WWT_PANEL,    14,   244,   324,    14,    25, 0x0,										STR_NULL},
  1216 {     WWT_MATRIX,     RESIZE_RB,    14,     0,   313,    26,   207, 0x701,									STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
  1194 {     WWT_MATRIX,    14,     0,   313,    26,   207, 0x701,									STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
  1217 {  WWT_SCROLLBAR,    RESIZE_LRB,    14,   314,   324,    26,   207, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1195 {  WWT_SCROLLBAR,    14,   314,   324,    26,   207, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1218 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   156,   208,   219, STR_8815_NEW_VEHICLES,	STR_883E_BUILD_NEW_TRAINS_REQUIRES},
  1196 { WWT_PUSHTXTBTN,    14,     0,   161,   208,   219, STR_8815_NEW_VEHICLES,	STR_883E_BUILD_NEW_TRAINS_REQUIRES},
  1219 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   157,   313,   208,   219, STR_REPLACE_VEHICLES,    STR_REPLACE_HELP},
  1197 { WWT_PUSHTXTBTN,    14,   162,   324,   208,   219, STR_REPLACE_VEHICLES,					STR_REPLACE_HELP},
  1220 {      WWT_PANEL,    RESIZE_RTB,    14,   314,   313,   208,   219, 0x0,										STR_NULL},
       
  1221 {  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   314,   324,   208,   219, 0x0,										STR_RESIZE_BUTTON},
  1198 {   WIDGETS_END},
  1222 {   WIDGETS_END},
  1199 };
  1223 };
  1200 
  1224 
  1201 static Widget _other_player_trains_widgets[] = {
  1225 static const Widget _other_player_trains_widgets[] = {
  1202 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
  1226 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
  1203 {    WWT_CAPTION,    14,    11,   312,     0,    13, STR_881B_TRAINS,				STR_018C_WINDOW_TITLE_DRAG_THIS},
  1227 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   312,     0,    13, STR_881B_TRAINS,				STR_018C_WINDOW_TITLE_DRAG_THIS},
  1204 {  WWT_STICKYBOX,    14,   313,   324,     0,    13, 0x0,                   STR_STICKY_BUTTON},
  1228 {  WWT_STICKYBOX,     RESIZE_LR,    14,   313,   324,     0,    13, 0x0,										STR_STICKY_BUTTON},
  1205 { WWT_PUSHTXTBTN,    14,     0,    80,    14,    25, SRT_SORT_BY,           STR_SORT_ORDER_TIP},
  1229 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, SRT_SORT_BY,						STR_SORT_ORDER_TIP},
  1206 {      WWT_PANEL,    14,    81,   232,    14,    25, 0x0,										STR_SORT_CRITERIA_TIP},
  1230 {      WWT_PANEL,   RESIZE_NONE,    14,    81,   232,    14,    25, 0x0,										STR_SORT_CRITERIA_TIP},
  1207 {   WWT_CLOSEBOX,    14,   233,   243,    14,    25, STR_0225,              STR_SORT_CRITERIA_TIP},
  1231 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,   233,   243,    14,    25, STR_0225,							STR_SORT_CRITERIA_TIP},
  1208 {      WWT_PANEL,    14,   244,   324,    14,    25, 0x0,										STR_NULL},
  1232 {      WWT_PANEL,  RESIZE_RIGHT,    14,   244,   324,    14,    25, 0x0,										STR_NULL},
  1209 {     WWT_MATRIX,    14,     0,   313,    26,   207, 0x701,									STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
  1233 {     WWT_MATRIX,     RESIZE_RB,    14,     0,   313,    26,   207, 0x701,									STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
  1210 {  WWT_SCROLLBAR,    14,   314,   324,    26,   207, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1234 {  WWT_SCROLLBAR,    RESIZE_LRB,    14,   314,   324,    26,   207, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
  1235 {      WWT_PANEL,     RESIZE_TB,    14,     0,   312,   208,   219, 0x0,										STR_NULL},
       
  1236 {  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   314,   324,   208,   219, 0x0,										STR_RESIZE_BUTTON},
  1211 {   WIDGETS_END},
  1237 {   WIDGETS_END},
  1212 };
  1238 };
  1213 
  1239 
  1214 static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
  1240 static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
  1215 {
  1241 {
  1234 			w->disabled_state |= (1 << 3);
  1260 			w->disabled_state |= (1 << 3);
  1235 
  1261 
  1236 		/* draw the widgets */
  1262 		/* draw the widgets */
  1237 		{
  1263 		{
  1238 			const Player *p = DEREF_PLAYER(owner);
  1264 			const Player *p = DEREF_PLAYER(owner);
  1239 			/* XXX hack */
       
  1240 			if (station == -1) {
  1265 			if (station == -1) {
  1241 				/* Company Name -- (###) Trains */
  1266 				/* Company Name -- (###) Trains */
  1242 				SetDParam(0, p->name_1);
  1267 				SetDParam(0, p->name_1);
  1243 				SetDParam(1, p->name_2);
  1268 				SetDParam(1, p->name_2);
  1244 				SetDParam(2, w->vscroll.count);
  1269 				SetDParam(2, w->vscroll.count);
  1245 				_player_trains_widgets[1].unkA = STR_881B_TRAINS;
  1270 				w->widget[1].unkA = STR_881B_TRAINS;
  1246 				_other_player_trains_widgets[1].unkA = STR_881B_TRAINS;
       
  1247 			} else {
  1271 			} else {
  1248 				/* Station Name -- (###) Trains */
  1272 				/* Station Name -- (###) Trains */
  1249 				SetDParam(0, DEREF_STATION(station)->index);
  1273 				SetDParam(0, DEREF_STATION(station)->index);
  1250 				SetDParam(1, w->vscroll.count);
  1274 				SetDParam(1, w->vscroll.count);
  1251 				_player_trains_widgets[1].unkA = STR_SCHEDULED_TRAINS;
  1275 				w->widget[1].unkA = STR_SCHEDULED_TRAINS;
  1252 				_other_player_trains_widgets[1].unkA = STR_SCHEDULED_TRAINS;
       
  1253 			}
  1276 			}
  1254 			DrawWindowWidgets(w);
  1277 			DrawWindowWidgets(w);
  1255 		}
  1278 		}
  1256 		/* draw sorting criteria string */
  1279 		/* draw sorting criteria string */
  1257 		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
  1280 		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
  1265 			StringID str;
  1288 			StringID str;
  1266 
  1289 
  1267 			assert(v->type == VEH_Train && v->owner == owner);
  1290 			assert(v->type == VEH_Train && v->owner == owner);
  1268 
  1291 
  1269 			DrawTrainImage(
  1292 			DrawTrainImage(
  1270 				v, x + 21, y + 6 + _traininfo_vehicle_pitch, 10, 0, INVALID_VEHICLE);
  1293 				v, x + 21, y + 6 + _traininfo_vehicle_pitch, w->hscroll.cap, 0, INVALID_VEHICLE);
  1271 			DrawVehicleProfitButton(v, x, y + 13);
  1294 			DrawVehicleProfitButton(v, x, y + 13);
  1272 
  1295 
  1273 			SetDParam(0, v->unitnumber);
  1296 			SetDParam(0, v->unitnumber);
  1274 			if (IsTrainDepotTile(v->tile))
  1297 			if (IsTrainDepotTile(v->tile))
  1275 				str = STR_021F;
  1298 				str = STR_021F;
  1323 			}
  1346 			}
  1324 		} break;
  1347 		} break;
  1325 
  1348 
  1326 		case 9: { /* Build new Vehicle */
  1349 		case 9: { /* Build new Vehicle */
  1327 			uint tile;
  1350 			uint tile;
       
  1351 
       
  1352 			if (!IsWindowOfPrototype(w, _player_trains_widgets))
       
  1353 				break;
  1328 
  1354 
  1329 			tile = _last_built_train_depot_tile;
  1355 			tile = _last_built_train_depot_tile;
  1330 			do {
  1356 			do {
  1331 				if (_map_owner[tile] == _local_player && IsTrainDepotTile(tile)) {
  1357 				if (_map_owner[tile] == _local_player && IsTrainDepotTile(tile)) {
  1332 					ShowTrainDepotWindow(tile);
  1358 					ShowTrainDepotWindow(tile);
  1378 			vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
  1404 			vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
  1379 			vl->flags |= VL_RESORT;
  1405 			vl->flags |= VL_RESORT;
  1380 			SetWindowDirty(w);
  1406 			SetWindowDirty(w);
  1381 		}
  1407 		}
  1382 		break;
  1408 		break;
       
  1409 
       
  1410 	case WE_RESIZE:
       
  1411 		/* Update the scroll + matrix */
       
  1412 		w->hscroll.cap += e->sizing.diff.x / 29;
       
  1413 		w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
       
  1414 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
       
  1415 		break;
  1383 	}
  1416 	}
  1384 }
  1417 }
  1385 
  1418 
  1386 static const WindowDesc _player_trains_desc = {
  1419 static const WindowDesc _player_trains_desc = {
  1387 	-1, -1, 325, 220,
  1420 	-1, -1, 325, 220,
  1388 	WC_TRAINS_LIST,0,
  1421 	WC_TRAINS_LIST,0,
  1389 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
  1422 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1390 	_player_trains_widgets,
  1423 	_player_trains_widgets,
  1391 	PlayerTrainsWndProc
  1424 	PlayerTrainsWndProc
  1392 };
  1425 };
  1393 
  1426 
  1394 static const WindowDesc _other_player_trains_desc = {
  1427 static const WindowDesc _other_player_trains_desc = {
  1395 	-1, -1, 325, 208,
  1428 	-1, -1, 325, 220,
  1396 	WC_TRAINS_LIST,0,
  1429 	WC_TRAINS_LIST,0,
  1397 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
  1430 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1398 	_other_player_trains_widgets,
  1431 	_other_player_trains_widgets,
  1399 	PlayerTrainsWndProc
  1432 	PlayerTrainsWndProc
  1400 };
  1433 };
  1401 
  1434 
  1402 void ShowPlayerTrains(int player, int station)
  1435 void ShowPlayerTrains(int player, int station)
  1408 	} else {
  1441 	} else {
  1409 		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
  1442 		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
  1410 	}
  1443 	}
  1411 	if (w) {
  1444 	if (w) {
  1412 		w->caption_color = w->window_number;
  1445 		w->caption_color = w->window_number;
       
  1446 		w->hscroll.cap = 10;
  1413 		w->vscroll.cap = 7; // maximum number of vehicles shown
  1447 		w->vscroll.cap = 7; // maximum number of vehicles shown
  1414 	}
  1448 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1415 }
  1449 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
       
  1450 		w->resize.step_width = 29;
       
  1451 		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
       
  1452 	}
       
  1453 }