src/build_vehicle_gui.cpp
branchgamebalance
changeset 9907 3b068c3a1c74
parent 9903 dc85aaa556ae
child 9910 0b2aebc8283e
equal deleted inserted replaced
9906:6f41b8713b65 9907:3b068c3a1c74
    39 	BUILD_VEHICLE_WIDGET_SCROLLBAR,
    39 	BUILD_VEHICLE_WIDGET_SCROLLBAR,
    40 	BUILD_VEHICLE_WIDGET_PANEL,
    40 	BUILD_VEHICLE_WIDGET_PANEL,
    41 	BUILD_VEHICLE_WIDGET_BUILD,
    41 	BUILD_VEHICLE_WIDGET_BUILD,
    42 	BUILD_VEHICLE_WIDGET_RENAME,
    42 	BUILD_VEHICLE_WIDGET_RENAME,
    43 	BUILD_VEHICLE_WIDGET_RESIZE,
    43 	BUILD_VEHICLE_WIDGET_RESIZE,
       
    44 	BUILD_VEHICLE_WIDGET_END
    44 };
    45 };
    45 
    46 
    46 static const Widget _build_vehicle_widgets[] = {
    47 static const Widget _build_vehicle_widgets[] = {
    47 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
    48 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
    48 	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   227,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
    49 	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
    49 	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
    50 	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
    50 	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   215,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
    51 	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
    51 	{    WWT_TEXTBTN,     RESIZE_LR,    14,   216,   227,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
    52 	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
    52 	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   215,    26,   121, 0x0,                     STR_NULL },
    53 	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,   121, 0x0,                     STR_NULL },
    53 	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   216,   227,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
    54 	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
    54 	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   227,   122,   223, 0x0,                     STR_NULL },
    55 	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,   122,   243, 0x0,                     STR_NULL },
    55 
    56 
    56 	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   224,   235, 0x0,                     STR_NULL },
    57 	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   244,   255, 0x0,                     STR_NULL },
    57 	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   215,   224,   235, 0x0,                     STR_NULL },
    58 	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   244,   255, 0x0,                     STR_NULL },
    58 	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   216,   227,   224,   235, 0x0,                     STR_RESIZE_BUTTON },
    59 	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   244,   255, 0x0,                     STR_RESIZE_BUTTON },
    59 	{   WIDGETS_END},
    60 	{   WIDGETS_END},
    60 };
    61 };
    61 
    62 
    62 /* Setup widget strings to fit the different types of vehicles */
    63 /* Setup widget strings to fit the different types of vehicles */
    63 static void SetupWindowStrings(Window *w, byte type)
    64 static void SetupWindowStrings(Window *w, byte type)
   564 /**
   565 /**
   565  * Draw the purchase info details of a vehicle at a given location.
   566  * Draw the purchase info details of a vehicle at a given location.
   566  * @param x,y location where to draw the info
   567  * @param x,y location where to draw the info
   567  * @param w how wide are the text allowed to be (size of widget/window to Draw in)
   568  * @param w how wide are the text allowed to be (size of widget/window to Draw in)
   568  * @param engine_number the engine of which to draw the info of
   569  * @param engine_number the engine of which to draw the info of
       
   570  * @return y after drawing all the text
   569  */
   571  */
   570 void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
   572 int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
   571 {
   573 {
   572 	const Engine *e = GetEngine(engine_number);
   574 	const Engine *e = GetEngine(engine_number);
   573 	YearMonthDay ymd;
   575 	YearMonthDay ymd;
   574 	ConvertDateToYMD(e->intro_date, &ymd);
   576 	ConvertDateToYMD(e->intro_date, &ymd);
   575 	bool refitable = false;
   577 	bool refitable = false;
   631 	}
   633 	}
   632 
   634 
   633 	/* Additional text from NewGRF */
   635 	/* Additional text from NewGRF */
   634 	y += ShowAdditionalText(x, y, w, engine_number);
   636 	y += ShowAdditionalText(x, y, w, engine_number);
   635 	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
   637 	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
       
   638 
       
   639 	return y;
   636 }
   640 }
   637 
   641 
   638 /* Figure out what train EngineIDs to put in the list */
   642 /* Figure out what train EngineIDs to put in the list */
   639 static void GenerateBuildTrainList(Window *w)
   643 static void GenerateBuildTrainList(Window *w)
   640 {
   644 {
   830 			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
   834 			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
   831 		}
   835 		}
   832 	}
   836 	}
   833 }
   837 }
   834 
   838 
       
   839 static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
       
   840 {
       
   841 	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
       
   842 
       
   843 	SetWindowDirty(w);
       
   844 	wi->bottom += expand_by;
       
   845 
       
   846 	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
       
   847 		wi = &w->widget[i];
       
   848 		wi->top += expand_by;
       
   849 		wi->bottom += expand_by;
       
   850 	}
       
   851 
       
   852 	w->height += expand_by;
       
   853 	SetWindowDirty(w);
       
   854 }
       
   855 
   835 static void DrawBuildVehicleWindow(Window *w)
   856 static void DrawBuildVehicleWindow(Window *w)
   836 {
   857 {
   837 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
   858 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
   838 	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
   859 	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
   839 
   860 
   845 
   866 
   846 	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false);
   867 	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false);
   847 
   868 
   848 	if (bv->sel_engine != INVALID_ENGINE) {
   869 	if (bv->sel_engine != INVALID_ENGINE) {
   849 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
   870 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
   850 		DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
   871 		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
       
   872 
       
   873 		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
   851 	}
   874 	}
   852 
   875 
   853 	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
   876 	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
   854 	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
   877 	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
   855 }
   878 }
   978 			break;
  1001 			break;
   979 	}
  1002 	}
   980 }
  1003 }
   981 
  1004 
   982 static const WindowDesc _build_vehicle_desc = {
  1005 static const WindowDesc _build_vehicle_desc = {
   983 	WDP_AUTO, WDP_AUTO, 228, 236,
  1006 	WDP_AUTO, WDP_AUTO, 240, 256,
   984 	WC_BUILD_VEHICLE, WC_NONE,
  1007 	WC_BUILD_VEHICLE, WC_NONE,
   985 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1008 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
   986 	_build_vehicle_widgets,
  1009 	_build_vehicle_widgets,
   987 	NewVehicleWndProc
  1010 	NewVehicleWndProc
   988 };
  1011 };
  1019 		case VEH_TRAIN:
  1042 		case VEH_TRAIN:
  1020 			WP(w,buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1043 			WP(w,buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1021 			ResizeWindow(w, 0, 16);
  1044 			ResizeWindow(w, 0, 16);
  1022 			break;
  1045 			break;
  1023 		case VEH_ROAD:
  1046 		case VEH_ROAD:
  1024 			ResizeWindow(w, 20, 16);
  1047 			ResizeWindow(w, 0, 16);
  1025 		case VEH_SHIP:
  1048 		case VEH_SHIP:
  1026 			ResizeWindow(w, 27, 0);
       
  1027 			break;
  1049 			break;
  1028 		case VEH_AIRCRAFT:
  1050 		case VEH_AIRCRAFT:
  1029 			bv->filter.flags =
  1051 			bv->filter.flags =
  1030 				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
  1052 				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
  1031 			ResizeWindow(w, 12, 0);
       
  1032 			break;
  1053 			break;
  1033 	}
  1054 	}
  1034 	SetupWindowStrings(w, type);
  1055 	SetupWindowStrings(w, type);
  1035 	ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
  1056 	ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
  1036 
  1057