1
0
Fork 0

Codechange: Use parameterised GetString() for station view.

pull/13692/head
Peter Nelson 2025-03-01 22:20:03 +00:00
parent 170002ff7e
commit f7a67fedb7
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
1 changed files with 31 additions and 39 deletions

View File

@ -516,9 +516,7 @@ public:
* when the order had been removed and the station list hasn't been removed yet */ * when the order had been removed and the station list hasn't been removed yet */
assert(st->owner == owner || st->owner == OWNER_NONE); assert(st->owner == owner || st->owner == OWNER_NONE);
SetDParam(0, st->index); int x = DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, GetString(STR_STATION_LIST_STATION, st->index, st->facilities));
SetDParam(1, st->facilities);
int x = DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, STR_STATION_LIST_STATION);
x += rtl ? -text_spacing : text_spacing; x += rtl ? -text_spacing : text_spacing;
/* show cargo waiting and station ratings */ /* show cargo waiting and station ratings */
@ -1738,7 +1736,7 @@ struct StationViewWindow : public Window {
* @param any String to be shown if the entry refers to "any station". * @param any String to be shown if the entry refers to "any station".
* @return One of the three given strings or STR_STATION_VIEW_RESERVED, depending on what station the entry refers to. * @return One of the three given strings or STR_STATION_VIEW_RESERVED, depending on what station the entry refers to.
*/ */
StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any) StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any) const
{ {
if (station == this->window_number) { if (station == this->window_number) {
return here; return here;
@ -1747,11 +1745,20 @@ struct StationViewWindow : public Window {
} else if (station == NEW_STATION) { } else if (station == NEW_STATION) {
return STR_STATION_VIEW_RESERVED; return STR_STATION_VIEW_RESERVED;
} else { } else {
SetDParam(2, station);
return other_station; return other_station;
} }
} }
StringID GetGroupingString(Grouping grouping, StationID station) const
{
switch (grouping) {
case GR_SOURCE: return this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
case GR_NEXT: return this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
case GR_DESTINATION: return this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
default: NOT_REACHED();
}
}
/** /**
* Determine if we need to show the special "non-stop" string. * Determine if we need to show the special "non-stop" string.
* @param cd Entry we are going to show. * @param cd Entry we are going to show.
@ -1814,31 +1821,17 @@ struct StationViewWindow : public Window {
if (pos > -maxrows && pos <= 0) { if (pos > -maxrows && pos <= 0) {
StringID str = STR_EMPTY; StringID str = STR_EMPTY;
StationID station = StationID::Invalid();
int y = r.top - pos * GetCharacterHeight(FS_NORMAL); int y = r.top - pos * GetCharacterHeight(FS_NORMAL);
SetDParam(0, cargo);
SetDParam(1, cd->GetCount());
if (this->groupings[column] == GR_CARGO) { if (this->groupings[column] == GR_CARGO) {
str = STR_STATION_VIEW_WAITING_CARGO; str = STR_STATION_VIEW_WAITING_CARGO;
DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + this->expand_shrink_width, r.right - this->expand_shrink_width, y); DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + this->expand_shrink_width, r.right - this->expand_shrink_width, y);
} else { } else {
if (!auto_distributed) grouping = GR_SOURCE; if (!auto_distributed) grouping = GR_SOURCE;
StationID station = cd->GetStation(); station = cd->GetStation();
str = this->GetGroupingString(grouping, station);
if (grouping == GR_NEXT && str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
switch (grouping) {
case GR_SOURCE:
str = this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
break;
case GR_NEXT:
str = this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
if (str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
break;
case GR_DESTINATION:
str = this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
break;
default:
NOT_REACHED();
}
if (pos == -this->scroll_to_row && Station::IsValidID(station)) { if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
ScrollMainWindowToTile(Station::Get(station)->xy); ScrollMainWindowToTile(Station::Get(station)->xy);
} }
@ -1848,7 +1841,7 @@ struct StationViewWindow : public Window {
Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl); Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl);
Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl); Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl);
DrawString(text.left, text.right, y, str); DrawString(text.left, text.right, y, GetString(str, cargo, cd->GetCount(), station));
if (column < NUM_COLUMNS - 1) { if (column < NUM_COLUMNS - 1) {
const char *sym = nullptr; const char *sym = nullptr;
@ -1888,8 +1881,7 @@ struct StationViewWindow : public Window {
const Station *st = Station::Get(this->window_number); const Station *st = Station::Get(this->window_number);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
SetDParam(0, GetAcceptanceMask(st)); int bottom = DrawStringMultiLine(tr.left, tr.right, tr.top, INT32_MAX, GetString(STR_STATION_VIEW_ACCEPTS_CARGO, GetAcceptanceMask(st)));
int bottom = DrawStringMultiLine(tr.left, tr.right, tr.top, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO);
return CeilDiv(bottom - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FS_NORMAL)); return CeilDiv(bottom - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FS_NORMAL));
} }
@ -1905,8 +1897,7 @@ struct StationViewWindow : public Window {
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
if (st->town->exclusive_counter > 0) { if (st->town->exclusive_counter > 0) {
SetDParam(0, st->town->exclusivity); tr.top = DrawStringMultiLine(tr, GetString(st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY, st->town->exclusivity));
tr.top = DrawStringMultiLine(tr, st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY);
tr.top += WidgetDimensions::scaled.vsep_wide; tr.top += WidgetDimensions::scaled.vsep_wide;
} }
@ -1918,11 +1909,12 @@ struct StationViewWindow : public Window {
if (!ge->HasRating()) continue; if (!ge->HasRating()) continue;
const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph); const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph);
SetDParam(0, cs->name); DrawString(tr.Indent(WidgetDimensions::scaled.hsep_indent, rtl),
SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].supply) : 0); GetString(STR_STATION_VIEW_CARGO_SUPPLY_RATING,
SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5)); cs->name,
SetDParam(3, ToPercent8(ge->rating)); lg != nullptr ? lg->Monthly((*lg)[ge->node].supply) : 0,
DrawString(tr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), STR_STATION_VIEW_CARGO_SUPPLY_RATING); STR_CARGO_RATING_APPALLING + (ge->rating >> 5),
ToPercent8(ge->rating)));
tr.top += GetCharacterHeight(FS_NORMAL); tr.top += GetCharacterHeight(FS_NORMAL);
} }
return CeilDiv(tr.top - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FS_NORMAL)); return CeilDiv(tr.top - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FS_NORMAL));
@ -2338,9 +2330,9 @@ struct SelectStationWindow : Window {
for (const auto &station : _stations_nearby_list) { for (const auto &station : _stations_nearby_list) {
if (station == NEW_STATION) continue; if (station == NEW_STATION) continue;
const BaseStation *st = BaseStation::Get(station); const BaseStation *st = BaseStation::Get(station);
SetDParam(0, st->index); d = maxdim(d, GetStringBoundingBox(T::IsWaypoint()
SetDParam(1, st->facilities); ? GetString(STR_STATION_LIST_WAYPOINT, st->index)
d = maxdim(d, GetStringBoundingBox(T::IsWaypoint() ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION)); : GetString(STR_STATION_LIST_STATION, st->index, st->facilities)));
} }
resize.height = d.height; resize.height = d.height;
@ -2361,9 +2353,9 @@ struct SelectStationWindow : Window {
DrawString(tr, T::IsWaypoint() ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION); DrawString(tr, T::IsWaypoint() ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
} else { } else {
const BaseStation *st = BaseStation::Get(*it); const BaseStation *st = BaseStation::Get(*it);
SetDParam(0, st->index); DrawString(tr, T::IsWaypoint()
SetDParam(1, st->facilities); ? GetString(STR_STATION_LIST_WAYPOINT, st->index)
DrawString(tr, T::IsWaypoint() ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION); : GetString(STR_STATION_LIST_STATION, st->index, st->facilities));
} }
} }