OpenTTD

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