changeset 16220:22ed5c3cf68a draft

(svn r20921) -Fix [FS#4160]: Refit costs were not shown for long cargo names.
author terkhen <terkhen@openttd.org>
date Fri, 15 Oct 2010 10:22:04 +0000
parents ae82e848eca9
children 4f317dcb219a
files src/vehicle_gui.cpp
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -359,6 +359,7 @@
 	RefitOption *cargo;          ///< Refit option selected by \v sel.
 	SubtypeList list[NUM_CARGO]; ///< List of refit subtypes available for each sorted cargo.
 	VehicleOrderID order;        ///< If not #INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
+	uint information_width;      ///< Width required for correctly displaying all cargos in the information panel.
 	Scrollbar *vscroll;
 
 	/**
@@ -524,6 +525,10 @@
 				resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
 				size->height = resize->height * 8;
 				break;
+
+			case VRW_INFOPANEL:
+				size->width = WD_FRAMERECT_LEFT + this->information_width + WD_FRAMERECT_RIGHT;
+				break;
 		}
 	}
 
@@ -560,6 +565,27 @@
 		switch (data) {
 			case 0: { // The consist lenght of the vehicle has changed; rebuild the entire list.
 				this->BuildRefitList();
+				uint max_width = 0;
+				Vehicle *v = Vehicle::Get(this->window_number);
+
+				/* Check the width of all cargo information strings. */
+				for (uint i = 0; i < NUM_CARGO; i++) {
+					for (uint j = 0; j < this->list[i].Length(); j++) {
+						CommandCost cost = DoCommand(v->tile, v->index, list[i][j].cargo | list[i][j].subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
+						if (cost.Succeeded()) {
+							SetDParam(0, list[i][j].cargo);
+							SetDParam(1, _returned_refit_capacity);
+							SetDParam(2, cost.GetCost());
+							Dimension dim = GetStringBoundingBox(STR_REFIT_NEW_CAPACITY_COST_OF_REFIT);
+							max_width = max(dim.width, max_width);
+						}
+					}
+				}
+
+				if (this->information_width < max_width) {
+					this->information_width = max_width;
+					this->ReInit();
+				}
 				/* FALL THROUGH */
 			}