Skip to content

Commit

Permalink
Codechange: Replace SF_GUI_NEGATIVE_IS_SPECIAL with a settings value …
Browse files Browse the repository at this point in the history
…callback.
  • Loading branch information
frosch123 committed Jan 28, 2024
1 parent 28c8308 commit 17dfc1a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 0 additions & 1 deletion src/settings_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/settings_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/table/settings/company_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 17dfc1a

Please sign in to comment.