OpenTTD: src/settings_internal.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 */