OpenTTD Source: IntSettingDesc Struct Reference

OpenTTD Source 12.0-beta1

Public Types | Public Member Functions | Data Fields | Private Member Functions
IntSettingDesc Struct Reference

Base integer type, including boolean, settings. More...

`#include <settings_internal.h>`

Inheritance diagram for IntSettingDesc:

## 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...
Public Member Functions inherited from SettingDesc
| 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.
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 &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...

## Detailed Description

Base integer type, including boolean, settings.

Only these are shown in the settings UI.

Definition at line 136 of file settings_internal.h.

## Member Typedef Documentation

## ◆ PostChangeCallback

typedef void IntSettingDesc::PostChangeCallback(int32 value)

A callback to denote that a setting has been changed.

Parameters

  The | new value for the setting.

Definition at line 150 of file settings_internal.h.

## ◆ PreChangeCheck

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.

Parameters

  value | The prospective new value for the setting.

Returns
  True when the setting is accepted.

Definition at line 145 of file settings_internal.h.

## Member Function Documentation

## ◆ ChangeValue()

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.

Parameters

  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().

## ◆ FormatValue()

void IntSettingDesc::FormatValue | ( | char * | buf,
|  | const char * | last,
|  | const void * | object
| ) |  | const
| overridevirtual

Format the value of the setting associated with this object.

Parameters

  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.

## ◆ IsBoolSetting()

virtual bool IntSettingDesc::IsBoolSetting | ( |  | ) | const
| inlinevirtual

Check whether this setting is a boolean type setting.

Returns
  True when the underlying type is an integer.

Reimplemented in BoolSettingDesc.

Definition at line 175 of file settings_internal.h.

Referenced by SettingEntry::SetValueDParams().

## ◆ IsIntSetting()

bool IntSettingDesc::IsIntSetting | ( |  | ) | const
| inlineoverridevirtual

Check whether this setting is an integer type setting.

Returns
  True when the underlying type is an integer.

Reimplemented from SettingDesc.

Definition at line 176 of file settings_internal.h.

## ◆ IsSameValue()

bool IntSettingDesc::IsSameValue | ( | const IniItem * | item,
|  | void * | object
| ) |  | const
| 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.

Parameters

  item | The Ini item with the content of this setting.
  object | The object the setting is in.

Returns
  True if the value is definitely the same (might be false when the same).

Implements SettingDesc.

Definition at line 690 of file settings.cpp.

## ◆ MakeValueValid()

void IntSettingDesc::MakeValueValid | ( | int32 & | val | ) | const
| 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.

Parameters

  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().

## ◆ 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.

Parameters

  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().

## ◆ ParseValue() [1/2]

size_t IntSettingDesc::ParseValue | ( | const char * | str | ) | const
| virtual

Convert a string representation (external) of an integer-like setting to an integer.

Parameters

  str | Input string that will be parsed based on the type of desc.

Returns
  The value from the parse string, or the default value of the setting.

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().

## ◆ ParseValue() [2/2]

void IntSettingDesc::ParseValue | ( | const IniItem * | item,
|  | void * | object
| ) |  | const
| overridevirtual

Parse/read the value from the Ini item into the setting associated with this object.

Parameters

  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.

## ◆ Read()

int32 IntSettingDesc::Read | ( | const void * | object | ) | const

Read the integer from the the actual setting.

Parameters

  object | The object the setting is to be saved in.

Returns
  The value of the saved integer.

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().

## ◆ Write()

void IntSettingDesc::Write | ( | const void * | object,
|  | int32 | val
| ) |  | const
| private

Set the value of a setting.

Parameters

  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().

The documentation for this struct was generated from the following files:

- src/settings_internal.h
- src/settings.cpp