Codechange: Move settings string formatting into IntSettingDesc members.

This commit is contained in:
frosch
2024-01-27 21:07:07 +01:00
committed by frosch
parent a9d1078434
commit 022b9e92d2
3 changed files with 54 additions and 41 deletions

View File

@@ -447,6 +447,47 @@ size_t BoolSettingDesc::ParseValue(const char *str) const
return this->def;
}
/**
* Get the title of the setting.
* The string should include a {STRING2} to show the current value.
* @return The title string.
*/
StringID IntSettingDesc::GetTitle() const
{
return this->str;
}
/**
* Get the help text of the setting.
* @return The requested help text.
*/
StringID IntSettingDesc::GetHelp() const
{
return this->str_help;
}
/**
* Set the DParams for drawing the value of the setting.
* @param first_param First DParam to use
* @param value Setting value to set params for.
*/
void IntSettingDesc::SetValueDParams(uint first_param, int32_t value) const
{
if (this->IsBoolSetting()) {
SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
} else {
if ((this->flags & SF_GUI_DROPDOWN) != 0) {
SetDParam(first_param++, this->str_val - this->min + value);
} else if ((this->flags & SF_GUI_NEGATIVE_IS_SPECIAL) != 0) {
SetDParam(first_param++, this->str_val + ((value >= 0) ? 1 : 0));
value = abs(value);
} else {
SetDParam(first_param++, this->str_val + ((value == 0 && (this->flags & SF_GUI_0_IS_SPECIAL) != 0) ? 1 : 0));
}
SetDParam(first_param++, value);
}
}
/**
* Make the value valid and then write it to the setting.
* See #MakeValidValid and #Write for more details.