OpenTTD Source: src/settings_internal.h Source File

OpenTTD Source 1.11.0-RC1

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 <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef SETTINGS_INTERNAL_H
11 #define SETTINGS_INTERNAL_H
12
13 #include "saveload/saveload.h"
14
21 enum SettingDescType : byte {
22 /* 4 bytes allocated a maximum of 16 types for GenericType */
23 SDT_BEGIN = 0,
24 SDT_NUMX = 0,
25 SDT_BOOLX = 1,
26 SDT_ONEOFMANY = 2,
27 SDT_MANYOFMANY = 3,
28 SDT_INTLIST = 4,
29 SDT_STRING = 5,
30 SDT_STDSTRING = 6,
31 SDT_END,
32 /* 9 more possible primitives */
33 };
34
35
36 enum SettingGuiFlag : uint16 {
37 /* 1 byte allocated for a maximum of 8 flags
38 * Flags directing saving/loading of a variable */
39 SGF_NONE = 0,
40 SGF_0ISDISABLED = 1 << 0,
41 SGF_DISPLAY_ABS = 1 << 1,
42 SGF_MULTISTRING = 1 << 2,
43 SGF_NETWORK_ONLY = 1 << 3,
44 SGF_CURRENCY = 1 << 4,
45 SGF_NO_NETWORK = 1 << 5,
46 SGF_NEWGAME_ONLY = 1 << 6,
47 SGF_SCENEDIT_TOO = 1 << 7,
48 SGF_PER_COMPANY = 1 << 8,
49 };
50 DECLARE_ENUM_AS_BIT_SET(SettingGuiFlag)
51
52
60 enum SettingCategory {
61 SC_NONE = 0,
62
63 /* Filters for the list */
64 SC_BASIC_LIST = 1 << 0,
65 SC_ADVANCED_LIST = 1 << 1,
66 SC_EXPERT_LIST = 1 << 2,
67
68 /* Setting classification */
69 SC_BASIC = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST,
70 SC_ADVANCED = SC_ADVANCED_LIST | SC_EXPERT_LIST,
71 SC_EXPERT = SC_EXPERT_LIST,
72
73 SC_END,
74 };
75
79 enum SettingType {
80 ST_GAME,
81 ST_COMPANY,
82 ST_CLIENT,
83
84 ST_ALL,
85 };
86
87 typedef bool OnChange(int32 var);
88 typedef size_t OnConvert(const char *value);
89
91 struct SettingDescBase {
92 const char *name;
93 const void *def;
94 SettingDescType cmd;
95 SettingGuiFlag flags;
96 int32 min;
97 uint32 max;
98 int32 interval;
99 const char *many;
100 StringID str;
101 StringID str_help;
102 StringID str_val;
103 OnChange *proc;
104 OnConvert *proc_cnvt;
105 SettingCategory cat;
106 bool startup;
107 };
108
109 struct SettingDesc {
110 SettingDescBase desc;
111 SaveLoad save;
112
113 bool IsEditable(bool do_command = false) const;
114 SettingType GetType() const;
115 };
116
117 /* NOTE: The only difference between SettingDesc and SettingDescGlob is
118 * that one uses global variables as a source and the other offsets
119 * in a struct which are bound to a certain variable during runtime.
120 * The only way to differentiate between these two is to check if an object
121 * has been passed to the function or not. If not, then it is a global variable
122 * and save->variable has its address, otherwise save->variable only holds the
123 * offset in a certain struct */
124 typedef SettingDesc SettingDescGlobVarList;
125
126 const SettingDesc *GetSettingFromName(const char *name, uint *i);
127 bool SetSettingValue(uint index, int32 value, bool force_newgame = false);
128 bool SetSettingValue(uint index, const char *value, bool force_newgame = false);
129 void SetCompanySetting(uint index, int32 value);
130
131 #endif /* SETTINGS_INTERNAL_H */
SettingGuiFlag
SettingGuiFlag
Definition: settings_internal.h:36
SDT_STRING
@ SDT_STRING
string with a pre-allocated buffer
Definition: settings_internal.h:29
SC_EXPERT_LIST
@ SC_EXPERT_LIST
Settings displayed in the list of expert settings.
Definition: settings_internal.h:66
SettingDescBase::cat
SettingCategory cat
assigned categories of the setting
Definition: settings_internal.h:105
SettingDescBase::str_val
StringID str_val
(Translated) first string describing the value.
Definition: settings_internal.h:102
SGF_PER_COMPANY
@ SGF_PER_COMPANY
this setting can be different for each company (saved in company struct)
Definition: settings_internal.h:48
ST_GAME
@ ST_GAME
Game setting.
Definition: settings_internal.h:80
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config)
Definition: settings_internal.h:111
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:836
SettingDesc::IsEditable
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition: settings.cpp:821
SDT_BOOLX
@ SDT_BOOLX
a boolean number
Definition: settings_internal.h:25
ST_CLIENT
@ ST_CLIENT
Client setting.
Definition: settings_internal.h:82
SGF_NEWGAME_ONLY
@ SGF_NEWGAME_ONLY
this setting cannot be changed in a game
Definition: settings_internal.h:46
OnChange
bool OnChange(int32 var)
callback prototype on data modification
Definition: settings_internal.h:87
saveload.h
ST_COMPANY
@ ST_COMPANY
Company setting.
Definition: settings_internal.h:81
SGF_DISPLAY_ABS
@ SGF_DISPLAY_ABS
display absolute value of the setting
Definition: settings_internal.h:41
SettingDescBase::many
const char * many
ONE/MANY_OF_MANY: string of possible values for this type.
Definition: settings_internal.h:99
SDT_NUMX
@ SDT_NUMX
any number-type
Definition: settings_internal.h:24
SettingDescBase::str
StringID str
(translated) string with descriptive text; gui and console
Definition: settings_internal.h:100
SettingDescBase::min
int32 min
minimum values
Definition: settings_internal.h:96
SettingDescBase::startup
bool startup
setting has to be loaded directly at startup?
Definition: settings_internal.h:106
SDT_STDSTRING
@ SDT_STDSTRING
std::string
Definition: settings_internal.h:30
SettingType
SettingType
Type of settings for filtering.
Definition: settings_internal.h:79
SettingDescBase::cmd
SettingDescType cmd
various flags for the variable
Definition: settings_internal.h:94
SettingDescBase
Properties of config file settings.
Definition: settings_internal.h:91
SettingDescType
SettingDescType
Convention/Type of settings.
Definition: settings_internal.h:21
SettingDescBase::max
uint32 max
maximum values
Definition: settings_internal.h:97
SGF_NETWORK_ONLY
@ SGF_NETWORK_ONLY
this setting only applies to network games
Definition: settings_internal.h:43
SC_ADVANCED
@ SC_ADVANCED
Advanced settings are part of advanced and expert list.
Definition: settings_internal.h:70
SDT_MANYOFMANY
@ SDT_MANYOFMANY
bitmasked number where MULTIPLE bits may be set
Definition: settings_internal.h:27
SDT_ONEOFMANY
@ SDT_ONEOFMANY
bitmasked number where only ONE bit may be set
Definition: settings_internal.h:26
SettingDescBase::def
const void * def
default value given when none is present
Definition: settings_internal.h:93
SettingDescBase::interval
int32 interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
Definition: settings_internal.h:98
SDT_INTLIST
@ SDT_INTLIST
list of integers separated by a comma ','
Definition: settings_internal.h:28
SetCompanySetting
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:2018
SettingDescBase::flags
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
Definition: settings_internal.h:95
GetSettingFromName
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2106
SC_BASIC
@ SC_BASIC
Basic settings are part of all lists.
Definition: settings_internal.h:69
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SGF_MULTISTRING
@ SGF_MULTISTRING
the value represents a limited number of string-options (internally integer)
Definition: settings_internal.h:42
SGF_0ISDISABLED
@ SGF_0ISDISABLED
a value of zero means the feature is disabled
Definition: settings_internal.h:40
SGF_NO_NETWORK
@ SGF_NO_NETWORK
this setting does not apply to network games; it may not be changed during the game
Definition: settings_internal.h:45
SettingDesc
Definition: settings_internal.h:109
SC_BASIC_LIST
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
Definition: settings_internal.h:64
SGF_CURRENCY
@ SGF_CURRENCY
the number represents money, so when reading value multiply by exchange rate
Definition: settings_internal.h:44
SetSettingValue
bool SetSettingValue(uint index, int32 value, bool force_newgame=false)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1974
SettingDesc::desc
SettingDescBase desc
Settings structure (going to configuration file)
Definition: settings_internal.h:110
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
OnConvert
size_t OnConvert(const char *value)
callback prototype for conversion error
Definition: settings_internal.h:88
SettingCategory
SettingCategory
A SettingCategory defines a grouping of the settings.
Definition: settings_internal.h:60
SettingDescBase::name
const char * name
name of the setting. Used in configuration file and for console
Definition: settings_internal.h:92
SettingDescBase::proc
OnChange * proc
callback procedure for when the value is changed
Definition: settings_internal.h:103
ST_ALL
@ ST_ALL
Used in setting filter to match all types.
Definition: settings_internal.h:84
SC_ADVANCED_LIST
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
Definition: settings_internal.h:65
SettingDescBase::proc_cnvt
OnConvert * proc_cnvt
callback procedure when loading value mechanism fails
Definition: settings_internal.h:104
SC_EXPERT
@ SC_EXPERT
Expert settings can only be seen in the expert list.
Definition: settings_internal.h:71
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
SGF_SCENEDIT_TOO
@ SGF_SCENEDIT_TOO
this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
Definition: settings_internal.h:47
SettingDescBase::str_help
StringID str_help
(Translated) string with help text; gui only.
Definition: settings_internal.h:101