1
0
Fork 0

Codechange: Use parameterised GetString() for cheat window.

pull/13696/head
Peter Nelson 2025-03-01 23:41:28 +00:00 committed by Peter Nelson
parent 382d30dbb2
commit 4389321623
1 changed files with 15 additions and 15 deletions

View File

@ -280,12 +280,13 @@ struct CheatWindow : Window {
for (int i = 0; i != lengthof(_cheats_ui); i++) { for (int i = 0; i != lengthof(_cheats_ui); i++) {
const CheatEntry *ce = &_cheats_ui[i]; const CheatEntry *ce = &_cheats_ui[i];
std::string str;
switch (ce->type) { switch (ce->type) {
case SLE_BOOL: { case SLE_BOOL: {
bool on = (*(bool*)ce->variable); bool on = (*(bool*)ce->variable);
DrawBoolButton(button_left, y + button_y_offset, on, true); DrawBoolButton(button_left, y + button_y_offset, on, true);
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF); str = GetString(ce->str, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
break; break;
} }
@ -297,23 +298,27 @@ struct CheatWindow : Window {
switch (ce->str) { switch (ce->str) {
/* Display date for change date cheat */ /* Display date for change date cheat */
case STR_CHEAT_CHANGE_DATE: SetDParam(0, TimerGameCalendar::date); break; case STR_CHEAT_CHANGE_DATE:
str = GetString(ce->str, TimerGameCalendar::date);
break;
/* Draw coloured flag for change company cheat */ /* Draw coloured flag for change company cheat */
case STR_CHEAT_CHANGE_COMPANY: { case STR_CHEAT_CHANGE_COMPANY: {
SetDParam(0, val + 1);
uint offset = WidgetDimensions::scaled.hsep_indent + GetStringBoundingBox(ce->str).width; uint offset = WidgetDimensions::scaled.hsep_indent + GetStringBoundingBox(ce->str).width;
DrawCompanyIcon(_local_company, rtl ? text_right - offset - WidgetDimensions::scaled.hsep_indent : text_left + offset, y + icon_y_offset); DrawCompanyIcon(_local_company, rtl ? text_right - offset - WidgetDimensions::scaled.hsep_indent : text_left + offset, y + icon_y_offset);
str = GetString(ce->str, val + 1);
break; break;
} }
default: SetDParam(0, val); default:
str = GetString(ce->str, val);
break;
} }
break; break;
} }
} }
DrawString(text_left, text_right, y + text_y_offset, ce->str); DrawString(text_left, text_right, y + text_y_offset, str);
y += this->line_height; y += this->line_height;
} }
@ -375,29 +380,24 @@ struct CheatWindow : Window {
for (const auto &ce : _cheats_ui) { for (const auto &ce : _cheats_ui) {
switch (ce.type) { switch (ce.type) {
case SLE_BOOL: case SLE_BOOL:
SetDParam(0, STR_CONFIG_SETTING_ON); width = std::max(width, GetStringBoundingBox(GetString(ce.str, STR_CONFIG_SETTING_ON)).width);
width = std::max(width, GetStringBoundingBox(ce.str).width); width = std::max(width, GetStringBoundingBox(GetString(ce.str, STR_CONFIG_SETTING_OFF)).width);
SetDParam(0, STR_CONFIG_SETTING_OFF);
width = std::max(width, GetStringBoundingBox(ce.str).width);
break; break;
default: default:
switch (ce.str) { switch (ce.str) {
/* Display date for change date cheat */ /* Display date for change date cheat */
case STR_CHEAT_CHANGE_DATE: case STR_CHEAT_CHANGE_DATE:
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 11, 31)); width = std::max(width, GetStringBoundingBox(GetString(ce.str, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 11, 31))).width);
width = std::max(width, GetStringBoundingBox(ce.str).width);
break; break;
/* Draw coloured flag for change company cheat */ /* Draw coloured flag for change company cheat */
case STR_CHEAT_CHANGE_COMPANY: case STR_CHEAT_CHANGE_COMPANY:
SetDParamMaxValue(0, MAX_COMPANIES); width = std::max(width, GetStringBoundingBox(GetString(ce.str, MAX_COMPANIES)).width + WidgetDimensions::scaled.hsep_wide);
width = std::max(width, GetStringBoundingBox(ce.str).width + WidgetDimensions::scaled.hsep_wide);
break; break;
default: default:
SetDParam(0, INT64_MAX); width = std::max(width, GetStringBoundingBox(GetString(ce.str, INT64_MAX)).width);
width = std::max(width, GetStringBoundingBox(ce.str).width);
break; break;
} }
break; break;