Codechange: Replace SF_GUI_NEGATIVE_IS_SPECIAL with a settings value callback.

This commit is contained in:
frosch 2024-01-27 22:50:40 +01:00 committed by frosch
parent 28c83089f6
commit 17dfc1a49a
4 changed files with 10 additions and 5 deletions

View File

@ -480,9 +480,6 @@ void IntSettingDesc::SetValueDParams(uint first_param, int32_t value) const
} 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));
}

View File

@ -16,7 +16,6 @@
enum SettingFlag : uint16_t {
SF_NONE = 0,
SF_GUI_0_IS_SPECIAL = 1 << 0, ///< A value of zero is possible and has a custom string (the one after "strval").
SF_GUI_NEGATIVE_IS_SPECIAL = 1 << 1, ///< A negative value has another string (the one after "strval").
SF_GUI_DROPDOWN = 1 << 2, ///< The value represents a limited number of string-options (internally integer) presented as dropdown.
SF_GUI_CURRENCY = 1 << 3, ///< The number represents money, so when reading value multiply by exchange rate.
SF_NETWORK_ONLY = 1 << 4, ///< This setting only applies to network games.

View File

@ -108,6 +108,13 @@ static void SettingsValueVelocityUnit(const IntSettingDesc &, uint first_param,
SetDParam(first_param, val);
}
/** A negative value has another string (the one after "strval"). */
static void SettingsValueAbsolute(const IntSettingDesc &sd, uint first_param, int32_t value)
{
SetDParam(first_param, sd.str_val + ((value >= 0) ? 1 : 0));
SetDParam(first_param + 1, abs(value));
}
/** Reposition the main toolbar as the setting changed. */
static void v_PositionMainToolbar(int32_t)
{

View File

@ -11,6 +11,7 @@
static void UpdateAllServiceInterval(int32_t new_value);
static bool CanUpdateServiceInterval(VehicleType type, int32_t &new_value);
static void UpdateServiceInterval(VehicleType type, int32_t new_value);
static void SettingsValueAbsolute(const IntSettingDesc &sd, uint first_param, int32_t value);
static const SettingVariant _company_settings_table[] = {
[post-amble]
@ -52,13 +53,14 @@ cat = SC_BASIC
[SDT_VAR]
var = engine_renew_months
type = SLE_INT16
flags = SF_PER_COMPANY | SF_GUI_NEGATIVE_IS_SPECIAL
flags = SF_PER_COMPANY
def = 6
min = -12
max = 12
str = STR_CONFIG_SETTING_AUTORENEW_MONTHS
strhelp = STR_CONFIG_SETTING_AUTORENEW_MONTHS_HELPTEXT
strval = STR_CONFIG_SETTING_AUTORENEW_MONTHS_VALUE_BEFORE
val_cb = SettingsValueAbsolute
[SDT_VAR]
var = engine_renew_money