OpenTTD

Tasklist

FS#6102 - Number of vehicles in depots not fully displayed

Attached to Project: OpenTTD
Opened by Juanjo (juanjo) - Sunday, 31 August 2014, 18:36 GMT
Last edited by Remko Bijker (Rubidium) - Tuesday, 14 October 2014, 11:40 GMT
Type Bug
Category Interface
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

When there are thousands of vehicles, the number is not properly displayed in the depot window if the language has a digits separator (see image).

Currently, the space for the number is calculated as 4 digits, but doesn't take into account the separator:

#depot_gui.cpp
-Dimension unumber = { GetDigitWidth() * 4, FONT_HEIGHT_NORMAL };
+SetDParamMaxDigits(0, 4);
+Dimension unumber = GetStringBoundingBox(STR_BLACK_COMMA);

This task depends upon

Closed by  Remko Bijker (Rubidium)
Tuesday, 14 October 2014, 11:40 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r27014
Comment by Juanjo (juanjo) - Sunday, 31 August 2014, 19:07 GMT
Moreover, I think it doesn't look right to leave so much space.

The same problem in vehicle lists (see image).
Just to give some context about how vehicle lists deal with it:

#vehicle_gui.cpp
109 uint unitnumber = 0;
for (const Vehicle **v = this->vehicles.Begin(); v != this->vehicles.End(); v++) {
unitnumber = max<uint>(unitnumber, (*v)->unitnumber);
}

114 /* Because 111 is much less wide than e.g. 999 we use the
* wider numbers to determine the width instead of just
* the random number that it seems to be. */
if (unitnumber >= 1000) {
this->unitnumber_digits = 4;
} else if (unitnumber >= 100) {
this->unitnumber_digits = 3;
} else {
this->unitnumber_digits = 2;
}
...
1357 int text_offset = GetDigitWidth() * this->unitnumber_digits + WD_FRAMERECT_RIGHT;


I think a possible solution would be something like:
1) After building the list (depot, vehicle list,...), calculate the max unitnumber of the vehicles and store the number of digits (always at least 2).
2) Later on (probably on UpdateWidgetSize or similar), use that value with SetDParamMaxDigits and use GetStringBoundingBox. Keep that value for drawing the list later.

Loading...