summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/vehicle_gui.cpp45
2 files changed, 36 insertions, 11 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 1b99b18c9..caacfadc6 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1770,7 +1770,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
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 {
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 5b6f91379..7631c27e0 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1398,6 +1398,40 @@ struct VehicleDetailsWindow : Window {
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 @@ struct VehicleDetailsWindow : Window {
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: