1
0
Fork 0

Codechange: Use parameterised GetString() for goal, league and story windows. (#13662)

pull/13664/head
Peter Nelson 2025-02-25 22:55:06 +00:00 committed by GitHub
parent a8f56fe7b3
commit 31bd85b743
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 68 deletions

View File

@ -205,17 +205,15 @@ struct GoalListWindow : public Window {
switch (column) { switch (column) {
case GC_GOAL: { case GC_GOAL: {
/* Display the goal. */ /* Display the goal. */
SetDParamStr(0, s->text);
uint width_reduction = progress_col_width > 0 ? progress_col_width + WidgetDimensions::scaled.framerect.Horizontal() : 0; uint width_reduction = progress_col_width > 0 ? progress_col_width + WidgetDimensions::scaled.framerect.Horizontal() : 0;
DrawString(r.Indent(width_reduction, !rtl), STR_GOALS_TEXT); DrawString(r.Indent(width_reduction, !rtl), GetString(STR_GOALS_TEXT, s->text));
break; break;
} }
case GC_PROGRESS: case GC_PROGRESS:
if (!s->progress.empty()) { if (!s->progress.empty()) {
SetDParamStr(0, s->progress);
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS; StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
DrawString(r.WithWidth(progress_col_width, !rtl), str, TC_FROMSTRING, SA_RIGHT | SA_FORCE); DrawString(r.WithWidth(progress_col_width, !rtl), GetString(str, s->progress), TC_FROMSTRING, SA_RIGHT | SA_FORCE);
} }
break; break;
} }
@ -243,9 +241,8 @@ struct GoalListWindow : public Window {
uint max_width = 0; uint max_width = 0;
for (const Goal *s : Goal::Iterate()) { for (const Goal *s : Goal::Iterate()) {
if (!s->progress.empty()) { if (!s->progress.empty()) {
SetDParamStr(0, s->progress);
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS; StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
uint str_width = GetStringBoundingBox(str).width; uint str_width = GetStringBoundingBox(GetString(str, s->progress)).width;
if (str_width > max_width) max_width = str_width; if (str_width > max_width) max_width = str_width;
} }
} }
@ -392,16 +389,14 @@ struct GoalQuestionWindow : public Window {
{ {
if (widget != WID_GQ_QUESTION) return; if (widget != WID_GQ_QUESTION) return;
SetDParamStr(0, this->question); size.height = GetStringHeight(GetString(STR_JUST_RAW_STRING, this->question), size.width);
size.height = GetStringHeight(STR_JUST_RAW_STRING, size.width);
} }
void DrawWidget(const Rect &r, WidgetID widget) const override void DrawWidget(const Rect &r, WidgetID widget) const override
{ {
if (widget != WID_GQ_QUESTION) return; if (widget != WID_GQ_QUESTION) return;
SetDParamStr(0, this->question); DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, this->question), this->colour, SA_TOP | SA_HOR_CENTER);
DrawStringMultiLine(r, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
} }
}; };

View File

@ -116,15 +116,11 @@ public:
for (uint i = 0; i != this->companies.size(); i++) { for (uint i = 0; i != this->companies.size(); i++) {
const Company *c = this->companies[i]; const Company *c = this->companies[i];
SetDParam(0, i + 1); DrawString(ordinal.left, ordinal.right, ir.top + text_y_offset, GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, i + 1));
DrawString(ordinal.left, ordinal.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK);
DrawCompanyIcon(c->index, icon_left, ir.top + icon_y_offset); DrawCompanyIcon(c->index, icon_left, ir.top + icon_y_offset);
SetDParam(0, c->index); DrawString(text.left, text.right, ir.top + text_y_offset, GetString(STR_COMPANY_LEAGUE_COMPANY_NAME, c->index, c->index, GetPerformanceTitleFromValue(c->old_economy[0].performance_history)));
SetDParam(1, c->index);
SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
DrawString(text.left, text.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_NAME);
ir.top += this->line_height; ir.top += this->line_height;
} }
} }
@ -135,8 +131,7 @@ public:
this->ordinal_width = 0; this->ordinal_width = 0;
for (uint i = 0; i < MAX_COMPANIES; i++) { for (uint i = 0; i < MAX_COMPANIES; i++) {
SetDParam(0, i + 1); this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, i + 1)).width);
this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_RANK).width);
} }
this->ordinal_width += WidgetDimensions::scaled.hsep_wide; // Keep some extra spacing this->ordinal_width += WidgetDimensions::scaled.hsep_wide; // Keep some extra spacing
@ -154,10 +149,7 @@ public:
this->line_height = std::max<int>(this->icon.height + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL)); this->line_height = std::max<int>(this->icon.height + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL));
for (const Company *c : Company::Iterate()) { for (const Company *c : Company::Iterate()) {
SetDParam(0, c->index); widest_width = std::max(widest_width, GetStringBoundingBox(GetString(STR_COMPANY_LEAGUE_COMPANY_NAME, c->index, c->index, widest_title)).width);
SetDParam(1, c->index);
SetDParam(2, widest_title);
widest_width = std::max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
} }
this->text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing this->text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing
@ -325,8 +317,7 @@ public:
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
if (!lt->header.empty()) { if (!lt->header.empty()) {
SetDParamStr(0, lt->header); ir.top = DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, lt->header), TC_BLACK) + WidgetDimensions::scaled.vsep_wide;
ir.top = DrawStringMultiLine(ir, STR_JUST_RAW_STRING, TC_BLACK) + WidgetDimensions::scaled.vsep_wide;
} }
int icon_y_offset = (this->line_height - this->icon_size.height) / 2; int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
@ -341,20 +332,16 @@ public:
Rect score_rect = ir.Indent(this->rank_width + 2 * spacer + this->icon_size.width + this->text_width, rtl).WithWidth(this->score_width, rtl); Rect score_rect = ir.Indent(this->rank_width + 2 * spacer + this->icon_size.width + this->text_width, rtl).WithWidth(this->score_width, rtl);
for (const auto &[rank, lte] : this->rows) { for (const auto &[rank, lte] : this->rows) {
SetDParam(0, rank + 1); DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, rank + 1));
DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK);
if (this->icon_size.width > 0 && lte->company != CompanyID::Invalid()) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset); if (this->icon_size.width > 0 && lte->company != CompanyID::Invalid()) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
SetDParamStr(0, lte->text); DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, GetString(STR_JUST_RAW_STRING, lte->text), TC_BLACK);
DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK); DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, GetString(STR_JUST_RAW_STRING, lte->score), TC_BLACK, SA_RIGHT);
SetDParamStr(0, lte->score);
DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK, SA_RIGHT);
ir.top += this->line_height; ir.top += this->line_height;
} }
if (!lt->footer.empty()) { if (!lt->footer.empty()) {
ir.top += WidgetDimensions::scaled.vsep_wide; ir.top += WidgetDimensions::scaled.vsep_wide;
SetDParamStr(0, lt->footer); ir.top = DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, lt->footer), TC_BLACK);
ir.top = DrawStringMultiLine(ir, STR_JUST_RAW_STRING, TC_BLACK);
} }
} }
@ -372,12 +359,9 @@ public:
this->rank_width = this->text_width = this->score_width = 0; this->rank_width = this->text_width = this->score_width = 0;
bool show_icon_column = false; bool show_icon_column = false;
for (const auto &[rank, lte] : this->rows) { for (const auto &[rank, lte] : this->rows) {
SetDParam(0, rank + 1); this->rank_width = std::max(this->rank_width, GetStringBoundingBox(GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, rank + 1)).width);
this->rank_width = std::max(this->rank_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_RANK).width); this->text_width = std::max(this->text_width, GetStringBoundingBox(GetString(STR_JUST_RAW_STRING, lte->text)).width);
SetDParamStr(0, lte->text); this->score_width = std::max(this->score_width, GetStringBoundingBox(GetString(STR_JUST_RAW_STRING, lte->score)).width);
this->text_width = std::max(this->text_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
SetDParamStr(0, lte->score);
this->score_width = std::max(this->score_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
if (lte->company != CompanyID::Invalid()) show_icon_column = true; if (lte->company != CompanyID::Invalid()) show_icon_column = true;
} }
@ -395,16 +379,14 @@ public:
this->text_width = size.width - non_text_width; this->text_width = size.width - non_text_width;
if (!lt->header.empty()) { if (!lt->header.empty()) {
SetDParamStr(0, lt->header); this->header_height = GetStringHeight(GetString(STR_JUST_RAW_STRING, lt->header), size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
this->header_height = GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
size.height += header_height; size.height += header_height;
} else { } else {
this->header_height = 0; this->header_height = 0;
} }
if (!lt->footer.empty()) { if (!lt->footer.empty()) {
SetDParamStr(0, lt->footer); size.height += GetStringHeight(GetString(STR_JUST_RAW_STRING, lt->footer), size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
size.height += GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
} }
} }

