10#ifndef SETTINGS_INTERNAL_H
11#define SETTINGS_INTERNAL_H
77template <
typename T,
typename TTo>
90 bool IsEditable(
bool do_command =
false)
const;
97 constexpr const std::string &
GetName()
const
99 return this->save.
name;
160 using GetValueParamsCallback = std::pair<StringParameter, StringParameter>(
const IntSettingDesc &sd, int32_t value);
161 using GetDefaultValueCallback = int32_t(
const IntSettingDesc &sd);
162 using GetRangeCallback = std::tuple<int32_t, uint32_t>(
const IntSettingDesc &sd);
179 template <ConvertibleThroughBaseOrUnderlyingOrTo<
int32_t> Tdef, ConvertibleThroughBaseOrUnderlyingOrTo<
int32_t> Tmin, ConvertibleThroughBaseOrUnderlyingOrTo<u
int32_t> Tmax, ConvertibleThroughBaseOrUnderlyingOrTo<
int32_t> T
interval>
183 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
184 GetDefaultValueCallback
get_def_cb, GetRangeCallback get_range_cb) :
188 get_title_cb(get_title_cb), get_help_cb(get_help_cb), get_value_params_cb(get_value_params_cb),
192 this->def =
def.base();
193 }
else if constexpr (is_scoped_enum_v<Tdef>) {
200 this->min =
min.base();
201 }
else if constexpr (is_scoped_enum_v<Tmin>) {
208 this->max =
max.base();
209 }
else if constexpr (is_scoped_enum_v<Tmax>) {
217 }
else if constexpr (is_scoped_enum_v<Tinterval>) {
234 GetTitleCallback *get_title_cb;
235 GetHelpCallback *get_help_cb;
236 GetValueParamsCallback *get_value_params_cb;
238 GetRangeCallback *get_range_cb;
242 std::pair<StringParameter, StringParameter>
GetValueParams(int32_t value)
const;
244 std::tuple<int32_t, uint32_t>
GetRange()
const;
253 void ChangeValue(
const void *
object, int32_t newvalue)
const;
257 std::string
FormatValue(
const void *
object)
const override;
262 int32_t
Read(
const void *
object)
const;
266 void Write(
const void *
object, int32_t value)
const;
274 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
276 IntSettingDesc(
save,
flags,
startup,
def ? 1 : 0, 0, 1, 0,
str,
str_help,
str_val,
cat,
283 std::string
FormatValue(
const void *
object)
const override;
288 typedef std::optional<uint32_t>
OnConvert(std::string_view value);
290 template <ConvertibleThroughBaseOrUnderlyingOrTo<
int32_t> Tdef, ConvertibleThroughBaseOrUnderlyingOrTo<u
int32_t> Tmax>
294 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
296 IntSettingDesc(
save,
flags,
startup,
def, 0,
max, 0,
str,
str_help,
str_val,
cat,
299 for (
auto one :
many) this->
many.push_back(one);
302 std::vector<std::string_view>
many;
306 std::string FormatSingleValue(uint
id)
const;
309 std::string
FormatValue(
const void *
object)
const override;
314 template <ConvertibleThroughBaseOrTo<
int32_t> Tdef>
318 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
324 std::string
FormatValue(
const void *
object)
const override;
355 void ChangeValue(
const void *
object, std::string &&newval)
const;
357 std::string
FormatValue(
const void *
object)
const override;
362 const std::string &
Read(
const void *
object)
const;
366 void Write(
const void *
object, std::string_view str)
const;
376 std::string
FormatValue(
const void *
object)
const override;
388 std::string
FormatValue(
const void *)
const override { NOT_REACHED(); }
395typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
404 return std::visit([](
auto&& arg) ->
const SettingDesc * {
return &arg; }, desc);
407typedef std::span<const SettingVariant> SettingTable;
Type is convertible to TTo, either directly or through ConvertibleThroughBase.
Type is convertible to TTo, either directly, through ConvertibleThroughBase or through to_underlying.
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
Type (helpers) for enums.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
fluid_settings_t * settings
FluidSynth settings handle.
Functions/types related to saving and loading games.
const SettingDesc * GetSettingFromName(std::string_view name)
Given a name of any setting, return any setting description of it.
SettingFlag
Flags describing the behaviour of a setting.
@ NotInSave
Do not save with savegame, basically client-based.
@ GuiCurrency
The number represents money, so when reading value multiply by exchange rate.
@ Sandbox
This setting is a sandbox setting.
@ SceneditOnly
This setting can only be changed in the scenario editor.
@ PerCompany
This setting can be different for each company (saved in company struct).
@ NewgameOnly
This setting cannot be changed in a game.
@ GuiZeroIsSpecial
A value of zero is possible and has a custom string (the one after "strval").
@ NoNetwork
This setting does not apply to network games; it may not be changed during the game.
@ NotInConfig
Do not save to config file.
@ GuiDropdown
The value represents a limited number of string-options (internally integer) presented as dropdown.
@ SceneditToo
This setting can be changed in the scenario editor (only makes sense when SettingFlag::NewgameOnly is...
@ NoNetworkSync
Do not synchronize over network (but it is saved if SettingFlag::NotInSave is not set).
@ NetworkOnly
This setting only applies to network games.
std::vector< const SettingDesc * > GetFilteredSettingCollection(std::function< bool(const SettingDesc &desc)> func)
Get a collection of settings matching a custom filter.
SettingType
Type of settings for filtering.
@ ST_CLIENT
Client setting.
@ ST_ALL
Used in setting filter to match all types.
@ ST_COMPANY
Company setting.
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
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.
SettingTable GetSaveLoadSettingTable()
Create a single table with all settings that should be stored/loaded in the savegame.
SettingCategory
A SettingCategory defines a grouping of the settings.
@ SC_ADVANCED
Advanced settings are part of advanced and expert list.
@ SC_EXPERT
Expert settings can only be seen in the expert list.
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
@ SC_EXPERT_LIST
Settings displayed in the list of expert settings.
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
@ SC_BASIC
Basic settings are part of all lists.
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
bool IsBoolSetting() const override
Check whether this setting is a boolean type setting.
static std::optional< bool > ParseSingleValue(std::string_view str)
Find whether a string was a boolean true or a boolean false.
int32_t ParseValue(std::string_view str) const override
Convert a string representation (external) of an integer-like setting to an integer.
A single "line" in an ini file.
Base integer type, including boolean, settings.
StringID str_help
(Translated) string with help text; gui only.
StringID str_val
(Translated) first string describing the value.
void MakeValueValid(int32_t &value) const
Make the value valid given the limitations of this setting.
void ResetToDefault(void *object) 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.
int32_t def
default value given when none is present
SettingCategory cat
assigned categories of the setting
bool IsIntSetting() const override
Check whether this setting is an integer type setting.
std::tuple< int32_t, uint32_t > GetRange() const
Get the min/max range for the setting.
StringID GetTitle() const
Get the title of the setting.
void ChangeValue(const void *object, int32_t newvalue) const
Handle changing a value.
uint32_t max
maximum values
GetDefaultValueCallback * get_def_cb
Callback to set the correct default value.
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_t min
minimum values
bool(int32_t &value) PreChangeCheck
A check to be performed before the setting gets changed.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
int32_t GetDefaultValue() const
Get the default value of the setting.
void Write(const void *object, int32_t value) const
Set the value of a setting.
StringID GetHelp() const
Get the help text of the setting.
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
PostChangeCallback * post_callback
Callback when the setting has been changed.
StringID str
(translated) string with descriptive text; gui and console
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
void(int32_t value) PostChangeCallback
A callback to denote that a setting has been changed.
std::pair< StringParameter, StringParameter > GetValueParams(int32_t value) const
Get parameters for drawing the value of the setting.
int32_t Read(const void *object) const
Read the integer from the the actual setting.
int32_t interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
virtual int32_t ParseValue(std::string_view str) const
Convert a string representation (external) of an integer-like setting to an integer.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
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 ResetToDefault(void *object) const override
Reset the setting to its default value.
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.
std::string_view def
default value given when none is present
std::string FormatValue(const void *object) const override
Convert an integer-array (intlist) to a string representation.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
int32_t ParseValue(std::string_view 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.
Placeholder for settings that have been removed, but might still linger in the savegame.
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.
void ParseValue(const IniItem *, void *) const override
Parse/read the value from the Ini item into the setting associated with this object.
std::string FormatValue(const void *) const override
Format the value of the setting associated with this object.
bool IsDefaultValue(void *) const override
Check whether the value is the same as the default value.
void ResetToDefault(void *) const override
Reset the setting to its default value.
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
std::optional< uint32_t > OnConvert(std::string_view value)
callback prototype for conversion error
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
static std::optional< uint32_t > ParseSingleValue(std::string_view str, std::span< const std::string_view > many)
Find the index value of a ONEofMANY type in a string.
std::vector< std::string_view > many
possible values for this type
int32_t ParseValue(std::string_view str) const override
Convert a string representation (external) of an integer-like setting to an integer.
std::string name
Name of this field (optional, used for tables).
Properties of config file settings.
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.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
SettingFlags flags
Handles how a setting would show up in the GUI (text/currency, etc.).
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
virtual void ResetToDefault(void *object) const =0
Reset the setting to its default value.
SettingType GetType() const
Return the type of the setting.
constexpr const std::string & GetName() const
Get the name of this setting.
bool startup
Setting has to be loaded directly at startup?.
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
const struct StringSettingDesc * AsStringSetting() const
Get the setting description of this setting as a string setting.
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.
virtual bool IsDefaultValue(void *object) const =0
Check whether the value is the same as the default value.
SaveLoad save
Internal structure (going to savegame, parts to config).
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
const std::string & Read(const void *object) const
Read the string from the the actual setting.
void PostChangeCallback(const std::string &value)
A callback to denote that a setting has been changed.
std::string_view def
Default value given when none is present.
void Write(const void *object, std::string_view str) const
Write a string to the actual setting.
uint32_t max_length
Maximum length of the string, 0 means no maximum length.
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
void ChangeValue(const void *object, std::string &&newval) const
Handle changing a string value.
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this 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.
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
PostChangeCallback * post_callback
Callback when the setting has been changed.
void ResetToDefault(void *object) const override
Reset the setting to its default value.
bool PreChangeCheck(std::string &value)
A check to be performed before the setting gets changed.
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
bool IsStringSetting() const override
Check whether this setting is an string type 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.