1
0
Fork 0

Codechange: Use parameterised GetString() for settings window. (#13695)

pull/13696/head
Peter Nelson 2025-03-02 07:29:00 +00:00 committed by GitHub
parent f360913ebf
commit 382d30dbb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 27 deletions

View File

@ -544,18 +544,15 @@ struct GameOptionsWindow : Window {
{
switch (widget) {
case WID_GO_BASE_GRF_DESCRIPTION:
SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r, STR_JUST_RAW_STRING, TC_BLACK);
DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())), TC_BLACK);
break;
case WID_GO_BASE_SFX_DESCRIPTION:
SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r, STR_JUST_RAW_STRING, TC_BLACK);
DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())), TC_BLACK);
break;
case WID_GO_BASE_MUSIC_DESCRIPTION:
SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r, STR_JUST_RAW_STRING, TC_BLACK);
DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())), TC_BLACK);
break;
case WID_GO_GUI_SCALE:
@ -563,8 +560,7 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_VIDEO_DRIVER_INFO:
SetDParamStr(0, std::string{VideoDriver::GetInstance()->GetInfoString()});
DrawStringMultiLine(r, STR_GAME_OPTIONS_VIDEO_DRIVER_INFO);
DrawStringMultiLine(r, GetString(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, std::string{VideoDriver::GetInstance()->GetInfoString()}));
break;
case WID_GO_BASE_SFX_VOLUME:
@ -603,30 +599,30 @@ struct GameOptionsWindow : Window {
NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_GRF_DESCRIPTION);
int y = 0;
for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
y = std::max(y, GetStringHeight(STR_JUST_RAW_STRING, wid->current_x));
std::string str = GetString(STR_JUST_RAW_STRING, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
y = std::max(y, GetStringHeight(str, wid->current_x));
}
changed |= wid->UpdateVerticalSize(y);
wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_SFX_DESCRIPTION);
y = 0;
for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
y = std::max(y, GetStringHeight(STR_JUST_RAW_STRING, wid->current_x));
std::string str = GetString(STR_JUST_RAW_STRING, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
y = std::max(y, GetStringHeight(str, wid->current_x));
}
changed |= wid->UpdateVerticalSize(y);
wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_MUSIC_DESCRIPTION);
y = 0;
for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
y = std::max(y, GetStringHeight(STR_JUST_RAW_STRING, wid->current_x));
std::string str = GetString(STR_JUST_RAW_STRING, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
y = std::max(y, GetStringHeight(str, wid->current_x));
}
changed |= wid->UpdateVerticalSize(y);
wid = this->GetWidget<NWidgetResizeBase>(WID_GO_VIDEO_DRIVER_INFO);
SetDParamStr(0, std::string{VideoDriver::GetInstance()->GetInfoString()});
y = GetStringHeight(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, wid->current_x);
std::string str = GetString(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, std::string{VideoDriver::GetInstance()->GetInfoString()});
y = GetStringHeight(str, wid->current_x);
changed |= wid->UpdateVerticalSize(y);
if (changed) this->ReInit(0, 0, this->flags.Test(WindowFlag::Centred));
@ -1292,8 +1288,7 @@ struct GameSettingsWindow : Window {
STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
};
for (const auto &setting_type : setting_types) {
SetDParam(0, setting_type);
size.width = std::max(size.width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width + padding.width);
size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_CONFIG_SETTING_TYPE, setting_type)).width + padding.width);
}
size.height = 2 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal +
std::max(size.height, GetSettingsTree().GetMaxHelpHeight(size.width));
@ -1337,8 +1332,9 @@ struct GameSettingsWindow : Window {
/* Draw the 'some search results are hidden' notice. */
if (this->warn_missing != WHR_NONE) {
SetDParam(0, _game_settings_restrict_dropdown[this->filter.min_cat]);
DrawStringMultiLine(panel.WithHeight(this->warn_lines * GetCharacterHeight(FS_NORMAL)), warn_str, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(panel.WithHeight(this->warn_lines * GetCharacterHeight(FS_NORMAL)),
GetString(warn_str, _game_settings_restrict_dropdown[this->filter.min_cat]),
TC_FROMSTRING, SA_CENTER);
}
}
@ -1402,13 +1398,14 @@ struct GameSettingsWindow : Window {
const IntSettingDesc *sd = this->last_clicked->setting;
Rect tr = r;
std::string str;
switch (sd->GetType()) {
case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
case ST_COMPANY: str = GetString(STR_CONFIG_SETTING_TYPE, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
case ST_CLIENT: str = GetString(STR_CONFIG_SETTING_TYPE, STR_CONFIG_SETTING_TYPE_CLIENT); break;
case ST_GAME: str = GetString(STR_CONFIG_SETTING_TYPE, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
default: NOT_REACHED();
}
DrawString(tr, STR_CONFIG_SETTING_TYPE);
DrawString(tr, str);
tr.top += GetCharacterHeight(FS_NORMAL);
auto [param1, param2] = sd->GetValueParams(sd->GetDefaultValue());
@ -1940,9 +1937,7 @@ struct CustomCurrencyWindow : Window {
/* Make sure the window is wide enough for the widest exchange rate */
case WID_CC_RATE:
SetDParam(0, 1);
SetDParam(1, INT32_MAX);
size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
size = GetStringBoundingBox(GetString(STR_CURRENCY_EXCHANGE_RATE, 1, INT32_MAX));
break;
}
}