Changeset - r28599:46f9a48fef86
[Not reviewed]
master
0 4 0
frosch - 10 months ago 2024-01-27 21:50:40
frosch@openttd.org
Codechange: Replace SF_GUI_NEGATIVE_IS_SPECIAL with a settings value callback.
4 files changed with 10 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/settings.cpp
Show inline comments
 
@@ -480,9 +480,6 @@ void IntSettingDesc::SetValueDParams(uin
 
	} 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));
 
		}
src/settings_internal.h
Show inline comments
 
@@ -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.
src/settings_table.cpp
Show inline comments
 
@@ -108,6 +108,13 @@ static void SettingsValueVelocityUnit(co
 
	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)
 
{
src/table/settings/company_settings.ini
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)