9723
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file settings_internal.h Functions and types used internally for the settings configurations. */
|
|
4 |
|
|
5 |
#ifndef SETTINGS_INTERNAL_H
|
|
6 |
#define SETTINGS_INTERNAL_H
|
|
7 |
|
|
8 |
#include "saveload.h"
|
|
9 |
|
|
10 |
/** Convention/Type of settings. This is then further specified if necessary
|
|
11 |
* with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h
|
|
12 |
* @see VarTypes
|
|
13 |
* @see SettingDescBase */
|
|
14 |
enum SettingDescTypeLong {
|
|
15 |
/* 4 bytes allocated a maximum of 16 types for GenericType */
|
|
16 |
SDT_BEGIN = 0,
|
|
17 |
SDT_NUMX = 0, ///< any number-type
|
|
18 |
SDT_BOOLX = 1, ///< a boolean number
|
|
19 |
SDT_ONEOFMANY = 2, ///< bitmasked number where only ONE bit may be set
|
|
20 |
SDT_MANYOFMANY = 3, ///< bitmasked number where MULTIPLE bits may be set
|
|
21 |
SDT_INTLIST = 4, ///< list of integers seperated by a comma ','
|
|
22 |
SDT_STRING = 5, ///< string with a pre-allocated buffer
|
|
23 |
SDT_END,
|
|
24 |
/* 10 more possible primitives */
|
|
25 |
};
|
|
26 |
|
|
27 |
template <> struct EnumPropsT<SettingDescTypeLong> : MakeEnumPropsT<SettingDescTypeLong, byte, SDT_BEGIN, SDT_END, SDT_END> {};
|
|
28 |
typedef TinyEnumT<SettingDescTypeLong> SettingDescType;
|
|
29 |
|
|
30 |
|
|
31 |
enum SettingGuiFlagLong {
|
|
32 |
/* 8 bytes allocated for a maximum of 8 flags
|
|
33 |
* Flags directing saving/loading of a variable */
|
|
34 |
SGF_NONE = 0,
|
|
35 |
SGF_0ISDISABLED = 1 << 0, ///< a value of zero means the feature is disabled
|
|
36 |
SGF_NOCOMMA = 1 << 1, ///< number without any thousand seperators (no formatting)
|
|
37 |
SGF_MULTISTRING = 1 << 2, ///< the value represents a limited number of string-options (internally integer)
|
|
38 |
SGF_NETWORK_ONLY = 1 << 3, ///< this setting only applies to network games
|
|
39 |
SGF_CURRENCY = 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate
|
|
40 |
SGF_NO_NETWORK = 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game
|
|
41 |
SGF_END = 1 << 6,
|
|
42 |
/* 3 more possible flags */
|
|
43 |
};
|
|
44 |
|
|
45 |
DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong);
|
|
46 |
template <> struct EnumPropsT<SettingGuiFlagLong> : MakeEnumPropsT<SettingGuiFlagLong, byte, SGF_NONE, SGF_END, SGF_END> {};
|
|
47 |
typedef TinyEnumT<SettingGuiFlagLong> SettingGuiFlag;
|
|
48 |
|
|
49 |
|
|
50 |
typedef int32 OnChange(int32 var); ///< callback prototype on data modification
|
|
51 |
typedef int32 OnConvert(const char *value); ///< callback prototype for convertion error
|
|
52 |
|
|
53 |
struct SettingDescBase {
|
|
54 |
const char *name; ///< name of the setting. Used in configuration file and for console
|
|
55 |
const void *def; ///< default value given when none is present
|
|
56 |
SettingDescType cmd; ///< various flags for the variable
|
|
57 |
SettingGuiFlag flags; ///< handles how a setting would show up in the GUI (text/currency, etc.)
|
|
58 |
int32 min, max; ///< minimum and maximum values
|
|
59 |
int32 interval; ///< the interval to use between settings in the 'patches' window. If interval is '0' the interval is dynamically determined
|
|
60 |
const char *many; ///< ONE/MANY_OF_MANY: string of possible values for this type
|
|
61 |
StringID str; ///< (translated) string with descriptive text; gui and console
|
|
62 |
OnChange *proc; ///< callback procedure for when the value is changed
|
|
63 |
OnConvert *proc_cnvt; ///< callback procedure when loading value mechanism fails
|
|
64 |
};
|
|
65 |
|
|
66 |
struct SettingDesc {
|
|
67 |
SettingDescBase desc; ///< Settings structure (going to configuration file)
|
|
68 |
SaveLoad save; ///< Internal structure (going to savegame, parts to config)
|
|
69 |
};
|
|
70 |
|
|
71 |
/* NOTE: The only difference between SettingDesc and SettingDescGlob is
|
|
72 |
* that one uses global variables as a source and the other offsets
|
|
73 |
* in a struct which are bound to a certain variable during runtime.
|
|
74 |
* The only way to differentiate between these two is to check if an object
|
|
75 |
* has been passed to the function or not. If not, then it is a global variable
|
|
76 |
* and save->variable has its address, otherwise save->variable only holds the
|
|
77 |
* offset in a certain struct */
|
|
78 |
typedef SettingDesc SettingDescGlobVarList;
|
|
79 |
|
|
80 |
enum IniGroupType {
|
|
81 |
IGT_VARIABLES = 0, ///< values of the form "landscape = hilly"
|
|
82 |
IGT_LIST = 1, ///< a list of values, seperated by \n and terminated by the next group block
|
|
83 |
};
|
|
84 |
|
|
85 |
const SettingDesc *GetPatchFromName(const char *name, uint *i);
|
|
86 |
bool SetPatchValue(uint index, const Patches *object, int32 value);
|
|
87 |
|
|
88 |
#endif /* SETTINGS_H */
|