OpenTTD Source 20241224-master-gee860a5c8e
OneOfManySettingDesc Struct Reference

One of many setting. More...

#include <settings_internal.h>

Inheritance diagram for OneOfManySettingDesc:
IntSettingDesc SettingDesc ManyOfManySettingDesc

Public Types

typedef size_t OnConvert(const char *value)
 callback prototype for conversion error
 
- Public Types inherited from IntSettingDesc
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

 OneOfManySettingDesc (const SaveLoad &save, SettingFlag flags, bool startup, int32_t def, int32_t max, 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, std::initializer_list< const char * > many, OnConvert *many_cnvt)
 
std::string FormatSingleValue (uint id) const
 
size_t ParseValue (const char *str) const override
 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.
 
- Public Member Functions inherited from IntSettingDesc
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.
 
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 IntSettingDescAsIntSetting () const
 Get the setting description of this setting as an integer setting.
 
const struct StringSettingDescAsStringSetting () const
 Get the setting description of this setting as a string setting.
 

Static Public Member Functions

static size_t ParseSingleValue (const char *str, size_t len, const std::vector< std::string > &many)
 Find the index value of a ONEofMANY type in a string separated by |.
 

Data Fields

std::vector< std::string > many
 possible values for this type
 
OnConvertmany_cnvt
 callback procedure when loading value mechanism fails
 
- Data Fields inherited from IntSettingDesc
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
 
PreChangeCheckpre_check
 Callback to check for the validity of the setting.
 
PostChangeCallbackpost_callback
 Callback when the setting has been changed.
 
GetTitleCallback * get_title_cb
 
GetHelpCallback * get_help_cb
 
SetValueDParamsCallback * set_value_dparams_cb
 
GetDefaultValueCallbackget_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).
 

Detailed Description

One of many setting.

Definition at line 279 of file settings_internal.h.

Member Typedef Documentation

◆ OnConvert

typedef size_t OneOfManySettingDesc::OnConvert(const char *value)

callback prototype for conversion error

Definition at line 280 of file settings_internal.h.

Constructor & Destructor Documentation

◆ OneOfManySettingDesc()

OneOfManySettingDesc::OneOfManySettingDesc ( const SaveLoad save,
SettingFlag  flags,
bool  startup,
int32_t  def,
int32_t  max,
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,
std::initializer_list< const char * >  many,
OnConvert many_cnvt 
)
inline

Definition at line 282 of file settings_internal.h.

Member Function Documentation

◆ FormatSingleValue()

std::string OneOfManySettingDesc::FormatSingleValue ( uint  id) const

Definition at line 345 of file settings.cpp.

◆ FormatValue()

std::string OneOfManySettingDesc::FormatValue ( const void *  object) const
overridevirtual

Format the value of the setting associated with this object.

Parameters
bufThe before of the buffer to format into.
lastThe end of the buffer to format into.
objectThe object the setting is in.

Reimplemented from IntSettingDesc.

Definition at line 353 of file settings.cpp.

References IntSettingDesc::Read().

◆ ParseSingleValue()

size_t OneOfManySettingDesc::ParseSingleValue ( const char *  str,
size_t  len,
const std::vector< std::string > &  many 
)
static

Find the index value of a ONEofMANY type in a string separated by |.

Parameters
strthe current value of the setting for which a value needs found
lenlength of the string
manyfull domain of values the ONEofMANY setting can have
Returns
the integer index of the full-list, or SIZE_MAX if not found

Definition at line 185 of file settings.cpp.

References many, and IntSettingDesc::str.

Referenced by ConvertLandscape(), LoadFromConfig(), LookupManyOfMany(), and ParseValue().

◆ ParseValue()

size_t OneOfManySettingDesc::ParseValue ( const char *  str) const
overridevirtual

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

Parameters
strInput 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 from IntSettingDesc.

Definition at line 398 of file settings.cpp.

References _settings_error_list, IntSettingDesc::def, SettingDesc::GetName(), many, many_cnvt, ParseSingleValue(), ErrorMessageData::SetDParamStr(), and IntSettingDesc::str.

Field Documentation

◆ many

std::vector<std::string> OneOfManySettingDesc::many

possible values for this type

Definition at line 293 of file settings_internal.h.

Referenced by ParseSingleValue(), ParseValue(), and ManyOfManySettingDesc::ParseValue().

◆ many_cnvt

OnConvert* OneOfManySettingDesc::many_cnvt

callback procedure when loading value mechanism fails

Definition at line 294 of file settings_internal.h.

Referenced by ParseValue().


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