OpenTTD Source: src/settings_internal.h Source File

OpenTTD Source 15.3

settings_internal.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef SETTINGS_INTERNAL_H
11#define SETTINGS_INTERNAL_H
12
13#include <variant>
14#include "saveload/saveload.h"
15
16 enum class SettingFlag : uint8_t {
17 GuiZeroIsSpecial,
18 GuiDropdown,
19 GuiCurrency,
20 NetworkOnly,
21 NoNetwork,
22 NewgameOnly,
23 SceneditToo,
24 SceneditOnly,
25 PerCompany,
26 NotInSave,
27 NotInConfig,
28 NoNetworkSync,
29 Sandbox,
30};
31using SettingFlags = EnumBitSet<SettingFlag, uint16_t>;
32
41 enum SettingCategory : uint8_t {
42 SC_NONE = 0,
43
44 /* Filters for the list */
45 SC_BASIC_LIST = 1 << 0,
46 SC_ADVANCED_LIST = 1 << 1,
47 SC_EXPERT_LIST = 1 << 2,
48
49 /* Setting classification */
50 SC_BASIC = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST,
51 SC_ADVANCED = SC_ADVANCED_LIST | SC_EXPERT_LIST,
52 SC_EXPERT = SC_EXPERT_LIST,
53
54 SC_END,
55};
56
60 enum SettingType : uint8_t {
61 ST_GAME,
62 ST_COMPANY,
63 ST_CLIENT,
64
65 ST_ALL,
66};
67
68struct IniItem;
69
71 struct SettingDesc {
72 SettingDesc(const SaveLoad &save, SettingFlags flags, bool startup) :
73 flags(flags), startup(startup), save(save) {}
74 virtual ~SettingDesc() = default;
75
76 SettingFlags flags;
77 bool startup;
78 SaveLoad save;
79
80 bool IsEditable(bool do_command = false) const;
81 SettingType GetType() const;
82
87 constexpr const std::string &GetName() const
88 {
89 return this->save.name;
90 }
91
96 virtual bool IsIntSetting() const { return false; }
97
102 virtual bool IsStringSetting() const { return false; }
103
104 const struct IntSettingDesc *AsIntSetting() const;
105 const struct StringSettingDesc *AsStringSetting() const;
106
113 virtual std::string FormatValue(const void *object) const = 0;
114
120 virtual void ParseValue(const IniItem *item, void *object) const = 0;
121
131 virtual bool IsSameValue(const IniItem *item, void *object) const = 0;
132
139 virtual bool IsDefaultValue(void *object) const = 0;
140
144 virtual void ResetToDefault(void *object) const = 0;
145};
146
148 struct IntSettingDesc : SettingDesc {
149 using GetTitleCallback = StringID(const IntSettingDesc &sd);
150 using GetHelpCallback = StringID(const IntSettingDesc &sd);
151 using GetValueParamsCallback = std::pair<StringParameter, StringParameter>(const IntSettingDesc &sd, int32_t value);
152 using GetDefaultValueCallback = int32_t(const IntSettingDesc &sd);
153 using GetRangeCallback = std::tuple<int32_t, uint32_t>(const IntSettingDesc &sd);
154
163 using PreChangeCheck = bool(int32_t &value);
168 using PostChangeCallback = void(int32_t value);
169
170 template <ConvertibleThroughBaseOrTo<int32_t> Tdef, ConvertibleThroughBaseOrTo<int32_t> Tmin, ConvertibleThroughBaseOrTo<uint32_t> Tmax, ConvertibleThroughBaseOrTo<int32_t> Tinterval>
171 IntSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, Tdef def,
172 Tmin min, Tmax max, Tinterval interval, StringID str, StringID str_help, StringID str_val,
173 SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback,
174 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
175 GetDefaultValueCallback get_def_cb, GetRangeCallback get_range_cb) :
176 SettingDesc(save, flags, startup),
177 str(str), str_help(str_help), str_val(str_val), cat(cat), pre_check(pre_check),
178 post_callback(post_callback),
179 get_title_cb(get_title_cb), get_help_cb(get_help_cb), get_value_params_cb(get_value_params_cb),
180 get_def_cb(get_def_cb), get_range_cb(get_range_cb) {
181 if constexpr (ConvertibleThroughBase<Tdef>) {
182 this->def = def.base();
183 } else {
184 this->def = def;
185 }
186
187 if constexpr (ConvertibleThroughBase<Tmin>) {
188 this->min = min.base();
189 } else {
190 this->min = min;
191 }
192
193 if constexpr (ConvertibleThroughBase<Tmax>) {
194 this->max = max.base();
195 } else {
196 this->max = max;
197 }
198
199 if constexpr (ConvertibleThroughBase<Tinterval>) {
200 this->interval = interval.base();
201 } else {
202 this->interval = interval;
203 }
204 }
205
206 int32_t def;
207 int32_t min;
208 uint32_t max;
209 int32_t interval;
210 StringID str;
211 StringID str_help;
212 StringID str_val;
213 SettingCategory cat;
214 PreChangeCheck *pre_check;
215 PostChangeCallback *post_callback;
216 GetTitleCallback *get_title_cb;
217 GetHelpCallback *get_help_cb;
218 GetValueParamsCallback *get_value_params_cb;
219 GetDefaultValueCallback *get_def_cb;
220 GetRangeCallback *get_range_cb;
221
222 StringID GetTitle() const;
223 StringID GetHelp() const;
224 std::pair<StringParameter, StringParameter> GetValueParams(int32_t value) const;
225 int32_t GetDefaultValue() const;
226 std::tuple<int32_t, uint32_t> GetRange() const;
227
232 virtual bool IsBoolSetting() const { return false; }
233 bool IsIntSetting() const override { return true; }
234
235 void ChangeValue(const void *object, int32_t newvalue) const;
236 void MakeValueValidAndWrite(const void *object, int32_t value) const;
237
238 virtual int32_t ParseValue(std::string_view str) const;
239 std::string FormatValue(const void *object) const override;
240 void ParseValue(const IniItem *item, void *object) const override;
241 bool IsSameValue(const IniItem *item, void *object) const override;
242 bool IsDefaultValue(void *object) const override;
243 void ResetToDefault(void *object) const override;
244 int32_t Read(const void *object) const;
245
246private:
247 void MakeValueValid(int32_t &value) const;
248 void Write(const void *object, int32_t value) const;
249};
250
252 struct BoolSettingDesc : IntSettingDesc {
253 BoolSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, bool def,
254 StringID str, StringID str_help, StringID str_val, SettingCategory cat,
255 PreChangeCheck pre_check, PostChangeCallback post_callback,
256 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
257 GetDefaultValueCallback get_def_cb) :
258 IntSettingDesc(save, flags, startup, def ? 1 : 0, 0, 1, 0, str, str_help, str_val, cat,
259 pre_check, post_callback, get_title_cb, get_help_cb, get_value_params_cb, get_def_cb, nullptr) {}
260
261 static std::optional<bool> ParseSingleValue(std::string_view str);
262
263 bool IsBoolSetting() const override { return true; }
264 int32_t ParseValue(std::string_view str) const override;
265 std::string FormatValue(const void *object) const override;
266};
267
269 struct OneOfManySettingDesc : IntSettingDesc {
270 typedef std::optional<uint32_t> OnConvert(std::string_view value);
271
272 template <ConvertibleThroughBaseOrTo<int32_t> Tdef, ConvertibleThroughBaseOrTo<uint32_t> Tmax>
273 OneOfManySettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, Tdef def,
274 Tmax max, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
275 PreChangeCheck pre_check, PostChangeCallback post_callback,
276 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
277 GetDefaultValueCallback get_def_cb, std::initializer_list<std::string_view> many, OnConvert *many_cnvt) :
278 IntSettingDesc(save, flags, startup, def, 0, max, 0, str, str_help, str_val, cat,
279 pre_check, post_callback, get_title_cb, get_help_cb, get_value_params_cb, get_def_cb, nullptr), many_cnvt(many_cnvt)
280 {
281 for (auto one : many) this->many.push_back(one);
282 }
283
284 std::vector<std::string_view> many;
285 OnConvert *many_cnvt;
286
287 static std::optional<uint32_t> ParseSingleValue(std::string_view str, std::span<const std::string_view> many);
288 std::string FormatSingleValue(uint id) const;
289
290 int32_t ParseValue(std::string_view str) const override;
291 std::string FormatValue(const void *object) const override;
292};
293
295 struct ManyOfManySettingDesc : OneOfManySettingDesc {
296 template <ConvertibleThroughBaseOrTo<int32_t> Tdef>
297 ManyOfManySettingDesc(const SaveLoad &save, SettingFlags flags, bool startup,
298 Tdef def, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
299 PreChangeCheck pre_check, PostChangeCallback post_callback,
300 GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
301 GetDefaultValueCallback get_def_cb, std::initializer_list<std::string_view> many, OnConvert *many_cnvt) :
302 OneOfManySettingDesc(save, flags, startup, def, (1 << many.size()) - 1, str, str_help,
303 str_val, cat, pre_check, post_callback, get_title_cb, get_help_cb, get_value_params_cb, get_def_cb, many, many_cnvt) {}
304
305 int32_t ParseValue(std::string_view str) const override;
306 std::string FormatValue(const void *object) const override;
307};
308
310 struct StringSettingDesc : SettingDesc {
319 typedef bool PreChangeCheck(std::string &value);
324 typedef void PostChangeCallback(const std::string &value);
325
326 StringSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, std::string_view def,
327 uint32_t max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) :
328 SettingDesc(save, flags, startup), def(def), max_length(max_length),
329 pre_check(pre_check), post_callback(post_callback) {}
330
331 std::string_view def;
332 uint32_t max_length;
333 PreChangeCheck *pre_check;
334 PostChangeCallback *post_callback;
335
336 bool IsStringSetting() const override { return true; }
337 void ChangeValue(const void *object, std::string &&newval) const;
338
339 std::string FormatValue(const void *object) const override;
340 void ParseValue(const IniItem *item, void *object) const override;
341 bool IsSameValue(const IniItem *item, void *object) const override;
342 bool IsDefaultValue(void *object) const override;
343 void ResetToDefault(void *object) const override;
344 const std::string &Read(const void *object) const;
345
346private:
347 void MakeValueValid(std::string &str) const;
348 void Write(const void *object, std::string_view str) const;
349};
350
352 struct ListSettingDesc : SettingDesc {
353 ListSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, std::string_view def) :
354 SettingDesc(save, flags, startup), def(def) {}
355
356 std::string_view def;
357
358 std::string FormatValue(const void *object) const override;
359 void ParseValue(const IniItem *item, void *object) const override;
360 bool IsSameValue(const IniItem *item, void *object) const override;
361 bool IsDefaultValue(void *object) const override;
362 void ResetToDefault(void *object) const override;
363};
364
366 struct NullSettingDesc : SettingDesc {
367 NullSettingDesc(const SaveLoad &save) :
368 SettingDesc(save, SettingFlag::NotInConfig, false) {}
369
370 std::string FormatValue(const void *) const override { NOT_REACHED(); }
371 void ParseValue(const IniItem *, void *) const override { NOT_REACHED(); }
372 bool IsSameValue(const IniItem *, void *) const override { NOT_REACHED(); }
373 bool IsDefaultValue(void *) const override { NOT_REACHED(); }
374 void ResetToDefault(void *) const override { NOT_REACHED(); }
375};
376
377typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
378
384 static constexpr const SettingDesc *GetSettingDesc(const SettingVariant &desc)
385{
386 return std::visit([](auto&& arg) -> const SettingDesc * { return &arg; }, desc);
387}
388
389typedef std::span<const SettingVariant> SettingTable;
390
391const SettingDesc *GetSettingFromName(std::string_view name);
392void GetSaveLoadFromSettingTable(SettingTable settings, std::vector<SaveLoad> &saveloads);
393SettingTable GetSaveLoadSettingTable();
394bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame = false);
395bool SetSettingValue(const StringSettingDesc *sd, std::string_view value, bool force_newgame = false);
396
397std::vector<const SettingDesc *> GetFilteredSettingCollection(std::function<bool(const SettingDesc &desc)> func);
398
399#endif /* SETTINGS_INTERNAL_H */
EnumBitSet< SettingFlag, uint16_t >
ConvertibleThroughBase
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
Definition convertible_through_base.hpp:19
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition fluidsynth.cpp:25
saveload.h
Functions/types related to saving and loading games.
GetSettingFromName
const SettingDesc * GetSettingFromName(std::string_view name)
Given a name of any setting, return any setting description of it.
Definition settings.cpp:1722
SettingFlag
SettingFlag
Definition settings_internal.h:16
SettingFlag::NotInSave
@ NotInSave
Do not save with savegame, basically client-based.
SettingFlag::GuiCurrency
@ GuiCurrency
The number represents money, so when reading value multiply by exchange rate.
SettingFlag::Sandbox
@ Sandbox
This setting is a sandbox setting.
SettingFlag::SceneditOnly
@ SceneditOnly
This setting can only be changed in the scenario editor.
SettingFlag::PerCompany
@ PerCompany
This setting can be different for each company (saved in company struct).
SettingFlag::NewgameOnly
@ NewgameOnly
This setting cannot be changed in a game.
SettingFlag::GuiZeroIsSpecial
@ GuiZeroIsSpecial
A value of zero is possible and has a custom string (the one after "strval").
SettingFlag::NoNetwork
@ NoNetwork
This setting does not apply to network games; it may not be changed during the game.
SettingFlag::NotInConfig
@ NotInConfig
Do not save to config file.
SettingFlag::GuiDropdown
@ GuiDropdown
The value represents a limited number of string-options (internally integer) presented as dropdown.
SettingFlag::SceneditToo
@ SceneditToo
This setting can be changed in the scenario editor (only makes sense when SettingFlag::NewgameOnly is...
SettingFlag::NoNetworkSync
@ NoNetworkSync
Do not synchronize over network (but it is saved if SettingFlag::NotInSave is not set).
SettingFlag::NetworkOnly
@ NetworkOnly
This setting only applies to network games.
GetFilteredSettingCollection
std::vector< const SettingDesc * > GetFilteredSettingCollection(std::function< bool(const SettingDesc &desc)> func)
Get a collection of settings matching a custom filter.
Definition settings.cpp:1745
SettingType
SettingType
Type of settings for filtering.
Definition settings_internal.h:60
ST_CLIENT
@ ST_CLIENT
Client setting.
Definition settings_internal.h:63
ST_ALL
@ ST_ALL
Used in setting filter to match all types.
Definition settings_internal.h:65
ST_GAME
@ ST_GAME
Game setting.
Definition settings_internal.h:61
ST_COMPANY
@ ST_COMPANY
Company setting.
Definition settings_internal.h:62
GetSaveLoadFromSettingTable
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
Definition settings.cpp:1665
SetSettingValue
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.
Definition settings.cpp:1818
GetSaveLoadSettingTable
SettingTable GetSaveLoadSettingTable()
Create a single table with all settings that should be stored/loaded in the savegame.
Definition settings.cpp:1678
SettingCategory
SettingCategory
A SettingCategory defines a grouping of the settings.
Definition settings_internal.h:41
SC_ADVANCED
@ SC_ADVANCED
Advanced settings are part of advanced and expert list.
Definition settings_internal.h:51
SC_EXPERT
@ SC_EXPERT
Expert settings can only be seen in the expert list.
Definition settings_internal.h:52
SC_ADVANCED_LIST
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
Definition settings_internal.h:46
SC_EXPERT_LIST
@ SC_EXPERT_LIST
Settings displayed in the list of expert settings.
Definition settings_internal.h:47
SC_BASIC_LIST
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
Definition settings_internal.h:45
SC_BASIC
@ SC_BASIC
Basic settings are part of all lists.
Definition settings_internal.h:50
GetSettingDesc
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
Definition settings_internal.h:384
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
BoolSettingDesc
Boolean setting.
Definition settings_internal.h:252
BoolSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition settings.cpp:747
BoolSettingDesc::IsBoolSetting
bool IsBoolSetting() const override
Check whether this setting is a boolean type setting.
Definition settings_internal.h:263
BoolSettingDesc::ParseSingleValue
static std::optional< bool > ParseSingleValue(std::string_view str)
Find whether a string was a boolean true or a boolean false.
Definition settings.cpp:206
BoolSettingDesc::ParseValue
int32_t ParseValue(std::string_view str) const override
Convert a string representation (external) of an integer-like setting to an integer.
Definition settings.cpp:411
IniItem
A single "line" in an ini file.
Definition ini_type.h:23
IntSettingDesc
Base integer type, including boolean, settings.
Definition settings_internal.h:148
IntSettingDesc::str_help
StringID str_help
(Translated) string with help text; gui only.
Definition settings_internal.h:211
IntSettingDesc::str_val
StringID str_val
(Translated) first string describing the value.
Definition settings_internal.h:212
IntSettingDesc::MakeValueValid
void MakeValueValid(int32_t &value) const
Make the value valid given the limitations of this setting.
Definition settings.cpp:502
IntSettingDesc::ResetToDefault
void ResetToDefault(void *object) const override
Reset the setting to its default value.
Definition settings.cpp:766
IntSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition settings.cpp:736
IntSettingDesc::def
int32_t def
default value given when none is present
Definition settings_internal.h:206
IntSettingDesc::cat
SettingCategory cat
assigned categories of the setting
Definition settings_internal.h:213
IntSettingDesc::IsIntSetting
bool IsIntSetting() const override
Check whether this setting is an integer type setting.
Definition settings_internal.h:233
IntSettingDesc::GetRange
std::tuple< int32_t, uint32_t > GetRange() const
Get the min/max range for the setting.
Definition settings.cpp:476
IntSettingDesc::GetTitle
StringID GetTitle() const
Get the title of the setting.
Definition settings.cpp:427
IntSettingDesc::ChangeValue
void ChangeValue(const void *object, int32_t newvalue) const
Handle changing a value.
Definition settings.cpp:1611
IntSettingDesc::max
uint32_t max
maximum values
Definition settings_internal.h:208
IntSettingDesc::get_def_cb
GetDefaultValueCallback * get_def_cb
Callback to set the correct default value.
Definition settings_internal.h:219
IntSettingDesc::IsSameValue
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.
Definition settings.cpp:753
IntSettingDesc::min
int32_t min
minimum values
Definition settings_internal.h:207
IntSettingDesc::PreChangeCheck
bool(int32_t &value) PreChangeCheck
A check to be performed before the setting gets changed.
Definition settings_internal.h:163
IntSettingDesc::pre_check
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
Definition settings_internal.h:214
IntSettingDesc::GetDefaultValue
int32_t GetDefaultValue() const
Get the default value of the setting.
Definition settings.cpp:467
IntSettingDesc::Write
void Write(const void *object, int32_t value) const
Set the value of a setting.
Definition settings.cpp:556
IntSettingDesc::GetHelp
StringID GetHelp() const
Get the help text of the setting.
Definition settings.cpp:436
IntSettingDesc::IsBoolSetting
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
Definition settings_internal.h:232
IntSettingDesc::post_callback
PostChangeCallback * post_callback
Callback when the setting has been changed.
Definition settings_internal.h:215
IntSettingDesc::str
StringID str
(translated) string with descriptive text; gui and console
Definition settings_internal.h:210
IntSettingDesc::MakeValueValidAndWrite
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
Definition settings.cpp:487
IntSettingDesc::PostChangeCallback
void(int32_t value) PostChangeCallback
A callback to denote that a setting has been changed.
Definition settings_internal.h:168
IntSettingDesc::GetValueParams
std::pair< StringParameter, StringParameter > GetValueParams(int32_t value) const
Get parameters for drawing the value of the setting.
Definition settings.cpp:445
IntSettingDesc::Read
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition settings.cpp:567
IntSettingDesc::interval
int32_t interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
Definition settings_internal.h:209
IntSettingDesc::ParseValue
virtual int32_t ParseValue(std::string_view str) const
Convert a string representation (external) of an integer-like setting to an integer.
Definition settings.cpp:367
IntSettingDesc::IsDefaultValue
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
Definition settings.cpp:760
ListSettingDesc
List/array settings.
Definition settings_internal.h:352
ListSettingDesc::ParseValue
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
Definition settings.cpp:674
ListSettingDesc::ResetToDefault
void ResetToDefault(void *object) const override
Reset the setting to its default value.
Definition settings.cpp:820
ListSettingDesc::IsSameValue
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.
Definition settings.cpp:808
ListSettingDesc::def
std::string_view def
default value given when none is present
Definition settings_internal.h:356
ListSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Convert an integer-array (intlist) to a string representation.
Definition settings.cpp:310
ListSettingDesc::IsDefaultValue
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
Definition settings.cpp:814
ManyOfManySettingDesc
Many of many setting.
Definition settings_internal.h:295
ManyOfManySettingDesc::ParseValue
int32_t ParseValue(std::string_view str) const override
Convert a string representation (external) of an integer-like setting to an integer.
Definition settings.cpp:400
ManyOfManySettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition settings.cpp:347
NullSettingDesc
Placeholder for settings that have been removed, but might still linger in the savegame.
Definition settings_internal.h:366
NullSettingDesc::IsSameValue
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.
Definition settings_internal.h:372
NullSettingDesc::ParseValue
void ParseValue(const IniItem *, void *) const override
Parse/read the value from the Ini item into the setting associated with this object.
Definition settings_internal.h:371
NullSettingDesc::FormatValue
std::string FormatValue(const void *) const override
Format the value of the setting associated with this object.
Definition settings_internal.h:370
NullSettingDesc::IsDefaultValue
bool IsDefaultValue(void *) const override
Check whether the value is the same as the default value.
Definition settings_internal.h:373
NullSettingDesc::ResetToDefault
void ResetToDefault(void *) const override
Reset the setting to its default value.
Definition settings_internal.h:374
OneOfManySettingDesc
One of many setting.
Definition settings_internal.h:269
OneOfManySettingDesc::many_cnvt
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
Definition settings_internal.h:285
OneOfManySettingDesc::OnConvert
std::optional< uint32_t > OnConvert(std::string_view value)
callback prototype for conversion error
Definition settings_internal.h:270
OneOfManySettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition settings.cpp:341
OneOfManySettingDesc::ParseSingleValue
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.
Definition settings.cpp:188
OneOfManySettingDesc::many
std::vector< std::string_view > many
possible values for this type
Definition settings_internal.h:284
OneOfManySettingDesc::ParseValue
int32_t ParseValue(std::string_view str) const override
Convert a string representation (external) of an integer-like setting to an integer.
Definition settings.cpp:386
SaveLoad
SaveLoad type struct.
Definition saveload.h:732
SaveLoad::name
std::string name
Name of this field (optional, used for tables).
Definition saveload.h:733
SettingDesc
Properties of config file settings.
Definition settings_internal.h:71
SettingDesc::ParseValue
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.
SettingDesc::IsEditable
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition settings.cpp:894
SettingDesc::flags
SettingFlags flags
Handles how a setting would show up in the GUI (text/currency, etc.).
Definition settings_internal.h:76
SettingDesc::IsStringSetting
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
Definition settings_internal.h:102
SettingDesc::ResetToDefault
virtual void ResetToDefault(void *object) const =0
Reset the setting to its default value.
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition settings.cpp:911
SettingDesc::GetName
constexpr const std::string & GetName() const
Get the name of this setting.
Definition settings_internal.h:87
SettingDesc::startup
bool startup
Setting has to be loaded directly at startup?.
Definition settings_internal.h:77
SettingDesc::FormatValue
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
SettingDesc::AsStringSetting
const struct StringSettingDesc * AsStringSetting() const
Get the setting description of this setting as a string setting.
Definition settings.cpp:931
SettingDesc::IsSameValue
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.
SettingDesc::IsDefaultValue
virtual bool IsDefaultValue(void *object) const =0
Check whether the value is the same as the default value.
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config).
Definition settings_internal.h:78
SettingDesc::IsIntSetting
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
Definition settings_internal.h:96
SettingDesc::AsIntSetting
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
Definition settings.cpp:921
StringSettingDesc
String settings.
Definition settings_internal.h:310
StringSettingDesc::Read
const std::string & Read(const void *object) const
Read the string from the the actual setting.
Definition settings.cpp:606
StringSettingDesc::PostChangeCallback
void PostChangeCallback(const std::string &value)
A callback to denote that a setting has been changed.
Definition settings_internal.h:324
StringSettingDesc::def
std::string_view def
Default value given when none is present.
Definition settings_internal.h:331
StringSettingDesc::Write
void Write(const void *object, std::string_view str) const
Write a string to the actual setting.
Definition settings.cpp:596
StringSettingDesc::max_length
uint32_t max_length
Maximum length of the string, 0 means no maximum length.
Definition settings_internal.h:332
StringSettingDesc::pre_check
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
Definition settings_internal.h:333
StringSettingDesc::ChangeValue
void ChangeValue(const void *object, std::string &&newval) const
Handle changing a string value.
Definition settings.cpp:1913
StringSettingDesc::MakeValueValid
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this setting.
Definition settings.cpp:580
StringSettingDesc::IsSameValue
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.
Definition settings.cpp:787
StringSettingDesc::IsDefaultValue
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
Definition settings.cpp:797
StringSettingDesc::post_callback
PostChangeCallback * post_callback
Callback when the setting has been changed.
Definition settings_internal.h:334
StringSettingDesc::ResetToDefault
void ResetToDefault(void *object) const override
Reset the setting to its default value.
Definition settings.cpp:803
StringSettingDesc::PreChangeCheck
bool PreChangeCheck(std::string &value)
A check to be performed before the setting gets changed.
Definition settings_internal.h:319
StringSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition settings.cpp:771
StringSettingDesc::IsStringSetting
bool IsStringSetting() const override
Check whether this setting is an string type setting.
Definition settings_internal.h:336
StringSettingDesc::ParseValue
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
Definition settings.cpp:667