OpenTTD Source 20250205-master-gfd85ab1e2c
|
Functions and types used internally for the settings configurations. More...
Go to the source code of this file.
Data Structures | |
struct | SettingDesc |
Properties of config file settings. More... | |
struct | IntSettingDesc |
Base integer type, including boolean, settings. More... | |
struct | BoolSettingDesc |
Boolean setting. More... | |
struct | OneOfManySettingDesc |
One of many setting. More... | |
struct | ManyOfManySettingDesc |
Many of many setting. More... | |
struct | StringSettingDesc |
String settings. More... | |
struct | ListSettingDesc |
List/array settings. More... | |
struct | NullSettingDesc |
Placeholder for settings that have been removed, but might still linger in the savegame. More... | |
Typedefs | |
using | SettingFlags = EnumBitSet< SettingFlag, uint16_t > |
typedef std::variant< IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc > | SettingVariant |
typedef std::span< const SettingVariant > | SettingTable |
Enumerations | |
enum class | SettingFlag : uint8_t { GuiZeroIsSpecial , GuiDropdown , GuiCurrency , NetworkOnly , NoNetwork , NewgameOnly , SceneditToo , SceneditOnly , PerCompany , NotInSave , NotInConfig , NoNetworkSync , Sandbox } |
enum | SettingCategory : uint8_t { SC_NONE = 0 , SC_BASIC_LIST = 1 << 0 , SC_ADVANCED_LIST = 1 << 1 , SC_EXPERT_LIST = 1 << 2 , SC_BASIC = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST , SC_ADVANCED = SC_ADVANCED_LIST | SC_EXPERT_LIST , SC_EXPERT = SC_EXPERT_LIST , SC_END } |
A SettingCategory defines a grouping of the settings. More... | |
enum | SettingType : uint8_t { ST_GAME , ST_COMPANY , ST_CLIENT , ST_ALL } |
Type of settings for filtering. More... | |
Functions | |
static constexpr const SettingDesc * | GetSettingDesc (const SettingVariant &desc) |
Helper to convert the type of the iterated settings description to a pointer to it. | |
const SettingDesc * | GetSettingFromName (const std::string_view name) |
Given a name of any setting, return any setting description of it. | |
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. | |
bool | SetSettingValue (const StringSettingDesc *sd, const std::string value, bool force_newgame=false) |
Set a setting value with a string. | |
std::vector< const SettingDesc * > | GetFilteredSettingCollection (std::function< bool(const SettingDesc &desc)> func) |
Get a collection of settings matching a custom filter. | |
Functions and types used internally for the settings configurations.
Definition in file settings_internal.h.
using SettingFlags = EnumBitSet<SettingFlag, uint16_t> |
Definition at line 31 of file settings_internal.h.
typedef std::span<const SettingVariant> SettingTable |
Definition at line 387 of file settings_internal.h.
typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant |
Definition at line 375 of file settings_internal.h.
enum SettingCategory : uint8_t |
A SettingCategory defines a grouping of the settings.
The group SC_BASIC is intended for settings which also a novice player would like to change and is able to understand. The group SC_ADVANCED is intended for settings which an experienced player would like to use. This is the case for most settings. Finally SC_EXPERT settings only few people want to see in rare cases. The grouping is meant to be inclusive, i.e. all settings in SC_BASIC also will be included in the set of settings in SC_ADVANCED. The group SC_EXPERT contains all settings.
Definition at line 41 of file settings_internal.h.
|
strong |
Enumerator | |
---|---|
GuiZeroIsSpecial | A value of zero is possible and has a custom string (the one after "strval"). |
GuiDropdown | The value represents a limited number of string-options (internally integer) presented as dropdown. |
GuiCurrency | The number represents money, so when reading value multiply by exchange rate. |
NetworkOnly | This setting only applies to network games. |
NoNetwork | This setting does not apply to network games; it may not be changed during the game. |
NewgameOnly | This setting cannot be changed in a game. |
SceneditToo | This setting can be changed in the scenario editor (only makes sense when SettingFlag::NewgameOnly is set). |
SceneditOnly | This setting can only be changed in the scenario editor. |
PerCompany | This setting can be different for each company (saved in company struct). |
NotInSave | Do not save with savegame, basically client-based. |
NotInConfig | Do not save to config file. |
NoNetworkSync | Do not synchronize over network (but it is saved if SettingFlag::NotInSave is not set). |
Sandbox | This setting is a sandbox setting. |
Definition at line 16 of file settings_internal.h.
enum SettingType : uint8_t |
Type of settings for filtering.
Enumerator | |
---|---|
ST_GAME | Game setting. |
ST_COMPANY | Company setting. |
ST_CLIENT | Client setting. |
ST_ALL | Used in setting filter to match all types. |
Definition at line 60 of file settings_internal.h.
std::vector< const SettingDesc * > GetFilteredSettingCollection | ( | std::function< bool(const SettingDesc &desc)> | func | ) |
Get a collection of settings matching a custom filter.
func | Function to filter each setting. |
Definition at line 1702 of file settings.cpp.
References GenericSettingTables(), and GetSettingDesc().
void GetSaveLoadFromSettingTable | ( | SettingTable | settings, |
std::vector< SaveLoad > & | saveloads | ||
) |
Get the SaveLoad for all settings in the settings table.
settings | The settings table to get the SaveLoad objects from. |
saveloads | A vector to store the result in. |
Definition at line 1651 of file settings.cpp.
References GetSettingDesc(), SettingDesc::save, settings, SlIsObjectCurrentlyValid(), SaveLoad::version_from, and SaveLoad::version_to.
|
staticconstexpr |
Helper to convert the type of the iterated settings description to a pointer to it.
desc | The type of the iterator of the value in SettingTable. |
Definition at line 382 of file settings_internal.h.
Referenced by GetFilteredSettingCollection(), GetSaveLoadFromSettingTable(), GetSettingFromName(), GetSettingsDesc(), IniLoadSettings(), IniSaveSettings(), PATSChunkHandler::Load(), LoadSettings(), RemoveEntriesFromIni(), SetDefaultCompanySettings(), SurveySettingsTable(), and SyncCompanySettings().
const SettingDesc * GetSettingFromName | ( | const std::string_view | name | ) |
Given a name of any setting, return any setting description of it.
name | Name of the setting to return a setting description of. |
nullptr
indicates failure to obtain the description. Definition at line 1679 of file settings.cpp.
References GenericSettingTables(), GetCompanySettingFromName(), GetSettingFromName(), PrivateSettingTables(), and SecretSettingTables().
bool SetSettingValue | ( | const IntSettingDesc * | sd, |
int32_t | value, | ||
bool | force_newgame | ||
) |
Top function to save the new value of an element of the Settings struct.
index | offset in the SettingDesc array of the Settings struct which identifies the setting member we want to change |
value | new value of the setting |
force_newgame | force the newgame settings |
Definition at line 1775 of file settings.cpp.
References _local_company, _network_server, _networking, _settings_client, _settings_newgame, SettingDesc::AsIntSetting(), IntSettingDesc::ChangeValue(), ClientSettings::company, SettingDesc::flags, GetGameSettings(), SettingDesc::GetName(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NoNetworkSync, PerCompany, and EnumBitSet< Tenum, Tstorage >::Test().
Referenced by GameSettingsWindow::OnClick(), GameSettingsWindow::OnDropdownSelect(), CheatWindow::OnQueryTextFinished(), NetworkClientListWindow::OnQueryTextFinished(), and GameSettingsWindow::OnQueryTextFinished().
bool SetSettingValue | ( | const StringSettingDesc * | sd, |
std::string | value, | ||
bool | force_newgame | ||
) |
Set a setting value with a string.
sd | the setting to change. |
value | the value to write |
force_newgame | force the newgame settings |
Definition at line 1851 of file settings.cpp.
References _settings_game, _settings_newgame, SettingDesc::AsStringSetting(), StringSettingDesc::ChangeValue(), SaveLoad::conv, SettingDesc::flags, GetVarMemType(), NoNetworkSync, SettingDesc::save, SLE_VAR_STRQ, and EnumBitSet< Tenum, Tstorage >::Test().