annotate mde/options.d @ 22:249eb6620685

Changes to Options, particularly regarding window sizes. Window sizes for fullscreen and windowed modes are now independant. Window resizes by the WM are now persistant. Options class contents are now generated by templates. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 25 Mar 2008 12:24:04 +0000
parents a60cbb7359dd
children 47478557428d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
1 /* LICENSE BLOCK
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
2 Part of mde: a Modular D game-oriented Engine
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
4
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
5 This program is free software; you can redistribute it and/or modify it under the terms of
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
6 the GNU General Public License, version 2, as published by the Free Software Foundation.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
7
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
8 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
10 See the GNU General Public License for more details.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
11
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
12 You should have received a copy of the GNU General Public License along
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
13 with this program; if not, write to the Free Software Foundation, Inc.,
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
15
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** This module handles stored options, currently all except input maps.
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 *
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
19 * and ease saving and loading of values. The Options class is only really designed around handling
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
20 * small numbers of variables for now.
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 */
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 module mde.options;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mde.exception;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
26 import mde.mergetag.Reader;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
27 import mde.mergetag.Writer;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
28 import mde.mergetag.DataSet;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 import mde.mergetag.exception;
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
30 import mde.resource.paths;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 import tango.scrapple.text.convert.parseTo : parseTo;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 import tango.scrapple.text.convert.parseFrom : parseFrom;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 import tango.util.log.Log : Log, Logger;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
37 /** Base class for handling options. This class itself will handle no options and should not be
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
38 * instantiated, but sub-classes handle options.
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
39 *
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
40 * Each sub-class provides named variables for maximal-speed reading & writing. Sub-class references
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
41 * are stored by name, and will be available after pre-init has run (DO NOT access before this).
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 *
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
43 * The static class keeps track of all Options class instances for global loading and saving.
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
44 *
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
45 * Details: Options sub-classes hold associative arrays of pointers to all option variables, with a
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
46 * char[] id. This list is used for saving, loading and to provide generic GUI options screens. The
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
47 * built-in support in Options is only for bool, int and char[] types (a float type may get added).
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 */
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
49 class Options : IDataSection
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 {
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
51 // No actual options are stored by this class. However, much of the infrastructure is
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
52 // present since it need not be redefined in sub-classes.
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
53
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
54 // The "pointer lists":
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
55 protected bool* [ID] optsBool;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
56 protected char[]*[ID] optsCharA;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
57 protected int* [ID] optsInt;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
59 //BEGIN Mergtag loading/saving code
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 void addTag (char[] tp, ID id, char[] dt) {
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
61 if (tp == "bool") {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
62 bool** p = id in optsBool;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
63 if (p !is null) **p = parseTo!(bool) (dt);
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
64 } else if (tp == "char[]") {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
65 char[]** p = id in optsCharA;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
66 if (p !is null) **p = parseTo!(char[]) (dt);
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
67 } else if (tp == "int") {
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
68 int** p = id in optsInt;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
69 if (p !is null) **p = parseTo!(int) (dt);
12
bff0d802cb7d Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 11
diff changeset
70 }
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 }
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 void writeAll (ItemDelg dlg) {
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
73 foreach (ID id, bool* val; optsBool) dlg ("bool" , id, parseFrom!(bool ) (*val));
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
74 foreach (ID id, char[]* val; optsCharA) dlg ("char[]", id, parseFrom!(char[]) (*val));
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
75 foreach (ID id, int* val; optsInt) dlg ("int" , id, parseFrom!(int ) (*val));
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 }
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
77 //END Mergtag loading/saving code
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
78
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
79 //BEGIN Static
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
80 // Each individual section
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
81 static OptionsMisc misc;
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
82 static OptionsVideo video;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 /* Load/save options from file.
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 *
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 * If the file doesn't exist, no reading is attempted (options are left at default values).
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 */
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
88 private static const fileName = "options";
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 static void load () {
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
90 // Create all uncreated sections now, so that if we return early they are still created.
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
91 if (misc is null) misc = new OptionsMisc;
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
92 if (video is null) video = new OptionsVideo;
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
93
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
94 // Check it exists (if not it should still be created on exit).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
95 // Don't bother checking it's not a folder, because it could still be a block or something.
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
96 if (!confDir.exists (fileName)) return;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 12
diff changeset
98 IReader reader;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 try {
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
100 reader = confDir.makeMTReader (fileName, PRIORITY.LOW_HIGH);
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
101 reader.dataSecCreator = delegate IDataSection(ID id) {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
102 /* Recognise each defined section, and return null for unrecognised sections. */
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
103
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
104 if (id == cast(ID) "misc") return misc;
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
105 else if (id == cast(ID) "video") return video;
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
106 else return null;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 };
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 reader.read;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 } catch (MTException e) {
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 logger.error ("Mergetag exception occurred:");
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 logger.error (e.msg);
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 throw new optionsLoadException ("Loading aborted: mergetag exception");
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 }
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 }
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 static void save () {
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
116 DataSet ds = new DataSet();
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
117 ds.sec[cast(ID) "misc"] = misc;
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
118 ds.sec[cast(ID) "video"] = video;
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 IWriter writer;
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 try {
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
122 writer = confDir.makeMTWriter (fileName, ds);
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 writer.write();
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 } catch (MTException e) {
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 logger.error ("Mergetag exception occurred; saving aborted:");
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 logger.error (e.msg);
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 //FIXME: currently nothing done besides logging the error
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 }
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 }
12
bff0d802cb7d Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 11
diff changeset
130
bff0d802cb7d Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 11
diff changeset
131 private static Logger logger;
bff0d802cb7d Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 11
diff changeset
132 static this() {
bff0d802cb7d Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 11
diff changeset
133 logger = Log.getLogger ("mde.options");
bff0d802cb7d Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 11
diff changeset
134 }
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
135 //END Static
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
136
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
137 //BEGIN Templates
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
138 template store(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
139 alias A a;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
140 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
141 template decRecurse(char[] A, B...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
142 static if (B.length) const char[] decRecurse = A ~ ", " ~ decRecurse!(B);
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
143 else const char[] decRecurse = A;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
144 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
145 template decBool(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
146 const char[] decBool = "bool " ~ decRecurse!(A) ~ ";\n";
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
147 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
148 template decCharA(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
149 const char[] decCharA = "char[] " ~ decRecurse!(A) ~ ";\n";
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
150 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
151 template decInt(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
152 const char[] decInt = "int " ~ decRecurse!(A) ~ ";\n";
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
153 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
154 template aaRecurse(char[] A, B...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
155 static if (B.length) const char[] aaRecurse = "\""~A~"\"[]:&"~A ~ ", " ~ aaRecurse!(B);
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
156 else const char[] aaRecurse = "\""~A~"\"[]:&"~A;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
157 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
158 template aaBool(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
159 const char[] aaBool = "optsBool = [" ~ aaRecurse!(A) ~ "];\n";
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
160 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
161 template aaInt(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
162 const char[] aaInt = "optsInt = [" ~ aaRecurse!(A) ~ "];\n";
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
163 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
164 template aaCharA(A...) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
165 const char[] aaCharA = "optsCharA = [" ~ aaRecurse!(A) ~ "];\n";
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
166 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
167 //END Templates
11
b940f267419e Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 }
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
169
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
170 /* NOTE: These Options classes use templates to ease inserting contents.
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
171 *
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
172 * Each entry has an I18nTranslation entry; see data/L10n/ClassName.mtt for descriptions.
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
173 *
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
174 * To create a new class, copy and paste, and update Options.
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
175 */
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
176
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
177 /** A home for all miscellaneous options, at least for now. */
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
178 class OptionsMisc : Options {
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
179 alias store!("useThreads") BOOL;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
180 alias store!("logLevel") INT;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
181 alias store!("L10n") CHARA;
18
56a42ec95024 Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
182
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
183 mixin (decBool!(BOOL.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
184 mixin (decInt!(INT.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
185 mixin (decCharA!(CHARA.a));
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
186
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
187 this () {
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
188 mixin (aaBool!(BOOL.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
189 mixin (aaInt!(INT.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
190 mixin (aaCharA!(CHARA.a));
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
191 }
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
192 }
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
193
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
194 /** All video options. */
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
195 class OptionsVideo : Options {
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
196 alias store!("fullscreen","hardware","resizable","noFrame") BOOL;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
197 alias store!("screenW","screenH","windowW","windowH") INT;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
198 //alias store!() CHARA;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
199
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
200 mixin (decBool!(BOOL.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
201 mixin (decInt!(INT.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
202 //mixin (decCharA!(CHARA.a));
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
203
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
204 this () {
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
205 mixin (aaBool!(BOOL.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
206 mixin (aaInt!(INT.a));
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
207 //mixin (aaCharA!(CHARA.a));
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
208 }
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 18
diff changeset
209 }