OpenTTD Source: IntSettingDesc Struct Reference

OpenTTD Source 15.3

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
using | GetTitleCallback = StringID(const IntSettingDesc &sd)
using | GetHelpCallback = StringID(const IntSettingDesc &sd)
using | GetValueParamsCallback = std::pair< StringParameter, StringParameter >(const IntSettingDesc &sd, int32_t value)
using | GetDefaultValueCallback = int32_t(const IntSettingDesc &sd)
using | GetRangeCallback = std::tuple< int32_t, uint32_t >(const IntSettingDesc &sd)
using | PreChangeCheck = bool(int32_t &value)
| A check to be performed before the setting gets changed.
using | PostChangeCallback = void(int32_t value)
| A callback to denote that a setting has been changed.

## Public Member Functions
template<ConvertibleThroughBaseOrTo< int32_t > Tdef, ConvertibleThroughBaseOrTo< int32_t > Tmin, ConvertibleThroughBaseOrTo< uint32_t > Tmax, ConvertibleThroughBaseOrTo< int32_t > Tinterval>
| IntSettingDesc (const SaveLoad &save, SettingFlags 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, GetValueParamsCallback get_value_params_cb, GetDefaultValueCallback get_def_cb, GetRangeCallback get_range_cb)
StringID | GetTitle () const
| Get the title of the setting.
StringID | GetHelp () const
| Get the help text of the setting.
std::pair< StringParameter, StringParameter > | GetValueParams (int32_t value) const
| Get parameters for drawing the value of the setting.
int32_t | GetDefaultValue () const
| Get the default value of the setting.
std::tuple< int32_t, uint32_t > | GetRange () const
| Get the min/max range for 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 int32_t | ParseValue (std::string_view 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, SettingFlags 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
GetValueParamsCallback * | get_value_params_cb
GetDefaultValueCallback * | get_def_cb
| Callback to set the correct default value.
GetRangeCallback * | get_range_cb
Data Fields inherited from SettingDesc
SettingFlags | 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.

## Detailed Description

Base integer type, including boolean, settings.

Only these are shown in the settings UI.

Definition at line 148 of file settings_internal.h.

## Member Typedef Documentation

## ◆ GetDefaultValueCallback

using IntSettingDesc::GetDefaultValueCallback = int32_t(const IntSettingDesc &sd)

Definition at line 152 of file settings_internal.h.

## ◆ GetHelpCallback

using IntSettingDesc::GetHelpCallback = StringID(const IntSettingDesc &sd)

Definition at line 150 of file settings_internal.h.

## ◆ GetRangeCallback

using IntSettingDesc::GetRangeCallback = std::tuple<int32_t, uint32_t>(const IntSettingDesc &sd)

Definition at line 153 of file settings_internal.h.

## ◆ GetTitleCallback

using IntSettingDesc::GetTitleCallback = StringID(const IntSettingDesc &sd)

Definition at line 149 of file settings_internal.h.

## ◆ GetValueParamsCallback

using IntSettingDesc::GetValueParamsCallback = std::pair<StringParameter, StringParameter>(const IntSettingDesc &sd, int32_t value)

Definition at line 151 of file settings_internal.h.

## ◆ PostChangeCallback

using IntSettingDesc::PostChangeCallback = void(int32_t value)

A callback to denote that a setting has been changed.

Parameters

  The | new value for the setting.

Definition at line 168 of file settings_internal.h.

## ◆ PreChangeCheck

using IntSettingDesc::PreChangeCheck = bool(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.

Parameters

  value | The prospective new value for the setting.

Returns
  True when the setting is accepted.

Definition at line 163 of file settings_internal.h.

## Constructor & Destructor Documentation

## ◆ IntSettingDesc()

template<ConvertibleThroughBaseOrTo< int32_t > Tdef, ConvertibleThroughBaseOrTo< int32_t > Tmin, ConvertibleThroughBaseOrTo< uint32_t > Tmax, ConvertibleThroughBaseOrTo< int32_t > Tinterval>

IntSettingDesc::IntSettingDesc | ( | const SaveLoad & | save,
|  | SettingFlags | 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,
|  | GetValueParamsCallback | get_value_params_cb,
|  | GetDefaultValueCallback | get_def_cb,
|  | GetRangeCallback | get_range_cb
| ) |  |
| inline

Definition at line 171 of file settings_internal.h.

## Member Function Documentation

## ◆ ChangeValue()

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.

Parameters

  object | The object the setting is in.
  newval | The new value for the setting.

Definition at line 1611 of file settings.cpp.

References _gamelog, SettingDesc::flags, SettingDesc::GetName(), GLAT_SETTING, MakeValueValid(), NoNetwork, post_callback, pre_check, Read(), Sandbox, SaveToConfig(), Gamelog::Setting(), SetWindowClassesDirty(), Gamelog::StartAction(), Gamelog::StopAction(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), WC_CHEATS, WC_GAME_OPTIONS, and Write().

Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), and SetSettingValue().

## ◆ FormatValue()

std::string IntSettingDesc::FormatValue | ( | 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 OneOfManySettingDesc, and ManyOfManySettingDesc.

Definition at line 736 of file settings.cpp.

References SaveLoad::conv, Read(), and SettingDesc::save.

## ◆ GetDefaultValue()

int32_t IntSettingDesc::GetDefaultValue | ( |  | ) | const

Get the default value of the setting.

Returns
  The default value.

Definition at line 467 of file settings.cpp.

References def, and get_def_cb.

Referenced by GameOptionsWindow::DrawWidget(), IConsoleGetSetting(), IsDefaultValue(), SettingEntry::IsVisibleByRestrictionMode(), MakeValueValid(), CheatWindow::OnQueryTextFinished(), GameOptionsWindow::OnQueryTextFinished(), ParseValue(), ParseValue(), BoolSettingDesc::ParseValue(), OneOfManySettingDesc::ParseValue(), ManyOfManySettingDesc::ParseValue(), ResetToDefault(), and SetDefaultCompanySettings().

## ◆ GetHelp()

StringID IntSettingDesc::GetHelp | ( |  | ) | const

Get the help text of the setting.

Returns
  The requested help text.

Definition at line 436 of file settings.cpp.

References str_help.

Referenced by GameOptionsWindow::DrawWidget(), SettingEntry::GetMaxHelpHeight(), CheatWindow::OnTooltip(), and SettingEntry::UpdateFilterState().

## ◆ GetRange()

std::tuple< int32_t, uint32_t > IntSettingDesc::GetRange | ( |  | ) | const

Get the min/max range for the setting.

Returns
  The min/max range.

Definition at line 476 of file settings.cpp.

References max, and min.

Referenced by SettingEntry::DrawSetting(), GetValueParams(), IConsoleGetSetting(), and MakeValueValid().

## ◆ GetTitle()

StringID IntSettingDesc::GetTitle | ( |  | ) | const

Get the title of the setting.

The string should include a {STRING2} to show the current value.

Returns
  The title string.

Definition at line 427 of file settings.cpp.

References str.

Referenced by SettingEntry::DrawSetting(), and SettingEntry::UpdateFilterState().

## ◆ GetValueParams()

std::pair< StringParameter, StringParameter > IntSettingDesc::GetValueParams | ( | int32_t | value | ) | const

Get parameters for drawing the value of the setting.

Parameters

  value | Setting value to set params for.

Definition at line 445 of file settings.cpp.

References SettingDesc::flags, GetRange(), GuiDropdown, GuiZeroIsSpecial, IsBoolSetting(), str_val, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by SettingEntry::DrawSetting(), and GameOptionsWindow::DrawWidget().

## ◆ 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 232 of file settings_internal.h.

Referenced by SettingEntry::DrawSetting(), and GetValueParams().

## ◆ IsDefaultValue()

bool IntSettingDesc::IsDefaultValue | ( | void * | object | ) | const
| overridevirtual

Check whether the value is the same as the default value.

Parameters

  object | The object the setting is in.

Returns
  true iff the value is the default value.

Implements SettingDesc.

Definition at line 760 of file settings.cpp.

References GetDefaultValue(), and Read().

## ◆ 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 233 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 753 of file settings.cpp.

References ParseValue(), Read(), and IniItem::value.

## ◆ MakeValueValid()

void IntSettingDesc::MakeValueValid | ( | int32_t & | 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 SettingFlag::GuiZeroIsSpecial is set. This is generally done by clamping the value so it is within the allowed value range. However, for SettingFlag::GuiDropdown the default is used when the value is not valid.

Parameters

  val | The value to make valid.

Definition at line 502 of file settings.cpp.

References Clamp(), ClampU(), SaveLoad::conv, SettingDesc::flags, GetDefaultValue(), GetRange(), GetVarMemType(), GuiDropdown, GuiZeroIsSpecial, SettingDesc::save, SLE_VAR_NULL, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by ChangeValue(), and MakeValueValidAndWrite().

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

Parameters

  object | The object the setting is to be saved in.
  val | Signed version of the new value.

Definition at line 487 of file settings.cpp.

References MakeValueValid(), and Write().

Referenced by HandleOldDiffCustom(), LoadSettings(), ParseValue(), and SetDefaultCompanySettings().

## ◆ ParseValue() [1/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 661 of file settings.cpp.

References GetDefaultValue(), MakeValueValidAndWrite(), ParseValue(), and IniItem::value.

## ◆ ParseValue() [2/2]

int32_t IntSettingDesc::ParseValue | ( | std::string_view | 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 BoolSettingDesc, OneOfManySettingDesc, and ManyOfManySettingDesc.

Definition at line 367 of file settings.cpp.

References _settings_error_list, GetDefaultValue(), GetEncodedString(), SettingDesc::GetName(), str, and StringConsumer::TryReadIntegerBase().

Referenced by IsSameValue(), and ParseValue().

## ◆ Read()

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

## ◆ ResetToDefault()

void IntSettingDesc::ResetToDefault | ( | void * | object | ) | const
| overridevirtual

Reset the setting to its default value.

Implements SettingDesc.

Definition at line 766 of file settings.cpp.

References GetDefaultValue(), and Write().

## ◆ Write()

void IntSettingDesc::Write | ( | const void * | object,
|  | int32_t | 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 556 of file settings.cpp.

References SaveLoad::conv, GetVariableAddress(), SettingDesc::save, and WriteValue().

Referenced by ChangeValue(), MakeValueValidAndWrite(), and ResetToDefault().

## Field Documentation

## ◆ cat

SettingCategory IntSettingDesc::cat

assigned categories of the setting

Definition at line 213 of file settings_internal.h.

Referenced by SettingEntry::IsVisibleByRestrictionMode().

## ◆ def

int32_t IntSettingDesc::def

default value given when none is present

Definition at line 206 of file settings_internal.h.

Referenced by GetDefaultServiceInterval(), and GetDefaultValue().

## ◆ get_def_cb

GetDefaultValueCallback* IntSettingDesc::get_def_cb

Callback to set the correct default value.

Definition at line 219 of file settings_internal.h.

Referenced by GetDefaultValue().

## ◆ get_help_cb

GetHelpCallback* IntSettingDesc::get_help_cb

Definition at line 217 of file settings_internal.h.

## ◆ get_range_cb

GetRangeCallback* IntSettingDesc::get_range_cb

Definition at line 220 of file settings_internal.h.

## ◆ get_title_cb

GetTitleCallback* IntSettingDesc::get_title_cb

Definition at line 216 of file settings_internal.h.

## ◆ get_value_params_cb

GetValueParamsCallback* IntSettingDesc::get_value_params_cb

Definition at line 218 of file settings_internal.h.

## ◆ interval

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 209 of file settings_internal.h.

## ◆ max

uint32_t IntSettingDesc::max

maximum values

Definition at line 208 of file settings_internal.h.

Referenced by GetRange().

## ◆ min

int32_t IntSettingDesc::min

minimum values

Definition at line 207 of file settings_internal.h.

Referenced by GetRange().

## ◆ post_callback

PostChangeCallback* IntSettingDesc::post_callback

Callback when the setting has been changed.

Definition at line 215 of file settings_internal.h.

Referenced by ChangeValue().

## ◆ pre_check

PreChangeCheck* IntSettingDesc::pre_check

Callback to check for the validity of the setting.

Definition at line 214 of file settings_internal.h.

Referenced by ChangeValue().

## ◆ str

StringID IntSettingDesc::str

(translated) string with descriptive text; gui and console

Definition at line 210 of file settings_internal.h.

Referenced by GetTitle(), BoolSettingDesc::ParseSingleValue(), OneOfManySettingDesc::ParseSingleValue(), ParseValue(), BoolSettingDesc::ParseValue(), OneOfManySettingDesc::ParseValue(), ManyOfManySettingDesc::ParseValue(), and SettingTitleWallclock().

## ◆ str_help

StringID IntSettingDesc::str_help

(Translated) string with help text; gui only.

Definition at line 211 of file settings_internal.h.

Referenced by GetHelp(), and SettingHelpWallclock().

## ◆ str_val

StringID IntSettingDesc::str_val

(Translated) first string describing the value.

Definition at line 212 of file settings_internal.h.

Referenced by GetValueParams(), ServiceIntervalSettingsValueText(), and SettingsValueAbsolute().

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

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