View File

@ -285,8 +285,7 @@ protected:
/* Title lines */ /* Title lines */
height += GetCharacterHeight(FS_NORMAL); // Date always use exactly one line. height += GetCharacterHeight(FS_NORMAL); // Date always use exactly one line.
SetDParamStr(0, !page->title.empty() ? page->title : this->selected_generic_title); height += GetStringHeight(GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title : this->selected_generic_title), max_width);
height += GetStringHeight(STR_STORY_BOOK_TITLE, max_width);
return height; return height;
} }
@ -322,8 +321,7 @@ protected:
{ {
switch (pe.type) { switch (pe.type) {
case SPET_TEXT: case SPET_TEXT:
SetDParamStr(0, pe.text); return GetStringHeight(GetString(STR_JUST_RAW_STRING, pe.text), max_width);
return GetStringHeight(STR_JUST_RAW_STRING, max_width);
case SPET_GOAL: case SPET_GOAL:
case SPET_LOCATION: { case SPET_LOCATION: {
@ -513,7 +511,7 @@ protected:
* @param string_id The string id to draw. * @param string_id The string id to draw.
* @return the number of lines. * @return the number of lines.
*/ */
void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, StringID string_id = STR_JUST_RAW_STRING) const void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, const std::string &text) const
{ {
Dimension sprite_dim = GetSpriteSize(action_sprite); Dimension sprite_dim = GetSpriteSize(action_sprite);
uint element_height = std::max(sprite_dim.height, (uint)line_height); uint element_height = std::max(sprite_dim.height, (uint)line_height);
@ -522,7 +520,7 @@ protected:
uint text_top = y_offset + (element_height - line_height) / 2; uint text_top = y_offset + (element_height - line_height) / 2;
DrawSprite(action_sprite, PAL_NONE, 0, sprite_top); DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
DrawString(sprite_dim.width + WidgetDimensions::scaled.frametext.left, width, text_top, string_id, TC_BLACK); DrawString(sprite_dim.width + WidgetDimensions::scaled.frametext.left, width, text_top, text, TC_BLACK);
y_offset += element_height; y_offset += element_height;
} }
@ -697,14 +695,13 @@ public:
/* Date */ /* Date */
if (page->date != CalendarTime::INVALID_DATE) { if (page->date != CalendarTime::INVALID_DATE) {
SetDParam(0, page->date); DrawString(0, fr.right, y_offset, GetString(STR_JUST_DATE_LONG, page->date), TC_BLACK);
DrawString(0, fr.right, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
} }
y_offset += line_height; y_offset += line_height;
/* Title */ /* Title */
SetDParamStr(0, !page->title.empty() ? page->title : this->selected_generic_title); y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom,
y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER); GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title : this->selected_generic_title), TC_BLACK, SA_TOP | SA_HOR_CENTER);
/* Page elements */ /* Page elements */
this->EnsureStoryPageElementLayout(); this->EnsureStoryPageElementLayout();
@ -712,21 +709,20 @@ public:
y_offset = ce.bounds.top - scrollpos; y_offset = ce.bounds.top - scrollpos;
switch (ce.pe->type) { switch (ce.pe->type) {
case SPET_TEXT: case SPET_TEXT:
SetDParamStr(0, ce.pe->text); y_offset = DrawStringMultiLine(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos,
y_offset = DrawStringMultiLine(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos, STR_JUST_RAW_STRING, TC_BLACK, SA_TOP | SA_LEFT); GetString(STR_JUST_RAW_STRING, ce.pe->text), TC_BLACK, SA_TOP | SA_LEFT);
break; break;
case SPET_GOAL: { case SPET_GOAL: {
Goal *g = Goal::Get((GoalID) ce.pe->referenced_id); Goal *g = Goal::Get((GoalID) ce.pe->referenced_id);
StringID string_id = g == nullptr ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING; DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe),
if (g != nullptr) SetDParamStr(0, g->text); g == nullptr ? GetString(STR_STORY_BOOK_INVALID_GOAL_REF) : GetString(STR_JUST_RAW_STRING, g->text));
DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe), string_id);
break; break;
} }
case SPET_LOCATION: case SPET_LOCATION:
SetDParamStr(0, ce.pe->text); DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe),
DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe)); GetString(STR_JUST_RAW_STRING, ce.pe->text));
break; break;
case SPET_BUTTON_PUSH: case SPET_BUTTON_PUSH:
@ -738,8 +734,8 @@ public:
DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame); DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame);
SetDParamStr(0, ce.pe->text); DrawString(ce.bounds.left + WidgetDimensions::scaled.bevel.left, ce.bounds.right - WidgetDimensions::scaled.bevel.right, ce.bounds.top + tmargin - scrollpos,
DrawString(ce.bounds.left + WidgetDimensions::scaled.bevel.left, ce.bounds.right - WidgetDimensions::scaled.bevel.right, ce.bounds.top + tmargin - scrollpos, STR_JUST_RAW_STRING, TC_WHITE, SA_CENTER); GetString(STR_JUST_RAW_STRING, ce.pe->text), TC_WHITE, SA_CENTER);
break; break;
} }
@ -762,13 +758,7 @@ public:
/* Get max title width. */ /* Get max title width. */
for (size_t i = 0; i < this->story_pages.size(); i++) { for (size_t i = 0; i < this->story_pages.size(); i++) {
const StoryPage *s = this->story_pages[i]; const StoryPage *s = this->story_pages[i];
Dimension title_d = GetStringBoundingBox(GetString(STR_JUST_RAW_STRING, s->title.empty() ? this->selected_generic_title : s->title));
if (!s->title.empty()) {
SetDParamStr(0, s->title);
} else {
SetDParamStr(0, this->selected_generic_title);
}
Dimension title_d = GetStringBoundingBox(STR_JUST_RAW_STRING);
if (title_d.width > d.width) { if (title_d.width > d.width) {
d.width = title_d.width; d.width = title_d.width;