1
0
Fork 0

Codechange: Use parameterised GetString() for smallmap window. (#13684)

pull/13685/head
Peter Nelson 2025-03-01 18:24:14 +00:00 committed by GitHub
parent 1bd841b896
commit b92172e3d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 21 deletions

View File

@ -997,8 +997,7 @@ protected:
y + GetCharacterHeight(FS_SMALL) > dpi->top && y + GetCharacterHeight(FS_SMALL) > dpi->top &&
y < dpi->top + dpi->height) { y < dpi->top + dpi->height) {
/* And draw it. */ /* And draw it. */
SetDParam(0, t->index); DrawString(x, x + t->cache.sign.width_small, y, GetString(STR_SMALLMAP_TOWN, t->index));
DrawString(x, x + t->cache.sign.width_small, y, STR_SMALLMAP_TOWN);
} }
} }
} }
@ -1529,14 +1528,11 @@ public:
uint height = 0; uint height = 0;
uint num_columns = 1; uint num_columns = 1;
for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) { for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) {
StringID str; std::string str;
if (i == SMT_INDUSTRY) { if (i == SMT_INDUSTRY) {
SetDParam(0, tbl->legend); str = GetString(STR_SMALLMAP_INDUSTRY, tbl->legend, IndustryPool::MAX_SIZE);
SetDParam(1, IndustryPool::MAX_SIZE);
str = STR_SMALLMAP_INDUSTRY;
} else if (i == SMT_LINKSTATS) { } else if (i == SMT_LINKSTATS) {
SetDParam(0, tbl->legend); str = GetString(STR_SMALLMAP_LINKSTATS, tbl->legend);
str = STR_SMALLMAP_LINKSTATS;
} else if (i == SMT_OWNER) { } else if (i == SMT_OWNER) {
if (tbl->company != CompanyID::Invalid()) { if (tbl->company != CompanyID::Invalid()) {
if (!Company::IsValidID(tbl->company)) { if (!Company::IsValidID(tbl->company)) {
@ -1546,10 +1542,9 @@ public:
return; return;
} }
/* Non-fixed legend entries for the owner view. */ /* Non-fixed legend entries for the owner view. */
SetDParam(0, tbl->company); str = GetString(STR_SMALLMAP_COMPANY, tbl->company);
str = STR_SMALLMAP_COMPANY;
} else { } else {
str = tbl->legend; str = GetString(tbl->legend);
} }
} else { } else {
if (tbl->col_break) { if (tbl->col_break) {
@ -1558,8 +1553,11 @@ public:
num_columns++; num_columns++;
} }
height++; height++;
str = tbl->legend; if (i == SMT_CONTOUR) {
if (i == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP); str = GetString(tbl->legend, tbl->height * TILE_HEIGHT_STEP);
} else {
str = GetString(tbl->legend);
}
} }
min_width = std::max(GetStringBoundingBox(str).width, min_width); min_width = std::max(GetStringBoundingBox(str).width, min_width);
} }
@ -1644,30 +1642,31 @@ public:
uint8_t legend_colour = tbl->colour; uint8_t legend_colour = tbl->colour;
std::array<StringParameter, 2> params{};
switch (this->map_type) { switch (this->map_type) {
case SMT_INDUSTRY: case SMT_INDUSTRY:
/* Industry name must be formatted, since it's not in tiny font in the specs. /* Industry name must be formatted, since it's not in tiny font in the specs.
* So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */ * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */
SetDParam(0, tbl->legend); params[0] = tbl->legend;
SetDParam(1, Industry::GetIndustryTypeCount(tbl->type)); params[1] = Industry::GetIndustryTypeCount(tbl->type);
if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) { if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) {
legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK; legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK;
} }
[[fallthrough]]; [[fallthrough]];
case SMT_LINKSTATS: case SMT_LINKSTATS:
SetDParam(0, tbl->legend); params[0] = tbl->legend;
[[fallthrough]]; [[fallthrough]];
case SMT_OWNER: case SMT_OWNER:
if (this->map_type != SMT_OWNER || tbl->company != CompanyID::Invalid()) { if (this->map_type != SMT_OWNER || tbl->company != CompanyID::Invalid()) {
if (this->map_type == SMT_OWNER) SetDParam(0, tbl->company); if (this->map_type == SMT_OWNER) params[0] = tbl->company;
if (!tbl->show_on_map) { if (!tbl->show_on_map) {
/* Simply draw the string, not the black border of the legend colour. /* Simply draw the string, not the black border of the legend colour.
* This will enforce the idea of the disabled item */ * This will enforce the idea of the disabled item */
DrawString(text, string, TC_GREY); DrawString(text, GetStringWithArgs(string, params), TC_GREY);
} else { } else {
DrawString(text, string, TC_BLACK); DrawString(text, GetStringWithArgs(string, params), TC_BLACK);
GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour
} }
break; break;
@ -1675,10 +1674,13 @@ public:
[[fallthrough]]; [[fallthrough]];
default: default:
if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP);
/* Anything that is not an industry or a company is using normal process */ /* Anything that is not an industry or a company is using normal process */
GfxFillRect(icon, PC_BLACK); GfxFillRect(icon, PC_BLACK);
DrawString(text, tbl->legend); if (this->map_type == SMT_CONTOUR) {
DrawString(text, GetString(tbl->legend, tbl->height * TILE_HEIGHT_STEP));
} else {
DrawString(text, tbl->legend);
}
break; break;
} }
GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), legend_colour); // Legend colour GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), legend_colour); // Legend colour