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/>.
8 /** @file settings_internal.h Functions and types used internally for the settings configurations. */
10 #ifndef SETTINGS_INTERNAL_H
11 #define SETTINGS_INTERNAL_H
13 #include "saveload/saveload.h"
16 * Convention/Type of settings. This is then further specified if necessary
17 * with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h
19 * @see SettingDescBase
21 enum SettingDescType
: byte
{
22 /* 4 bytes allocated a maximum of 16 types for GenericType */
24 SDT_NUMX
= 0, ///< any number-type
25 SDT_BOOLX
= 1, ///< a boolean number
26 SDT_ONEOFMANY
= 2, ///< bitmasked number where only ONE bit may be set
27 SDT_MANYOFMANY
= 3, ///< bitmasked number where MULTIPLE bits may be set
28 SDT_INTLIST
= 4, ///< list of integers separated by a comma ','
29 SDT_STRING
= 5, ///< string with a pre-allocated buffer
31 /* 10 more possible primitives */
35 enum SettingGuiFlag
: uint16
{
36 /* 1 byte allocated for a maximum of 8 flags
37 * Flags directing saving/loading of a variable */
39 SGF_0ISDISABLED
= 1 << 0, ///< a value of zero means the feature is disabled
40 SGF_DISPLAY_ABS
= 1 << 1, ///< display absolute value of the setting
41 SGF_MULTISTRING
= 1 << 2, ///< the value represents a limited number of string-options (internally integer)
42 SGF_NETWORK_ONLY
= 1 << 3, ///< this setting only applies to network games
43 SGF_CURRENCY
= 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate
44 SGF_NO_NETWORK
= 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game
45 SGF_NEWGAME_ONLY
= 1 << 6, ///< this setting cannot be changed in a game
46 SGF_SCENEDIT_TOO
= 1 << 7, ///< this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
47 SGF_PER_COMPANY
= 1 << 8, ///< this setting can be different for each company (saved in company struct)
49 DECLARE_ENUM_AS_BIT_SET(SettingGuiFlag
)
52 * A SettingCategory defines a grouping of the settings.
53 * The group #SC_BASIC is intended for settings which also a novice player would like to change and is able to understand.
54 * The group #SC_ADVANCED is intended for settings which an experienced player would like to use. This is the case for most settings.
55 * Finally #SC_EXPERT settings only few people want to see in rare cases.
56 * The grouping is meant to be inclusive, i.e. all settings in #SC_BASIC also will be included
57 * in the set of settings in #SC_ADVANCED. The group #SC_EXPERT contains all settings.
59 enum SettingCategory
{
62 /* Filters for the list */
63 SC_BASIC_LIST
= 1 << 0, ///< Settings displayed in the list of basic settings.
64 SC_ADVANCED_LIST
= 1 << 1, ///< Settings displayed in the list of advanced settings.
65 SC_EXPERT_LIST
= 1 << 2, ///< Settings displayed in the list of expert settings.
67 /* Setting classification */
68 SC_BASIC
= SC_BASIC_LIST
| SC_ADVANCED_LIST
| SC_EXPERT_LIST
, ///< Basic settings are part of all lists.
69 SC_ADVANCED
= SC_ADVANCED_LIST
| SC_EXPERT_LIST
, ///< Advanced settings are part of advanced and expert list.
70 SC_EXPERT
= SC_EXPERT_LIST
, ///< Expert settings can only be seen in the expert list.
76 * Type of settings for filtering.
79 ST_GAME
, ///< Game setting.
80 ST_COMPANY
, ///< Company setting.
81 ST_CLIENT
, ///< Client setting.
83 ST_ALL
, ///< Used in setting filter to match all types.
86 typedef bool OnChange(int32 var
); ///< callback prototype on data modification
87 typedef size_t OnConvert(const char *value
); ///< callback prototype for conversion error
89 /** Properties of config file settings. */
90 struct SettingDescBase
{
91 const char *name
; ///< name of the setting. Used in configuration file and for console
92 const void *def
; ///< default value given when none is present
93 SettingDescType cmd
; ///< various flags for the variable
94 SettingGuiFlag flags
; ///< handles how a setting would show up in the GUI (text/currency, etc.)
95 int32 min
; ///< minimum values
96 uint32 max
; ///< maximum values
97 int32 interval
; ///< the interval to use between settings in the 'settings' window. If interval is '0' the interval is dynamically determined
98 const char *many
; ///< ONE/MANY_OF_MANY: string of possible values for this type
99 StringID str
; ///< (translated) string with descriptive text; gui and console
100 StringID str_help
; ///< (Translated) string with help text; gui only.
101 StringID str_val
; ///< (Translated) first string describing the value.
102 OnChange
*proc
; ///< callback procedure for when the value is changed
103 OnConvert
*proc_cnvt
; ///< callback procedure when loading value mechanism fails
104 SettingCategory cat
; ///< assigned categories of the setting
108 SettingDescBase desc
; ///< Settings structure (going to configuration file)
109 SaveLoad save
; ///< Internal structure (going to savegame, parts to config)
111 bool IsEditable(bool do_command
= false) const;
112 SettingType
GetType() const;
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 */
122 typedef SettingDesc SettingDescGlobVarList
;
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
);
129 #endif /* SETTINGS_INTERNAL_H */