src/autoreplace_gui.cpp
changeset 9027 b28d0b8809ad
parent 9024 98e36f0e7075
child 9065 cb8e7bdc2782
equal deleted inserted replaced
9026:690846c6ee99 9027:b28d0b8809ad
    49 	STR_MAGLEV_VEHICLES,
    49 	STR_MAGLEV_VEHICLES,
    50 	INVALID_STRING_ID
    50 	INVALID_STRING_ID
    51 };
    51 };
    52 
    52 
    53 enum ReplaceVehicleWindowWidgets {
    53 enum ReplaceVehicleWindowWidgets {
    54 	RVW_WIDGET_LEFT_DETAILS = 3,
    54 	RVW_WIDGET_LEFT_MATRIX = 3,
       
    55 	RVW_WIDGET_LEFT_SCROLLBAR,
       
    56 	RVW_WIDGET_RIGHT_MATRIX,
       
    57 	RVW_WIDGET_RIGHT_SCROLLBAR,
       
    58 	RVW_WIDGET_LEFT_DETAILS,
       
    59 	RVW_WIDGET_RIGHT_DETAILS,
       
    60 
       
    61 	/* Button row */
    55 	RVW_WIDGET_START_REPLACE,
    62 	RVW_WIDGET_START_REPLACE,
    56 	RVW_WIDGET_INFO_TAB,
    63 	RVW_WIDGET_INFO_TAB,
    57 	RVW_WIDGET_STOP_REPLACE,
    64 	RVW_WIDGET_STOP_REPLACE,
    58 	RVW_WIDGET_LEFT_MATRIX,
    65 	RVW_WIDGET_RESIZE,
    59 	RVW_WIDGET_LEFT_SCROLLBAR,
    66 
    60 	RVW_WIDGET_RIGHT_MATRIX,
    67 	/* Train only widgets */
    61 	RVW_WIDGET_RIGHT_SCROLLBAR,
       
    62 	RVW_WIDGET_RIGHT_DETAILS,
       
    63 
       
    64 	RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE,
    68 	RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE,
    65 	RVW_WIDGET_TRAIN_FLUFF_LEFT,
    69 	RVW_WIDGET_TRAIN_FLUFF_LEFT,
    66 	RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN,
    70 	RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN,
    67 	RVW_WIDGET_TRAIN_FLUFF_RIGHT,
    71 	RVW_WIDGET_TRAIN_FLUFF_RIGHT,
    68 	RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE,
    72 	RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE,
   256 	WP(w, replaceveh_d).update_right = false;
   260 	WP(w, replaceveh_d).update_right = false;
   257 	WP(w, replaceveh_d).init_lists   = false;
   261 	WP(w, replaceveh_d).init_lists   = false;
   258 }
   262 }
   259 
   263 
   260 
   264 
   261 void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
   265 void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group);
   262 
   266 
   263 static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
   267 static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
   264 {
   268 {
   265 	/* Strings for the pulldown menu */
   269 	/* Strings for the pulldown menu */
   266 	static const StringID _vehicle_type_names[] = {
   270 	static const StringID _vehicle_type_names[] = {
   352 				EngineList list = WP(w, replaceveh_d).list[i]; // which list to draw
   356 				EngineList list = WP(w, replaceveh_d).list[i]; // which list to draw
   353 				EngineID start  = i == 0 ? w->vscroll.pos : w->vscroll2.pos; // what is the offset for the start (scrolling)
   357 				EngineID start  = i == 0 ? w->vscroll.pos : w->vscroll2.pos; // what is the offset for the start (scrolling)
   354 				EngineID end    = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list));
   358 				EngineID end    = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list));
   355 
   359 
   356 				/* Do the actual drawing */
   360 				/* Do the actual drawing */
   357 				DrawEngineList((VehicleType)w->window_number, w->widget[widget].left + 2, w->widget[widget].top + 1, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0, selected_group);
   361 				DrawEngineList((VehicleType)w->window_number, w->widget[widget].left + 2, w->widget[widget].top + 1, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0 ? w->widget[RVW_WIDGET_LEFT_MATRIX].right - 2 : 0, selected_group);
   358 
   362 
   359 				/* Also draw the details if an engine is selected */
   363 				/* Also draw the details if an engine is selected */
   360 				if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) {
   364 				if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) {
   361 					const Widget *wi = &w->widget[i == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS];
   365 					const Widget *wi = &w->widget[i == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS];
   362 					int text_end = DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, WP(w, replaceveh_d).sel_engine[i]);
   366 					int text_end = DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, WP(w, replaceveh_d).sel_engine[i]);
   437 			WP(w, replaceveh_d).init_lists   = true;
   441 			WP(w, replaceveh_d).init_lists   = true;
   438 			SetWindowDirty(w);
   442 			SetWindowDirty(w);
   439 		} break;
   443 		} break;
   440 
   444 
   441 		case WE_RESIZE:
   445 		case WE_RESIZE:
       
   446 		{
   442 			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
   447 			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
   443 			w->vscroll2.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
   448 			w->vscroll2.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
   444 
   449 
   445 			w->widget[RVW_WIDGET_LEFT_MATRIX].data  = (w->vscroll.cap  << 8) + 1;
   450 			Widget *widget = w->widget;
   446 			w->widget[RVW_WIDGET_RIGHT_MATRIX].data = (w->vscroll2.cap << 8) + 1;
   451 
   447 			break;
   452 			widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (w->vscroll2.cap << 8) + 1;
       
   453 
       
   454 			if (e->we.sizing.diff.x != 0) {
       
   455 				/* We changed the width of the window so we have to resize the lists.
       
   456 				 * Because ResizeButtons() makes each widget the same size it can't be used on the lists
       
   457 				 * because then the lists would have the same size as the scrollbars.
       
   458 				 * Instead we use it on the detail panels.
       
   459 				 * Afterwards we use the new location of the detail panels (the middle of the window)
       
   460 				 * to place the lists.
       
   461 				 * This way the lists will have equal size while keeping the width of the scrollbars unchanged. */
       
   462 				ResizeButtons(w, RVW_WIDGET_LEFT_DETAILS, RVW_WIDGET_RIGHT_DETAILS);
       
   463 				widget[RVW_WIDGET_RIGHT_MATRIX].left    = widget[RVW_WIDGET_RIGHT_DETAILS].left;
       
   464 				widget[RVW_WIDGET_LEFT_SCROLLBAR].right = widget[RVW_WIDGET_LEFT_DETAILS].right;
       
   465 				widget[RVW_WIDGET_LEFT_SCROLLBAR].left  = widget[RVW_WIDGET_LEFT_SCROLLBAR].right - 11;
       
   466 				widget[RVW_WIDGET_LEFT_MATRIX].right    = widget[RVW_WIDGET_LEFT_SCROLLBAR].left - 1;
       
   467 			}
       
   468 		} break;
   448 
   469 
   449 		case WE_INVALIDATE_DATA:
   470 		case WE_INVALIDATE_DATA:
   450 			if (_rebuild_left_list) WP(w, replaceveh_d).update_left = true;
   471 			if (_rebuild_left_list) WP(w, replaceveh_d).update_left = true;
   451 			if (_rebuild_right_list) WP(w, replaceveh_d).update_right = true;
   472 			if (_rebuild_right_list) WP(w, replaceveh_d).update_right = true;
   452 			SetWindowDirty(w);
   473 			SetWindowDirty(w);
   457 			EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
   478 			EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
   458 		break;
   479 		break;
   459 	}
   480 	}
   460 }
   481 }
   461 
   482 
   462 static const Widget _replace_rail_vehicle_widgets[] = {
   483 static const Widget _replace_vehicle_widgets[] = {
   463 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
   484 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
   464 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   485 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   465 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                        STR_STICKY_BUTTON},
   486 {  WWT_STICKYBOX,     RESIZE_LR,    14,   444,   455,     0,    13, STR_NULL,                        STR_STICKY_BUTTON},
   466 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   227, 0x0,                             STR_NULL},
   487 
   467 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   240,   251, STR_REPLACE_VEHICLES_START,      STR_REPLACE_HELP_START_BUTTON},
   488 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,    13, 0x1,                             STR_REPLACE_HELP_LEFT_ARRAY},
   468 {      WWT_PANEL,     RESIZE_TB,    14,   139,   316,   228,   239, 0x0,                             STR_REPLACE_HELP_REPLACE_INFO_TAB},
   489 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,    13, STR_NULL,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
   469 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   240,   251, STR_REPLACE_VEHICLES_STOP,       STR_REPLACE_HELP_STOP_BUTTON},
   490 {     WWT_MATRIX,    RESIZE_LRB,    14,   228,   443,    14,    13, 0x1,                             STR_REPLACE_HELP_RIGHT_ARRAY},
   470 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,                           STR_REPLACE_HELP_LEFT_ARRAY},
   491 { WWT_SCROLL2BAR,    RESIZE_LRB,    14,   444,   455,    14,    13, STR_NULL,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
   471 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
   492 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,    14,   105, 0x0,                             STR_NULL},
   472 {     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,                           STR_REPLACE_HELP_RIGHT_ARRAY},
   493 {      WWT_PANEL,    RESIZE_RTB,    14,   228,   455,    14,   105, 0x0,                             STR_NULL},
   473 { WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
   494 
   474 {      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   227, 0x0,                             STR_NULL},
   495 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   106,   117, STR_REPLACE_VEHICLES_START,      STR_REPLACE_HELP_START_BUTTON},
   475 // train specific stuff
   496 {      WWT_PANEL,    RESIZE_RTB,    14,   139,   305,   106,   117, 0x0,                             STR_REPLACE_HELP_REPLACE_INFO_TAB},
   476 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   228,   239, STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP},  // widget 12
   497 { WWT_PUSHTXTBTN,   RESIZE_LRTB,    14,   306,   443,   106,   117, STR_REPLACE_VEHICLES_STOP,       STR_REPLACE_HELP_STOP_BUTTON},
   477 {      WWT_PANEL,     RESIZE_TB,    14,   139,   153,   240,   251, 0x0,                             STR_NULL},
   498 {  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   444,   455,   106,   117, STR_NULL,                        STR_RESIZE_BUTTON},
   478 {   WWT_DROPDOWN,     RESIZE_TB,    14,   154,   289,   240,   251, 0x0,                             STR_REPLACE_HELP_RAILTYPE},
   499 
   479 {      WWT_PANEL,     RESIZE_TB,    14,   290,   305,   240,   251, 0x0,                             STR_NULL},
   500 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   128,   139, STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP},
   480 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   317,   455,   228,   239, STR_REPLACE_REMOVE_WAGON,        STR_REPLACE_REMOVE_WAGON_HELP},
   501 {      WWT_PANEL,     RESIZE_TB,    14,   139,   153,   128,   139, 0x0,                             STR_NULL},
   481 // end of train specific stuff
   502 {   WWT_DROPDOWN,    RESIZE_RTB,    14,   154,   289,   128,   139, 0x0,                             STR_REPLACE_HELP_RAILTYPE},
   482 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   240,   251, STR_NULL,                        STR_RESIZE_BUTTON},
   503 {      WWT_PANEL,   RESIZE_LRTB,    14,   290,   305,   128,   139, 0x0,                             STR_NULL},
       
   504 { WWT_PUSHTXTBTN,   RESIZE_LRTB,    14,   306,   443,   128,   139, STR_REPLACE_REMOVE_WAGON,        STR_REPLACE_REMOVE_WAGON_HELP},
   483 {   WIDGETS_END},
   505 {   WIDGETS_END},
   484 };
   506 };
   485 
   507 
   486 static const Widget _replace_road_vehicle_widgets[] = {
       
   487 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
       
   488 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
       
   489 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
       
   490 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   217, 0x0,                         STR_NULL},
       
   491 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   218,   229, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
       
   492 {      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   218,   229, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
       
   493 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   218,   229, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
       
   494 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,                       STR_REPLACE_HELP_LEFT_ARRAY},
       
   495 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
   496 {     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,                       STR_REPLACE_HELP_RIGHT_ARRAY},
       
   497 { WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
   498 {      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   217, 0x0,                         STR_NULL},
       
   499 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   218,   229, STR_NULL,                    STR_RESIZE_BUTTON},
       
   500 {   WIDGETS_END},
       
   501 };
       
   502 
       
   503 static const Widget _replace_ship_aircraft_vehicle_widgets[] = {
       
   504 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
       
   505 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
       
   506 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
       
   507 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   110,   201, 0x0,                         STR_NULL},
       
   508 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   202,   213, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
       
   509 {      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   202,   213, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
       
   510 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   202,   213, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
       
   511 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   109, 0x401,                       STR_REPLACE_HELP_LEFT_ARRAY},
       
   512 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
   513 {     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   109, 0x401,                       STR_REPLACE_HELP_RIGHT_ARRAY},
       
   514 { WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
   515 {      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   110,   201, 0x0,                         STR_NULL},
       
   516 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   202,   213, STR_NULL,                    STR_RESIZE_BUTTON},
       
   517 {   WIDGETS_END},
       
   518 };
       
   519 
       
   520 static const WindowDesc _replace_rail_vehicle_desc = {
   508 static const WindowDesc _replace_rail_vehicle_desc = {
   521 	WDP_AUTO, WDP_AUTO, 456, 252, 456, 252,
   509 	WDP_AUTO, WDP_AUTO, 456, 140, 456, 140,
   522 	WC_REPLACE_VEHICLE, WC_NONE,
   510 	WC_REPLACE_VEHICLE, WC_NONE,
   523 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   511 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   524 	_replace_rail_vehicle_widgets,
   512 	_replace_vehicle_widgets,
   525 	ReplaceVehicleWndProc
   513 	ReplaceVehicleWndProc
   526 };
   514 };
   527 
   515 
   528 static const WindowDesc _replace_road_vehicle_desc = {
   516 static const WindowDesc _replace_vehicle_desc = {
   529 	WDP_AUTO, WDP_AUTO, 456, 230, 456, 230,
   517 	WDP_AUTO, WDP_AUTO, 456, 118, 456, 118,
   530 	WC_REPLACE_VEHICLE, WC_NONE,
   518 	WC_REPLACE_VEHICLE, WC_NONE,
   531 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   519 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   532 	_replace_road_vehicle_widgets,
   520 	_replace_vehicle_widgets,
   533 	ReplaceVehicleWndProc
   521 	ReplaceVehicleWndProc
   534 };
   522 };
   535 
   523 
   536 static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
       
   537 	WDP_AUTO, WDP_AUTO, 456, 214, 456, 214,
       
   538 	WC_REPLACE_VEHICLE, WC_NONE,
       
   539 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
       
   540 	_replace_ship_aircraft_vehicle_widgets,
       
   541 	ReplaceVehicleWndProc
       
   542 };
       
   543 
       
   544 
   524 
   545 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
   525 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
   546 {
   526 {
   547 	Window *w;
       
   548 
       
   549 	DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
   527 	DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
   550 
   528 	Window *w = vehicletype == VEH_TRAIN ? AllocateWindowDescFront(&_replace_rail_vehicle_desc, VEH_TRAIN)
   551 	switch (vehicletype) {
   529 										 : AllocateWindowDescFront(&_replace_vehicle_desc, vehicletype);
   552 		default: NOT_REACHED();
   530 
   553 		case VEH_TRAIN:
   531 	w->resize.step_height = GetVehicleListHeight(vehicletype);
   554 			w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
   532 	w->vscroll.cap = w->resize.step_height == 14 ? 8 : 4;
   555 			w->vscroll.cap  = 8;
   533 
   556 			w->resize.step_height = 14;
   534 	Widget *widget = w->widget;
   557 			WP(w, replaceveh_d).wagon_btnstate = true;
   535 	widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (w->vscroll.cap << 8) + 1;
   558 			break;
   536 
   559 		case VEH_ROAD:
   537 	if (vehicletype == VEH_TRAIN) {
   560 			w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
   538 		WP(w, replaceveh_d).wagon_btnstate = true;
   561 			w->vscroll.cap  = 8;
   539 		/* The train window is bigger so we will move some of the widgets to fit the new size.
   562 			w->resize.step_height = 14;
   540 		 * We will start by moving the resize button to the lower right corner.                 */
   563 			break;
   541 		widget[RVW_WIDGET_RESIZE].top         = widget[RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE].top;
   564 		case VEH_SHIP:
   542 		widget[RVW_WIDGET_RESIZE].bottom      = widget[RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE].bottom;
   565 		case VEH_AIRCRAFT:
   543 		widget[RVW_WIDGET_STOP_REPLACE].right = widget[RVW_WIDGET_RESIZE].right;
   566 			w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
   544 
   567 			w->vscroll.cap  = 4;
   545 		/* The detail panel is one line taller for trains so we will move some of the widgets one line (10 pixels) down. */
   568 			w->resize.step_height = 24;
   546 		widget[RVW_WIDGET_LEFT_DETAILS].bottom  += 10;
   569 			break;
   547 		widget[RVW_WIDGET_RIGHT_DETAILS].bottom += 10;
   570 	}
   548 		for (int i = RVW_WIDGET_START_REPLACE; i < RVW_WIDGET_RESIZE; i++) {
       
   549 			widget[i].top    += 10;
       
   550 			widget[i].bottom += 10;
       
   551 		}
       
   552 	} else {
       
   553 		/* Since it's not a train we will hide the train only widgets. */
       
   554 		w->SetWidgetsHiddenState(true,
       
   555 								 RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE,
       
   556 								 RVW_WIDGET_TRAIN_FLUFF_LEFT,
       
   557 								 RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN,
       
   558 								 RVW_WIDGET_TRAIN_FLUFF_RIGHT,
       
   559 								 RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE,
       
   560 								 WIDGET_LIST_END);
       
   561 	}
       
   562 
       
   563 	ResizeWindow(w, 0, w->resize.step_height * w->vscroll.cap);
       
   564 
       
   565 	/* Set the minimum window size to the current window size */
       
   566 	w->resize.width  = w->width;
       
   567 	w->resize.height = w->height;
   571 
   568 
   572 	w->caption_color = _local_player;
   569 	w->caption_color = _local_player;
   573 	WP(w, replaceveh_d).sel_group = id_g;
   570 	WP(w, replaceveh_d).sel_group = id_g;
   574 	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
   571 	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
   575 }
   572 }