OpenTTD Source
12.0-beta2
|
Base integer type, including boolean, settings. More...
#include <settings_internal.h>
Public Types | |
typedef bool | PreChangeCheck(int32 &value) |
A check to be performed before the setting gets changed. More... | |
typedef void | PostChangeCallback(int32 value) |
A callback to denote that a setting has been changed. More... | |
Public Member Functions | |
IntSettingDesc (SaveLoad save, SettingFlag flags, bool startup, int32 def, int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) | |
virtual bool | IsBoolSetting () const |
Check whether this setting is a boolean type setting. More... | |
bool | IsIntSetting () const override |
Check whether this setting is an integer type setting. More... | |
void | ChangeValue (const void *object, int32 newvalue) const |
Handle changing a value. More... | |
void | MakeValueValidAndWrite (const void *object, int32 value) const |
Make the value valid and then write it to the setting. More... | |
virtual size_t | ParseValue (const char *str) const |
Convert a string representation (external) of an integer-like setting to an integer. More... | |
void | FormatValue (char *buf, const char *last, const void *object) const override |
Format the value of the setting associated with this object. More... | |
void | ParseValue (const IniItem *item, void *object) const override |
Parse/read the value from the Ini item into the setting associated with this object. More... | |
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. More... | |
int32 | Read (const void *object) const |
Read the integer from the the actual setting. More... | |
![]() | |
SettingDesc (SaveLoad save, SettingFlag flags, bool startup) | |
bool | IsEditable (bool do_command=false) const |
Check whether the setting is editable in the current gamemode. More... | |
SettingType | GetType () const |
Return the type of the setting. More... | |
constexpr const std::string & | GetName () const |
Get the name of this setting. More... | |
virtual bool | IsStringSetting () const |
Check whether this setting is an string type setting. More... | |
const struct IntSettingDesc * | AsIntSetting () const |
Get the setting description of this setting as an integer setting. More... | |
const struct StringSettingDesc * | AsStringSetting () const |
Get the setting description of this setting as a string setting. More... | |
Data Fields | |
int32 | def |
default value given when none is present | |
int32 | min |
minimum values | |
uint32 | max |
maximum values | |
int32 | 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. | |
![]() | |
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 &value) const |
Make the value valid given the limitations of this setting. More... | |
void | Write (const void *object, int32 value) const |
Set the value of a setting. More... | |
Base integer type, including boolean, settings.
Only these are shown in the settings UI.
Definition at line 136 of file settings_internal.h.
typedef void IntSettingDesc::PostChangeCallback(int32 value) |
A callback to denote that a setting has been changed.
The | new value for the setting. |
Definition at line 150 of file settings_internal.h.
typedef bool IntSettingDesc::PreChangeCheck(int32 &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 145 of file settings_internal.h.
void IntSettingDesc::ChangeValue | ( | const void * | object, |
int32 | 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 1364 of file settings.cpp.
References SettingDesc::flags, GamelogSetting(), GamelogStartAction(), GamelogStopAction(), SettingDesc::GetName(), GLAT_SETTING, MakeValueValid(), post_callback, pre_check, Read(), SetWindowClassesDirty(), SF_NO_NETWORK, WC_GAME_OPTIONS, and Write().
Referenced by CmdChangeCompanySetting(), and CmdChangeSetting().
|
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 ManyOfManySettingDesc, OneOfManySettingDesc, and BoolSettingDesc.
Definition at line 678 of file settings.cpp.
|
inlinevirtual |
Check whether this setting is a boolean type setting.
Reimplemented in BoolSettingDesc.
Definition at line 175 of file settings_internal.h.
Referenced by SettingEntry::SetValueDParams().
|
inlineoverridevirtual |
Check whether this setting is an integer type setting.
Reimplemented from SettingDesc.
Definition at line 176 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 690 of file settings.cpp.
|
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 449 of file settings.cpp.
References SaveLoad::conv, GetVarMemType(), SettingDesc::save, and SLE_VAR_NULL.
Referenced by ChangeValue(), and MakeValueValidAndWrite().
void IntSettingDesc::MakeValueValidAndWrite | ( | const void * | object, |
int32 | 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 434 of file settings.cpp.
References MakeValueValid(), and Write().
Referenced by LoadSettings(), and ParseValue().
|
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 ManyOfManySettingDesc, OneOfManySettingDesc, and BoolSettingDesc.
Definition at line 371 of file settings.cpp.
References _settings_error_list, def, SettingDesc::GetName(), ErrorMessageData::SetDParamStr(), and str.
Referenced by 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 603 of file settings.cpp.
References def, MakeValueValidAndWrite(), ParseValue(), and IniItem::value.
int32 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 513 of file settings.cpp.
References SaveLoad::conv, GetVariableAddress(), ReadValue(), and SettingDesc::save.
Referenced by ChangeValue(), BoolSettingDesc::FormatValue(), NewsTypeData::GetDisplay(), and LoadSettings().
|
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 502 of file settings.cpp.
References SaveLoad::conv, GetVariableAddress(), SettingDesc::save, and WriteValue().
Referenced by ChangeValue(), and MakeValueValidAndWrite().