Go to the documentation of this file.
10 #ifndef SETTINGS_INTERNAL_H
11 #define SETTINGS_INTERNAL_H
80 bool IsEditable(
bool do_command =
false)
const;
87 constexpr
const std::string &
GetName()
const
89 return this->save.
name;
113 virtual std::string
FormatValue(
const void *
object)
const = 0;
151 typedef void SetValueDParamsCallback(
const IntSettingDesc &sd, uint first_param, int32_t value);
173 std::enable_if_t<std::disjunction_v<std::is_convertible<Tdef, int32_t>, std::is_base_of<StrongTypedefBase, Tdef>>,
int> = 0,
174 std::enable_if_t<std::disjunction_v<std::is_convertible<Tmin, int32_t>, std::is_base_of<StrongTypedefBase, Tmin>>,
int> = 0,
175 std::enable_if_t<std::disjunction_v<std::is_convertible<Tmax, uint32_t>, std::is_base_of<StrongTypedefBase, Tmax>>,
int> = 0,
176 std::enable_if_t<std::disjunction_v<std::is_convertible<Tinterval, int32_t>, std::is_base_of<StrongTypedefBase, Tinterval>>,
int> = 0
181 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, SetValueDParamsCallback set_value_dparams_cb) :
185 get_title_cb(get_title_cb), get_help_cb(get_help_cb), set_value_dparams_cb(set_value_dparams_cb) {
186 if constexpr (std::is_base_of_v<StrongTypedefBase, Tdef>) {
187 this->def =
def.base();
192 if constexpr (std::is_base_of_v<StrongTypedefBase, Tmin>) {
193 this->min =
min.base();
198 if constexpr (std::is_base_of_v<StrongTypedefBase, Tmax>) {
199 this->max =
max.base();
204 if constexpr (std::is_base_of_v<StrongTypedefBase, Tinterval>) {
221 GetTitleCallback *get_title_cb;
222 GetHelpCallback *get_help_cb;
223 SetValueDParamsCallback *set_value_dparams_cb;
236 void ChangeValue(
const void *
object, int32_t newvalue)
const;
240 std::string
FormatValue(
const void *
object)
const override;
245 int32_t
Read(
const void *
object)
const;
249 void Write(
const void *
object, int32_t value)
const;
257 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, SetValueDParamsCallback set_value_dparams_cb) :
258 IntSettingDesc(
save,
flags,
startup,
def ? 1 : 0, 0, 1, 0,
str,
str_help,
str_val,
cat,
265 std::string
FormatValue(
const void *
object)
const override;
275 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, SetValueDParamsCallback set_value_dparams_cb,
277 IntSettingDesc(
save,
flags,
startup,
def, 0,
max, 0,
str,
str_help,
str_val,
cat,
280 for (
auto one :
many) this->many.push_back(one);
287 std::string FormatSingleValue(uint
id)
const;
290 std::string
FormatValue(
const void *
object)
const override;
298 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, SetValueDParamsCallback set_value_dparams_cb,
304 std::string
FormatValue(
const void *
object)
const override;
335 void ChangeValue(
const void *
object, std::string &newval)
const;
337 std::string
FormatValue(
const void *
object)
const override;
342 const std::string &
Read(
const void *
object)
const;
346 void Write(
const void *
object,
const std::string &str)
const;
356 std::string
FormatValue(
const void *
object)
const override;
368 std::string
FormatValue(
const void *)
const override { NOT_REACHED(); }
375 typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
384 return std::visit([](
auto&& arg) ->
const SettingDesc * {
return &arg; }, desc);
387 typedef std::span<const SettingVariant> SettingTable;
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this setting.
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame=false)
Top function to save the new value of an element of the Settings struct.
virtual bool IsDefaultValue(void *object) const =0
Check whether the value is the same as the default value.
@ SF_SCENEDIT_TOO
This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
bool PreChangeCheck(std::string &value)
A check to be performed before the setting gets changed.
bool PreChangeCheck(int32_t &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
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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
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.
@ SF_SCENEDIT_ONLY
This setting can only be changed in the scenario editor.
@ ST_CLIENT
Client setting.
@ ST_COMPANY
Company setting.
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
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.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
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.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
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.
@ SF_GUI_CURRENCY
The number represents money, so when reading value multiply by exchange rate.
void ChangeValue(const void *object, std::string &newval) const
Handle changing a string value.
@ SF_GUI_0_IS_SPECIAL
A value of zero is possible and has a custom string (the one after "strval").
bool IsStringSetting() const override
Check whether this setting is an string type setting.
StringID str_val
(Translated) first string describing the value.
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
void MakeValueValid(int32_t &value) const
Make the value valid given the limitations of this setting.
bool IsBoolSetting() const override
Check whether this setting is a boolean type setting.
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_NETWORK_ONLY
This setting only applies to network games.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
int32_t def
default value given when none is present
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
int32_t min
minimum values
void Write(const void *object, int32_t value) const
Set the value of a setting.
void PostChangeCallback(int32_t value)
A callback to denote that a setting has been changed.
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
fluid_settings_t * settings
FluidSynth settings handle.
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
void ChangeValue(const void *object, int32_t newvalue) const
Handle changing a value.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
virtual void ResetToDefault(void *object) const =0
Reset the setting to its default value.
StringID GetHelp() const
Get the help text of the setting.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
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.
static std::optional< bool > ParseSingleValue(const char *str)
Find whether a string was a boolean true or a boolean false.
StringID str_help
(Translated) string with help text; gui only.
StringID GetTitle() const
Get the title of the setting.
int32_t interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
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_NO_NETWORK
This setting does not apply to network games; it may not be changed during the game.
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.
uint32_t max
maximum values
@ SF_NEWGAME_ONLY
This setting cannot be changed in a game.
StringID str
(translated) string with descriptive text; gui and console
int32_t Read(const void *object) const
Read the integer from the the actual setting.
const char * def
default value given when none is present
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
uint32_t max_length
Maximum length of the string, 0 means no maximum length.
void SetValueDParams(uint first_param, int32_t value) const
Set the DParams for drawing the value of the setting.
void ResetToDefault(void *) const override
Reset the setting to its default value.
std::string FormatValue(const void *object) const override
Format the value of 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.
void ParseValue(const IniItem *, void *) const override
Parse/read the value from the Ini item into the setting associated with this 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.
std::string def
Default value given when none is present.
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
bool IsSameValue(const IniItem *, void *) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
std::string FormatValue(const void *object) const override
Convert an integer-array (intlist) to a string representation.
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.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
@ SF_GUI_DROPDOWN
The value represents a limited number of string-options (internally integer) presented as dropdown.
std::string name
Name of this field (optional, used for tables).
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
bool IsDefaultValue(void *) const override
Check whether the value is the same as the default value.
@ 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.
@ SF_PER_COMPANY
This setting can be different for each company (saved in company struct).
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
std::string FormatValue(const void *) const override
Format the value of the setting associated with this object.
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.
@ SF_NOT_IN_CONFIG
Do not save to config file.