changeset 14931:e58e07eb2293 draft

(svn r19533) -Fix [FS#3720]: Vehicle details window did not resize correctly after refitting a road vehicle to a longer variant.
author terkhen <terkhen@openttd.org>
date Thu, 01 Apr 2010 18:30:00 +0000
parents a26a72fe2470
children a1cadfd0c372
files src/roadveh_cmd.cpp src/vehicle_gui.cpp
diffstat 2 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1770,7 +1770,7 @@
 		RoadVehicle *front = v->First();
 		RoadVehUpdateCache(front);
 		if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) front->CargoChanged();
-		SetWindowDirty(WC_VEHICLE_DETAILS, front->index);
+		InvalidateWindowData(WC_VEHICLE_DETAILS, front->index);
 		SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
 		InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
 	} else {
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1398,6 +1398,40 @@
 		this->tab = TDW_TAB_CARGO;
 	}
 
+	virtual void OnInvalidateData(int data)
+	{
+		const Vehicle *v = Vehicle::Get(this->window_number);
+		if (v->type == VEH_ROAD) {
+			const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(VLD_WIDGET_MIDDLE_DETAILS);
+			uint aimed_height = this->GetRoadVehDetailsHeight(v);
+			/* If the number of articulated parts changes, the size of the window must change too. */
+			if (aimed_height != nwid_info->current_y) {
+				this->ReInit();
+			}
+		}
+	}
+
+	/**
+	 * Gets the desired height for the road vehicle details panel.
+	 * @param v Road vehicle being shown.
+	 * @return Desired height in pixels.
+	 */
+	uint GetRoadVehDetailsHeight(const Vehicle *v)
+	{
+		uint desired_height;
+		if (RoadVehicle::From(v)->HasArticulatedPart()) {
+			/* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
+			desired_height = WD_FRAMERECT_TOP + 15 + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM;
+			/* Add space for the cargo amount for each part. */
+			for (const Vehicle *u = v; u != NULL; u = u->Next()) {
+				if (u->cargo_cap != 0) desired_height += FONT_HEIGHT_NORMAL + 1;
+			}
+		} else {
+			desired_height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
+		}
+		return desired_height;
+	}
+
 	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 	{
 		switch (widget) {
@@ -1425,16 +1459,7 @@
 				const Vehicle *v = Vehicle::Get(this->window_number);
 				switch (v->type) {
 					case VEH_ROAD:
-						if (RoadVehicle::From(v)->HasArticulatedPart()) {
-							/* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
-							size->height = WD_FRAMERECT_TOP + 15 + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM;
-							/* Add space for the cargo amount for each part. */
-							for (const Vehicle *u = v; u != NULL; u = u->Next()) {
-								if (u->cargo_cap != 0) size->height += FONT_HEIGHT_NORMAL + 1;
-							}
-						} else {
-							size->height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
-						}
+						size->height = this->GetRoadVehDetailsHeight(v);
 						break;
 
 					case VEH_SHIP: