1
0
Fork 0

Codechange: Use parameterised GetString() for graph windows. (#13683)

pull/13685/head
Peter Nelson 2025-03-01 17:22:18 +00:00 committed by GitHub
parent e0e845fc4d
commit 1bd841b896
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 46 deletions

View File

@ -76,9 +76,7 @@ struct GraphLegendWindow : Window {
DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CenterBounds(ir.top, ir.bottom, d.height)); DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CenterBounds(ir.top, ir.bottom, d.height));
const Rect tr = ir.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl); const Rect tr = ir.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl);
SetDParam(0, cid); DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), GetString(STR_COMPANY_NAME_COMPANY_NUM, cid, cid), _legend_excluded_companies.Test(cid) ? TC_BLACK : TC_WHITE);
SetDParam(1, cid);
DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), STR_COMPANY_NAME_COMPANY_NUM, _legend_excluded_companies.Test(cid) ? TC_BLACK : TC_WHITE);
} }
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
@ -309,9 +307,7 @@ protected:
uint max_width = 0; uint max_width = 0;
for (int i = 0; i < (num_hori_lines + 1); i++) { for (int i = 0; i < (num_hori_lines + 1); i++) {
SetDParam(0, this->format_str_y_axis); Dimension d = GetStringBoundingBox(GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, y_label));
SetDParam(1, y_label);
Dimension d = GetStringBoundingBox(STR_GRAPH_Y_LABEL);
if (d.width > max_width) max_width = d.width; if (d.width > max_width) max_width = d.width;
y_label -= y_label_separation; y_label -= y_label_separation;
@ -412,9 +408,9 @@ protected:
y = r.top - GetCharacterHeight(FS_SMALL) / 2; y = r.top - GetCharacterHeight(FS_SMALL) / 2;
for (int i = 0; i < (num_hori_lines + 1); i++) { for (int i = 0; i < (num_hori_lines + 1); i++) {
SetDParam(0, this->format_str_y_axis); DrawString(r.left - label_width - ScaleGUITrad(4), r.left - ScaleGUITrad(4), y,
SetDParam(1, y_label); GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, y_label),
DrawString(r.left - label_width - ScaleGUITrad(4), r.left - ScaleGUITrad(4), y, STR_GRAPH_Y_LABEL, GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT); GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT);
y_label -= y_label_separation; y_label -= y_label_separation;
y += y_sep; y += y_sep;
@ -427,9 +423,9 @@ protected:
TimerGameEconomy::Month month = this->month; TimerGameEconomy::Month month = this->month;
TimerGameEconomy::Year year = this->year; TimerGameEconomy::Year year = this->year;
for (int i = 0; i < this->num_on_x_axis; i++) { for (int i = 0; i < this->num_on_x_axis; i++) {
SetDParam(0, STR_MONTH_ABBREV_JAN + month); DrawStringMultiLine(x, x + x_sep, y, this->height,
SetDParam(1, year); GetString(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + month, year),
DrawStringMultiLine(x, x + x_sep, y, this->height, month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, GRAPH_AXIS_LABEL_COLOUR, SA_LEFT); GRAPH_AXIS_LABEL_COLOUR, SA_LEFT);
month += this->month_increment; month += this->month_increment;
if (month >= 12) { if (month >= 12) {
@ -448,8 +444,7 @@ protected:
uint16_t label = this->x_values_start; uint16_t label = this->x_values_start;
for (int i = 0; i < this->num_on_x_axis; i++) { for (int i = 0; i < this->num_on_x_axis; i++) {
SetDParam(0, label); DrawString(x + 1, x + x_sep - 1, y, GetString(STR_GRAPH_Y_LABEL_NUMBER, label), GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
DrawString(x + 1, x + x_sep - 1, y, STR_GRAPH_Y_LABEL_NUMBER, GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
label += this->x_values_increment; label += this->x_values_increment;
x += x_sep; x += x_sep;
@ -564,9 +559,7 @@ public:
TimerGameEconomy::Month month = this->month; TimerGameEconomy::Month month = this->month;
TimerGameEconomy::Year year = this->year; TimerGameEconomy::Year year = this->year;
for (int i = 0; i < this->num_on_x_axis; i++) { for (int i = 0; i < this->num_on_x_axis; i++) {
SetDParam(0, STR_MONTH_ABBREV_JAN + month); x_label_width = std::max(x_label_width, GetStringBoundingBox(GetString(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + month, year)).width);
SetDParam(1, year);
x_label_width = std::max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width);
month += this->month_increment; month += this->month_increment;
if (month >= 12) { if (month >= 12) {
@ -576,13 +569,11 @@ public:
} }
} else { } else {
/* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */ /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */
SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL); uint64_t max_value = GetParamMaxValue(this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL);
x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width; x_label_width = GetStringBoundingBox(GetString(STR_GRAPH_Y_LABEL_NUMBER, max_value)).width;
} }
SetDParam(0, this->format_str_y_axis); uint y_label_width = GetStringBoundingBox(GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, INT64_MAX)).width;
SetDParam(1, INT64_MAX);
uint y_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL).width;
size.width = std::max<uint>(size.width, ScaleGUITrad(5) + y_label_width + this->num_vert_lines * (x_label_width + ScaleGUITrad(5)) + ScaleGUITrad(9)); size.width = std::max<uint>(size.width, ScaleGUITrad(5) + y_label_width + this->num_vert_lines * (x_label_width + ScaleGUITrad(5)) + ScaleGUITrad(9));
size.height = std::max<uint>(size.height, ScaleGUITrad(5) + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->draw_dates ? 3 : 1)) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4)); size.height = std::max<uint>(size.height, ScaleGUITrad(5) + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->draw_dates ? 3 : 1)) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4));
@ -1072,8 +1063,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
size.height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical(); size.height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical();
for (const CargoSpec *cs : _sorted_standard_cargo_specs) { for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
SetDParam(0, cs->name); Dimension d = GetStringBoundingBox(GetString(STR_GRAPH_CARGO_PAYMENT_CARGO, cs->name));
Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field
d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.width += WidgetDimensions::scaled.framerect.Horizontal();
d.height += WidgetDimensions::scaled.framerect.Vertical(); d.height += WidgetDimensions::scaled.framerect.Vertical();
@ -1114,8 +1104,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
GfxFillRect(cargo.Shrink(WidgetDimensions::scaled.bevel), cs->legend_colour); GfxFillRect(cargo.Shrink(WidgetDimensions::scaled.bevel), cs->legend_colour);
/* Cargo name */ /* Cargo name */
SetDParam(0, cs->name); DrawString(text.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl), GetString(STR_GRAPH_CARGO_PAYMENT_CARGO, cs->name));
DrawString(text.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl), STR_GRAPH_CARGO_PAYMENT_CARGO);
line = line.Translate(0, this->line_height); line = line.Translate(0, this->line_height);
} }
@ -1300,11 +1289,9 @@ struct PerformanceRatingDetailWindow : Window {
for (uint i = SCORE_BEGIN; i < SCORE_END; i++) { for (uint i = SCORE_BEGIN; i < SCORE_END; i++) {
score_info_width = std::max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width); score_info_width = std::max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width);
} }
SetDParamMaxValue(0, 1000); score_info_width += GetStringBoundingBox(GetString(STR_JUST_COMMA, GetParamMaxValue(1000))).width + WidgetDimensions::scaled.hsep_wide;
score_info_width += GetStringBoundingBox(STR_JUST_COMMA).width + WidgetDimensions::scaled.hsep_wide;
SetDParamMaxValue(0, 100); this->bar_width = GetStringBoundingBox(GetString(STR_PERFORMANCE_DETAIL_PERCENT, GetParamMaxValue(100))).width + WidgetDimensions::scaled.hsep_indent * 2; // Wide bars!
this->bar_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_PERCENT).width + WidgetDimensions::scaled.hsep_indent * 2; // Wide bars!
/* At this number we are roughly at the max; it can become wider, /* At this number we are roughly at the max; it can become wider,
* but then you need at 1000 times more money. At that time you're * but then you need at 1000 times more money. At that time you're
@ -1326,9 +1313,7 @@ struct PerformanceRatingDetailWindow : Window {
* exchange rate is that high, 999 999 k is usually not enough anymore * exchange rate is that high, 999 999 k is usually not enough anymore
* to show the different currency numbers. */ * to show the different currency numbers. */
if (GetCurrency().rate < 1000) max /= GetCurrency().rate; if (GetCurrency().rate < 1000) max /= GetCurrency().rate;
SetDParam(0, max); uint score_detail_width = GetStringBoundingBox(GetString(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, max, max)).width;
SetDParam(1, max);
uint score_detail_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY).width;
size.width = WidgetDimensions::scaled.frametext.Horizontal() + score_info_width + WidgetDimensions::scaled.hsep_wide + this->bar_width + WidgetDimensions::scaled.hsep_wide + score_detail_width; size.width = WidgetDimensions::scaled.frametext.Horizontal() + score_info_width + WidgetDimensions::scaled.hsep_wide + this->bar_width + WidgetDimensions::scaled.hsep_wide + score_detail_width;
uint left = WidgetDimensions::scaled.frametext.left; uint left = WidgetDimensions::scaled.frametext.left;
@ -1385,8 +1370,7 @@ struct PerformanceRatingDetailWindow : Window {
DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type); DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
/* Draw the score */ /* Draw the score */
SetDParam(0, score); DrawString(this->score_info_left, this->score_info_right, text_top, GetString(STR_JUST_COMMA, score), TC_BLACK, SA_RIGHT);
DrawString(this->score_info_left, this->score_info_right, text_top, STR_JUST_COMMA, TC_BLACK, SA_RIGHT);
/* Calculate the %-bar */ /* Calculate the %-bar */
uint x = Clamp<int64_t>(val, 0, needed) * this->bar_width / needed; uint x = Clamp<int64_t>(val, 0, needed) * this->bar_width / needed;
@ -1402,26 +1386,24 @@ struct PerformanceRatingDetailWindow : Window {
if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone); if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone);
/* Draw it */ /* Draw it */
SetDParam(0, Clamp<int64_t>(val, 0, needed) * 100 / needed); DrawString(this->bar_left, this->bar_right, text_top, GetString(STR_PERFORMANCE_DETAIL_PERCENT, Clamp<int64_t>(val, 0, needed) * 100 / needed), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_HOR_CENTER);
/* SCORE_LOAN is inversed */ /* SCORE_LOAN is inversed */
if (score_type == SCORE_LOAN) val = needed - val; if (score_type == SCORE_LOAN) val = needed - val;
/* Draw the amount we have against what is needed /* Draw the amount we have against what is needed
* For some of them it is in currency format */ * For some of them it is in currency format */
SetDParam(0, val);
SetDParam(1, needed);
switch (score_type) { switch (score_type) {
case SCORE_MIN_PROFIT: case SCORE_MIN_PROFIT:
case SCORE_MIN_INCOME: case SCORE_MIN_INCOME:
case SCORE_MAX_INCOME: case SCORE_MAX_INCOME:
case SCORE_MONEY: case SCORE_MONEY:
case SCORE_LOAN: case SCORE_LOAN:
DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY); DrawString(this->score_detail_left, this->score_detail_right, text_top, GetString(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, val, needed));
break; break;
default: default:
DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT); DrawString(this->score_detail_left, this->score_detail_right, text_top, GetString(STR_PERFORMANCE_DETAIL_AMOUNT_INT, val, needed));
break;
} }
} }
@ -1559,8 +1541,7 @@ struct IndustryProductionGraphWindow : BaseGraphWindow {
if (!IsValidCargoType(p.cargo)) continue; if (!IsValidCargoType(p.cargo)) continue;
cs = CargoSpec::Get(p.cargo); cs = CargoSpec::Get(p.cargo);
SetDParam(0, cs->name); Dimension d = GetStringBoundingBox(GetString(STR_GRAPH_CARGO_PAYMENT_CARGO, cs->name));
Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field
d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.width += WidgetDimensions::scaled.framerect.Horizontal();
d.height += WidgetDimensions::scaled.framerect.Vertical(); d.height += WidgetDimensions::scaled.framerect.Vertical();
@ -1610,8 +1591,7 @@ struct IndustryProductionGraphWindow : BaseGraphWindow {
GfxFillRect(cargo.Shrink(WidgetDimensions::scaled.bevel), cs->legend_colour); GfxFillRect(cargo.Shrink(WidgetDimensions::scaled.bevel), cs->legend_colour);
/* Cargo name */ /* Cargo name */
SetDParam(0, cs->name); DrawString(text.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl), GetString(STR_GRAPH_CARGO_PAYMENT_CARGO, cs->name));
DrawString(text.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl), STR_GRAPH_CARGO_PAYMENT_CARGO);
line = line.Translate(0, this->line_height); line = line.Translate(0, this->line_height);
} }

View File

@ -611,7 +611,7 @@ STR_GRAPH_KEY_BUTTON :{BLACK}Key
STR_GRAPH_KEY_TOOLTIP :{BLACK}Show key to graphs STR_GRAPH_KEY_TOOLTIP :{BLACK}Show key to graphs
STR_GRAPH_X_LABEL_MONTH :{TINY_FONT}{STRING} STR_GRAPH_X_LABEL_MONTH :{TINY_FONT}{STRING}
STR_GRAPH_X_LABEL_MONTH_YEAR :{TINY_FONT}{STRING}{}{NUM} STR_GRAPH_X_LABEL_MONTH_YEAR :{TINY_FONT}{STRING}{}{NUM}
STR_GRAPH_Y_LABEL :{TINY_FONT}{STRING2} STR_GRAPH_Y_LABEL :{TINY_FONT}{STRING1}
STR_GRAPH_Y_LABEL_NUMBER :{TINY_FONT}{COMMA} STR_GRAPH_Y_LABEL_NUMBER :{TINY_FONT}{COMMA}
STR_GRAPH_OPERATING_PROFIT_CAPTION :{WHITE}Operating Profit Graph STR_GRAPH_OPERATING_PROFIT_CAPTION :{WHITE}Operating Profit Graph