OpenTTD Source  1.11.2
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,
29  SDT_STRING = 5,
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  SGF_SCENEDIT_ONLY = 1 << 9,
50 };
52 
53 
62  SC_NONE = 0,
63 
64  /* Filters for the list */
65  SC_BASIC_LIST = 1 << 0,
66  SC_ADVANCED_LIST = 1 << 1,
67  SC_EXPERT_LIST = 1 << 2,
68 
69  /* Setting classification */
73 
74  SC_END,
75 };
76 
84 
86 };
87 
88 typedef bool OnChange(int32 var);
89 typedef size_t OnConvert(const char *value);
90 
93  const char *name;
94  const void *def;
97  int32 min;
98  uint32 max;
99  int32 interval;
100  const char *many;
107  bool startup;
108 };
109 
110 struct SettingDesc {
113 
114  bool IsEditable(bool do_command = false) const;
115  SettingType GetType() const;
116 };
117 
118 /* NOTE: The only difference between SettingDesc and SettingDescGlob is
119  * that one uses global variables as a source and the other offsets
120  * in a struct which are bound to a certain variable during runtime.
121  * The only way to differentiate between these two is to check if an object
122  * has been passed to the function or not. If not, then it is a global variable
123  * and save->variable has its address, otherwise save->variable only holds the
124  * offset in a certain struct */
126 
127 const SettingDesc *GetSettingFromName(const char *name, uint *i);
128 bool SetSettingValue(uint index, int32 value, bool force_newgame = false);
129 bool SetSettingValue(uint index, const char *value, bool force_newgame = false);
130 void SetCompanySetting(uint index, int32 value);
131 
132 #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:67
SettingDescBase::cat
SettingCategory cat
assigned categories of the setting
Definition: settings_internal.h:106
SettingDescBase::str_val
StringID str_val
(Translated) first string describing the value.
Definition: settings_internal.h:103
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:81
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config)
Definition: settings_internal.h:112
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:837
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:83
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:88
saveload.h
ST_COMPANY
@ ST_COMPANY
Company setting.
Definition: settings_internal.h:82
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:100
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:101
SettingDescBase::min
int32 min
minimum values
Definition: settings_internal.h:97
SettingDescBase::startup
bool startup
setting has to be loaded directly at startup?
Definition: settings_internal.h:107
SDT_STDSTRING
@ SDT_STDSTRING
std::string
Definition: settings_internal.h:30
SettingType
SettingType
Type of settings for filtering.
Definition: settings_internal.h:80
SettingDescBase::cmd
SettingDescType cmd
various flags for the variable
Definition: settings_internal.h:95
SettingDescBase
Properties of config file settings.
Definition: settings_internal.h:92
SettingDescType
SettingDescType
Convention/Type of settings.
Definition: settings_internal.h:21
SettingDescBase::max
uint32 max
maximum values
Definition: settings_internal.h:98
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:71
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:94
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:99
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:2019
SettingDescBase::flags
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
Definition: settings_internal.h:96
GetSettingFromName
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2107
SC_BASIC
@ SC_BASIC
Basic settings are part of all lists.
Definition: settings_internal.h:70
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:110
SC_BASIC_LIST
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
Definition: settings_internal.h:65
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:1975
SettingDesc::desc
SettingDescBase desc
Settings structure (going to configuration file)
Definition: settings_internal.h:111
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:89
SettingCategory
SettingCategory
A SettingCategory defines a grouping of the settings.
Definition: settings_internal.h:61
SettingDescBase::name
const char * name
name of the setting. Used in configuration file and for console
Definition: settings_internal.h:93
SettingDescBase::proc
OnChange * proc
callback procedure for when the value is changed
Definition: settings_internal.h:104
ST_ALL
@ ST_ALL
Used in setting filter to match all types.
Definition: settings_internal.h:85
SC_ADVANCED_LIST
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
Definition: settings_internal.h:66
SettingDescBase::proc_cnvt
OnConvert * proc_cnvt
callback procedure when loading value mechanism fails
Definition: settings_internal.h:105
SC_EXPERT
@ SC_EXPERT
Expert settings can only be seen in the expert list.
Definition: settings_internal.h:72
SaveLoad
SaveLoad type struct.
Definition: saveload.h:517
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:102
SGF_SCENEDIT_ONLY
@ SGF_SCENEDIT_ONLY
this setting can only be changed in the scenario editor
Definition: settings_internal.h:49