mirror of https://github.com/OpenTTD/OpenTTD
(svn r19533) -Fix [FS#3720]: Vehicle details window did not resize correctly after refitting a road vehicle to a longer variant.
parent
08eba44922
commit
e1c68f1b2c
|
@ -1770,7 +1770,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
RoadVehicle *front = v->First();
|
RoadVehicle *front = v->First();
|
||||||
RoadVehUpdateCache(front);
|
RoadVehUpdateCache(front);
|
||||||
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) front->CargoChanged();
|
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);
|
SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
|
||||||
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
|
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1398,6 +1398,40 @@ struct VehicleDetailsWindow : Window {
|
||||||
this->tab = TDW_TAB_CARGO;
|
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)
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
|
@ -1425,16 +1459,7 @@ struct VehicleDetailsWindow : Window {
|
||||||
const Vehicle *v = Vehicle::Get(this->window_number);
|
const Vehicle *v = Vehicle::Get(this->window_number);
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
if (RoadVehicle::From(v)->HasArticulatedPart()) {
|
size->height = this->GetRoadVehDetailsHeight(v);
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
|
|
Loading…
Reference in New Issue