OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #ifndef SETTINGS_INTERNAL_H
11 #define SETTINGS_INTERNAL_H
81 bool IsEditable(
bool do_command =
false)
const;
88 constexpr
const std::string &
GetName()
const
90 return this->save.
name;
114 virtual void FormatValue(
char *buf,
const char *last,
const void *
object)
const = 0;
178 void ChangeValue(
const void *
object, int32 newvalue)
const;
182 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override;
185 int32
Read(
const void *
object)
const;
189 void Write(
const void *
object, int32 value)
const;
197 IntSettingDesc(
save,
flags,
startup,
def, 0, 1, 0,
str,
str_help,
str_val,
cat,
203 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override;
214 IntSettingDesc(
save,
flags,
startup,
def, 0,
max, 0,
str,
str_help,
str_val,
cat,
217 for (
auto one :
many) this->many.push_back(one);
226 char *FormatSingleValue(
char *buf,
const char *last, uint
id)
const;
229 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override;
243 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override;
275 void ChangeValue(
const void *
object, std::string &newval)
const;
277 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override;
280 const std::string &
Read(
const void *
object)
const;
284 void Write(
const void *
object,
const std::string &str)
const;
295 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override;
306 void FormatValue(
char *buf,
const char *last,
const void *
object)
const override { NOT_REACHED(); }
311 typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
320 return std::visit([](
auto&& arg) ->
const SettingDesc * {
return &arg; }, desc);
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
void MakeValueValid(int32 &value) const
Make the value valid given the limitations of this setting.
@ SF_PER_COMPANY
This setting can be different for each company (saved in company struct).
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.
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
@ SF_GUI_0_IS_SPECIAL
A value of zero is possible and has a custom string (the one after "strval").
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this setting.
bool PreChangeCheck(std::string &value)
A check to be performed before the setting gets changed.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
@ SC_EXPERT_LIST
Settings displayed in the list of expert settings.
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.
SettingCategory cat
assigned categories of the setting
@ SF_NOT_IN_CONFIG
Do not save to config file.
void PostChangeCallback(const std::string &value)
A callback to denote that a setting has been changed.
Placeholder for settings that have been removed, but might still linger in the savegame.
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
void MakeValueValidAndWrite(const void *object, int32 value) const
Make the value valid and then write it to the setting.
A single "line" in an ini file.
SaveLoad save
Internal structure (going to savegame, parts to config).
SettingType GetType() const
Return the type of the setting.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
@ ST_CLIENT
Client setting.
virtual void FormatValue(char *buf, const char *last, const void *object) const =0
Format the value of the setting associated with this object.
void ChangeValue(const void *object, int32 newvalue) const
Handle changing a value.
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
@ ST_COMPANY
Company setting.
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
const std::string & Read(const void *object) const
Read the string from the the actual 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.).
virtual bool IsSameValue(const IniItem *item, void *object) const =0
Check whether the value in the Ini item is the same as is saved in this setting in the object.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
uint32 max_length
Maximum length of the string, 0 means no maximum length.
const struct StringSettingDesc * AsStringSetting() const
Get the setting description of this setting as a string setting.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
bool IsIntSetting() const override
Check whether this setting is an integer type setting.
virtual void ParseValue(const IniItem *item, void *object) const =0
Parse/read the value from the Ini item into 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.
SettingType
Type of settings for filtering.
void ChangeValue(const void *object, std::string &newval) const
Handle changing a string value.
bool IsStringSetting() const override
Check whether this setting is an string type setting.
StringID str_val
(Translated) first string describing the value.
@ SF_NETWORK_ONLY
This setting only applies to network games.
bool IsBoolSetting() const override
Check whether this setting is a boolean type setting.
A trimmed down version of what std::span will be in C++20.
bool startup
Setting has to be loaded directly at startup?.
Base integer type, including boolean, settings.
@ SC_ADVANCED
Advanced settings are part of advanced and expert list.
constexpr const std::string & GetName() const
Get the name of this setting.
@ SF_NEWGAME_ONLY
This setting cannot be changed in a game.
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
fluid_settings_t * settings
FluidSynth settings handle.
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
@ SF_GUI_NEGATIVE_IS_SPECIAL
A negative value has another string (the one after "strval").
void FormatValue(char *buf, const char *last, const void *object) const override
Convert an integer-array (intlist) to a string representation.
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame=false)
Top function to save the new value of an element of the Settings struct.
@ SF_GUI_CURRENCY
The number represents money, so when reading value multiply by exchange rate.
bool PreChangeCheck(int32 &value)
A check to be performed before the setting gets changed.
void Write(const void *object, int32 value) const
Set the value of a setting.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
std::vector< std::string > many
possible values for this type
@ SC_BASIC
Basic settings are part of all lists.
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
StringID str_help
(Translated) string with help text; gui only.
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.
int32 interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
Properties of config file settings.
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
const SettingDesc * GetSettingFromName(const std::string_view name)
Given a name of any setting, return any setting description of it.
StringID str
(translated) string with descriptive text; gui and console
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
const char * def
default value given when none is present
@ SF_SCENEDIT_ONLY
This setting can only be changed in the scenario editor.
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
@ SF_GUI_DROPDOWN
The value represents a limited number of string-options (internally integer) presented as dropdown.
int32 Read(const void *object) const
Read the integer from the the actual setting.
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.
virtual size_t ParseValue(const char *str) const
Convert a string representation (external) of an integer-like setting to an integer.
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
void Write(const void *object, const std::string &str) const
Write a string to the actual setting.
@ SF_SCENEDIT_TOO
This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
std::string def
Default value given when none is present.
void PostChangeCallback(int32 value)
A callback to denote that a setting has been changed.
PostChangeCallback * post_callback
Callback when the setting has been changed.
SettingCategory
A SettingCategory defines a grouping of the settings.
@ ST_ALL
Used in setting filter to match all types.
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
std::string name
Name of this field (optional, used for tables).
@ SC_EXPERT
Expert settings can only be seen in the expert list.
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.
@ SF_NO_NETWORK
This setting does not apply to network games; it may not be changed during the game.
int32 def
default value given when none is present
size_t OnConvert(const char *value)
callback prototype for conversion error
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 |.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
void FormatValue(char *buf, const char *last, const void *object) const override
Format the value of the setting associated with this object.