src/build_vehicle_gui.cpp
branchgamebalance
changeset 9907 3b068c3a1c74
parent 9903 dc85aaa556ae
child 9910 0b2aebc8283e
--- a/src/build_vehicle_gui.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/build_vehicle_gui.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -41,21 +41,22 @@
 	BUILD_VEHICLE_WIDGET_BUILD,
 	BUILD_VEHICLE_WIDGET_RENAME,
 	BUILD_VEHICLE_WIDGET_RESIZE,
+	BUILD_VEHICLE_WIDGET_END
 };
 
 static const Widget _build_vehicle_widgets[] = {
 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
-	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   227,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
+	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
 	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
-	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   215,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
-	{    WWT_TEXTBTN,     RESIZE_LR,    14,   216,   227,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
-	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   215,    26,   121, 0x0,                     STR_NULL },
-	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   216,   227,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
-	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   227,   122,   223, 0x0,                     STR_NULL },
+	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
+	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
+	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,   121, 0x0,                     STR_NULL },
+	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
+	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,   122,   243, 0x0,                     STR_NULL },
 
-	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   224,   235, 0x0,                     STR_NULL },
-	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   215,   224,   235, 0x0,                     STR_NULL },
-	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   216,   227,   224,   235, 0x0,                     STR_RESIZE_BUTTON },
+	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   244,   255, 0x0,                     STR_NULL },
+	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   244,   255, 0x0,                     STR_NULL },
+	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   244,   255, 0x0,                     STR_RESIZE_BUTTON },
 	{   WIDGETS_END},
 };
 
@@ -566,8 +567,9 @@
  * @param x,y location where to draw the info
  * @param w how wide are the text allowed to be (size of widget/window to Draw in)
  * @param engine_number the engine of which to draw the info of
+ * @return y after drawing all the text
  */
-void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
+int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	const Engine *e = GetEngine(engine_number);
 	YearMonthDay ymd;
@@ -633,6 +635,8 @@
 	/* Additional text from NewGRF */
 	y += ShowAdditionalText(x, y, w, engine_number);
 	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
+
+	return y;
 }
 
 /* Figure out what train EngineIDs to put in the list */
@@ -832,6 +836,23 @@
 	}
 }
 
+static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
+{
+	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
+
+	SetWindowDirty(w);
+	wi->bottom += expand_by;
+
+	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
+		wi = &w->widget[i];
+		wi->top += expand_by;
+		wi->bottom += expand_by;
+	}
+
+	w->height += expand_by;
+	SetWindowDirty(w);
+}
+
 static void DrawBuildVehicleWindow(Window *w)
 {
 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
@@ -847,7 +868,9 @@
 
 	if (bv->sel_engine != INVALID_ENGINE) {
 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
-		DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
+		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
+
+		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
 	}
 
 	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
@@ -980,7 +1003,7 @@
 }
 
 static const WindowDesc _build_vehicle_desc = {
-	WDP_AUTO, WDP_AUTO, 228, 236,
+	WDP_AUTO, WDP_AUTO, 240, 256,
 	WC_BUILD_VEHICLE, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 	_build_vehicle_widgets,
@@ -1021,14 +1044,12 @@
 			ResizeWindow(w, 0, 16);
 			break;
 		case VEH_ROAD:
-			ResizeWindow(w, 20, 16);
+			ResizeWindow(w, 0, 16);
 		case VEH_SHIP:
-			ResizeWindow(w, 27, 0);
 			break;
 		case VEH_AIRCRAFT:
 			bv->filter.flags =
 				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
-			ResizeWindow(w, 12, 0);
 			break;
 	}
 	SetupWindowStrings(w, type);