OpenTTD Source 20241224-master-gf74b0cf984
|
Base integer type, including boolean, settings. More...
#include <settings_internal.h>
Public Types | |
typedef StringID | GetTitleCallback(const IntSettingDesc &sd) |
typedef StringID | GetHelpCallback(const IntSettingDesc &sd) |
typedef void | SetValueDParamsCallback(const IntSettingDesc &sd, uint first_param, int32_t value) |
typedef bool | PreChangeCheck(int32_t &value) |
A check to be performed before the setting gets changed. | |
typedef void | PostChangeCallback(int32_t value) |
A callback to denote that a setting has been changed. | |
typedef int32_t | GetDefaultValueCallback() |
A callback to get the correct default value. | |
Public Member Functions | |
template<typename Tdef , typename Tmin , typename Tmax , typename Tinterval , std::enable_if_t< std::disjunction_v< std::is_convertible< Tdef, int32_t >, std::is_base_of< StrongTypedefBase, Tdef > >, int > = 0, std::enable_if_t< std::disjunction_v< std::is_convertible< Tmin, int32_t >, std::is_base_of< StrongTypedefBase, Tmin > >, int > = 0, std::enable_if_t< std::disjunction_v< std::is_convertible< Tmax, uint32_t >, std::is_base_of< StrongTypedefBase, Tmax > >, int > = 0, std::enable_if_t< std::disjunction_v< std::is_convertible< Tinterval, int32_t >, std::is_base_of< StrongTypedefBase, Tinterval > >, int > = 0> | |
IntSettingDesc (const SaveLoad &save, SettingFlag flags, bool startup, Tdef def, Tmin min, Tmax max, Tinterval interval, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback, GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, SetValueDParamsCallback set_value_dparams_cb, GetDefaultValueCallback get_def_cb) | |
StringID | GetTitle () const |
Get the title of the setting. | |
StringID | GetHelp () const |
Get the help text of the setting. | |
void | SetValueDParams (uint first_param, int32_t value) const |
Set the DParams for drawing the value of the setting. | |
virtual bool | IsBoolSetting () const |
Check whether this setting is a boolean type setting. | |
bool | IsIntSetting () const override |
Check whether this setting is an integer type setting. | |
void | ChangeValue (const void *object, int32_t newvalue) const |
Handle changing a value. | |
void | MakeValueValidAndWrite (const void *object, int32_t value) const |
Make the value valid and then write it to the setting. | |
virtual size_t | ParseValue (const char *str) const |
Convert a string representation (external) of an integer-like setting to an integer. | |
std::string | FormatValue (const void *object) const override |
Format the value of the setting associated with this object. | |
void | ParseValue (const IniItem *item, void *object) const override |
Parse/read the value from the Ini item into the setting associated with this object. | |
bool | IsSameValue (const IniItem *item, void *object) const override |
Check whether the value in the Ini item is the same as is saved in this setting in the object. | |
bool | IsDefaultValue (void *object) const override |
Check whether the value is the same as the default value. | |
void | ResetToDefault (void *object) const override |
Reset the setting to its default value. | |
int32_t | Read (const void *object) const |
Read the integer from the the actual setting. | |
Public Member Functions inherited from SettingDesc | |
SettingDesc (const SaveLoad &save, SettingFlag flags, bool startup) | |
bool | IsEditable (bool do_command=false) const |
Check whether the setting is editable in the current gamemode. | |
SettingType | GetType () const |
Return the type of the setting. | |
constexpr const std::string & | GetName () const |
Get the name of this setting. | |
virtual bool | IsStringSetting () const |
Check whether this setting is an string type setting. | |
const struct IntSettingDesc * | AsIntSetting () const |
Get the setting description of this setting as an integer setting. | |
const struct StringSettingDesc * | AsStringSetting () const |
Get the setting description of this setting as a string setting. | |
Data Fields | |
int32_t | def |
default value given when none is present | |
int32_t | min |
minimum values | |
uint32_t | max |
maximum values | |
int32_t | interval |
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dynamically determined | |
StringID | str |
(translated) string with descriptive text; gui and console | |
StringID | str_help |
(Translated) string with help text; gui only. | |
StringID | str_val |
(Translated) first string describing the value. | |
SettingCategory | cat |
assigned categories of the setting | |
PreChangeCheck * | pre_check |
Callback to check for the validity of the setting. | |
PostChangeCallback * | post_callback |
Callback when the setting has been changed. | |
GetTitleCallback * | get_title_cb |
GetHelpCallback * | get_help_cb |
SetValueDParamsCallback * | set_value_dparams_cb |
GetDefaultValueCallback * | get_def_cb |
Callback to set the correct default value. | |
Data Fields inherited from SettingDesc | |
SettingFlag | flags |
Handles how a setting would show up in the GUI (text/currency, etc.). | |
bool | startup |
Setting has to be loaded directly at startup?. | |
SaveLoad | save |
Internal structure (going to savegame, parts to config). | |
Private Member Functions | |
void | MakeValueValid (int32_t &value) const |
Make the value valid given the limitations of this setting. | |
void | Write (const void *object, int32_t value) const |
Set the value of a setting. | |
Base integer type, including boolean, settings.
Only these are shown in the settings UI.
Definition at line 148 of file settings_internal.h.
typedef int32_t IntSettingDesc::GetDefaultValueCallback() |
A callback to get the correct default value.
For example a default that can be measured in time units or expressed as a percentage.
Definition at line 172 of file settings_internal.h.
typedef StringID IntSettingDesc::GetHelpCallback(const IntSettingDesc &sd) |
Definition at line 150 of file settings_internal.h.
typedef StringID IntSettingDesc::GetTitleCallback(const IntSettingDesc &sd) |
Definition at line 149 of file settings_internal.h.
typedef void IntSettingDesc::PostChangeCallback(int32_t value) |
A callback to denote that a setting has been changed.
The | new value for the setting. |
Definition at line 166 of file settings_internal.h.
typedef bool IntSettingDesc::PreChangeCheck(int32_t &value) |
A check to be performed before the setting gets changed.
The passed integer may be changed by the check if that is important, for example to remove some unwanted bit. The return value denotes whether the value, potentially after the changes, is allowed to be used/set in the configuration.
value | The prospective new value for the setting. |
Definition at line 161 of file settings_internal.h.
typedef void IntSettingDesc::SetValueDParamsCallback(const IntSettingDesc &sd, uint first_param, int32_t value) |
Definition at line 151 of file settings_internal.h.
|
inline |
Definition at line 184 of file settings_internal.h.
void IntSettingDesc::ChangeValue | ( | const void * | object, |
int32_t | newval | ||
) | const |
Handle changing a value.
This performs validation of the input value and calls the appropriate callbacks, and saves it when the value is changed.
object | The object the setting is in. |
newval | The new value for the setting. |
Definition at line 1588 of file settings.cpp.
References _gamelog, SettingDesc::flags, SettingDesc::GetName(), GLAT_SETTING, MakeValueValid(), post_callback, pre_check, Read(), SaveToConfig(), Gamelog::Setting(), SetWindowClassesDirty(), SF_NO_NETWORK, Gamelog::StartAction(), Gamelog::StopAction(), WC_GAME_OPTIONS, and Write().
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), and SetSettingValue().
|
overridevirtual |
Format the value of the setting associated with this object.
buf | The before of the buffer to format into. |
last | The end of the buffer to format into. |
object | The object the setting is in. |
Implements SettingDesc.
Reimplemented in OneOfManySettingDesc, and ManyOfManySettingDesc.
Definition at line 725 of file settings.cpp.
References SaveLoad::conv, Read(), and SettingDesc::save.
StringID IntSettingDesc::GetHelp | ( | ) | const |
Get the help text of the setting.
Definition at line 450 of file settings.cpp.
References str_help.
Referenced by SettingEntry::GetMaxHelpHeight(), and SettingEntry::UpdateFilterState().
StringID IntSettingDesc::GetTitle | ( | ) | const |
Get the title of the setting.
The string should include a {STRING2} to show the current value.
Definition at line 441 of file settings.cpp.
References str.
Referenced by SettingEntry::DrawSetting(), and SettingEntry::UpdateFilterState().
|
inlinevirtual |
Check whether this setting is a boolean type setting.
Reimplemented in BoolSettingDesc.
Definition at line 242 of file settings_internal.h.
Referenced by SettingEntry::DrawSetting(), and SetValueDParams().
|
overridevirtual |
Check whether the value is the same as the default value.
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 749 of file settings.cpp.
|
inlineoverridevirtual |
Check whether this setting is an integer type setting.
Reimplemented from SettingDesc.
Definition at line 243 of file settings_internal.h.
|
overridevirtual |
Check whether the value in the Ini item is the same as is saved in this setting in the object.
It might be that determining whether the value is the same is way more expensive than just writing the value. In those cases this function may unconditionally return false even though the value might be the same as in the Ini item.
item | The Ini item with the content of this setting. |
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 742 of file settings.cpp.
References ParseValue(), Read(), and IniItem::value.
|
private |
Make the value valid given the limitations of this setting.
In the case of int settings this is ensuring the value is between the minimum and maximum value, with a special case for 0 if SF_GUI_0_IS_SPECIAL is set. This is generally done by clamping the value so it is within the allowed value range. However, for SF_GUI_DROPDOWN the default is used when the value is not valid.
val | The value to make valid. |
Definition at line 497 of file settings.cpp.
References Clamp(), ClampU(), SaveLoad::conv, def, SettingDesc::flags, GetVarMemType(), max, min, SettingDesc::save, SF_GUI_0_IS_SPECIAL, SF_GUI_DROPDOWN, and SLE_VAR_NULL.
Referenced by ChangeValue(), and MakeValueValidAndWrite().
void IntSettingDesc::MakeValueValidAndWrite | ( | const void * | object, |
int32_t | val | ||
) | const |
Make the value valid and then write it to the setting.
See #MakeValidValid and Write for more details.
object | The object the setting is to be saved in. |
val | Signed version of the new value. |
Definition at line 482 of file settings.cpp.
References MakeValueValid(), and Write().
Referenced by HandleOldDiffCustom(), LoadSettings(), ParseValue(), and SetDefaultCompanySettings().
|
virtual |
Convert a string representation (external) of an integer-like setting to an integer.
str | Input string that will be parsed based on the type of desc. |
Reimplemented in BoolSettingDesc, OneOfManySettingDesc, and ManyOfManySettingDesc.
Definition at line 379 of file settings.cpp.
References _settings_error_list, def, SettingDesc::GetName(), ErrorMessageData::SetDParamStr(), and str.
Referenced by IsSameValue(), and ParseValue().
|
overridevirtual |
Parse/read the value from the Ini item into the setting associated with this object.
item | The Ini item with the content of this setting. |
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 655 of file settings.cpp.
References def, MakeValueValidAndWrite(), ParseValue(), and IniItem::value.
int32_t IntSettingDesc::Read | ( | const void * | object | ) | const |
Read the integer from the the actual setting.
object | The object the setting is to be saved in. |
Definition at line 561 of file settings.cpp.
References SaveLoad::conv, GetVariableAddress(), ReadValue(), and SettingDesc::save.
Referenced by ChangeValue(), SettingEntry::DrawSetting(), FormatValue(), BoolSettingDesc::FormatValue(), OneOfManySettingDesc::FormatValue(), ManyOfManySettingDesc::FormatValue(), NewsTypeData::GetDisplay(), IsDefaultValue(), IsSameValue(), SettingEntry::IsVisibleByRestrictionMode(), LoadSettings(), and SyncCompanySettings().
|
overridevirtual |
Reset the setting to its default value.
Implements SettingDesc.
Definition at line 755 of file settings.cpp.
void IntSettingDesc::SetValueDParams | ( | uint | first_param, |
int32_t | value | ||
) | const |
Set the DParams for drawing the value of the setting.
first_param | First DParam to use |
value | Setting value to set params for. |
Definition at line 460 of file settings.cpp.
References SettingDesc::flags, IsBoolSetting(), min, SetDParam(), SF_GUI_0_IS_SPECIAL, SF_GUI_DROPDOWN, and str_val.
Referenced by SettingEntry::DrawSetting().
|
private |
Set the value of a setting.
object | The object the setting is to be saved in. |
val | Signed version of the new value. |
Definition at line 550 of file settings.cpp.
References SaveLoad::conv, GetVariableAddress(), SettingDesc::save, and WriteValue().
Referenced by ChangeValue(), MakeValueValidAndWrite(), and ResetToDefault().
SettingCategory IntSettingDesc::cat |
assigned categories of the setting
Definition at line 226 of file settings_internal.h.
Referenced by SettingEntry::IsVisibleByRestrictionMode().
int32_t IntSettingDesc::def |
default value given when none is present
Definition at line 219 of file settings_internal.h.
Referenced by IsDefaultValue(), SettingEntry::IsVisibleByRestrictionMode(), MakeValueValid(), ParseValue(), BoolSettingDesc::ParseValue(), OneOfManySettingDesc::ParseValue(), ManyOfManySettingDesc::ParseValue(), ParseValue(), ResetToDefault(), and SetDefaultCompanySettings().
GetDefaultValueCallback* IntSettingDesc::get_def_cb |
Callback to set the correct default value.
Definition at line 232 of file settings_internal.h.
GetHelpCallback* IntSettingDesc::get_help_cb |
Definition at line 230 of file settings_internal.h.
GetTitleCallback* IntSettingDesc::get_title_cb |
Definition at line 229 of file settings_internal.h.
int32_t IntSettingDesc::interval |
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dynamically determined
Definition at line 222 of file settings_internal.h.
uint32_t IntSettingDesc::max |
maximum values
Definition at line 221 of file settings_internal.h.
Referenced by SettingEntry::DrawSetting(), IConsoleGetSetting(), and MakeValueValid().
int32_t IntSettingDesc::min |
minimum values
Definition at line 220 of file settings_internal.h.
Referenced by SettingEntry::DrawSetting(), IConsoleGetSetting(), MakeValueValid(), and SetValueDParams().
PostChangeCallback* IntSettingDesc::post_callback |
Callback when the setting has been changed.
Definition at line 228 of file settings_internal.h.
Referenced by ChangeValue().
PreChangeCheck* IntSettingDesc::pre_check |
Callback to check for the validity of the setting.
Definition at line 227 of file settings_internal.h.
Referenced by ChangeValue().
SetValueDParamsCallback* IntSettingDesc::set_value_dparams_cb |
Definition at line 231 of file settings_internal.h.
StringID IntSettingDesc::str |
(translated) string with descriptive text; gui and console
Definition at line 223 of file settings_internal.h.
Referenced by GetTitle(), BoolSettingDesc::ParseSingleValue(), OneOfManySettingDesc::ParseSingleValue(), ParseValue(), BoolSettingDesc::ParseValue(), OneOfManySettingDesc::ParseValue(), ManyOfManySettingDesc::ParseValue(), and SettingTitleWallclock().
StringID IntSettingDesc::str_help |
(Translated) string with help text; gui only.
Definition at line 224 of file settings_internal.h.
Referenced by GetHelp(), and SettingHelpWallclock().
StringID IntSettingDesc::str_val |
(Translated) first string describing the value.
Definition at line 225 of file settings_internal.h.
Referenced by ServiceIntervalSettingsValueText(), SettingsValueAbsolute(), and SetValueDParams().