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