Mercurial > projects > mde
annotate mde/lookup/Options.d @ 134:7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 14:59:45 +0000 |
parents | 1b1e2297e2fc |
children |
rev | line source |
---|---|
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
16 /** This module handles loading and saving of, and allows generic access to named option variables |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
17 * of a simple type (see Options.TYPES). */ |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
18 module mde.lookup.Options; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 |
134
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
20 import mde.file.paths; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 import mde.exception; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
23 public import mde.content.AStringContent; |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
24 import mde.content.miscContent; // ContentLists used by content.Items |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
25 |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
26 import mde.file.mergetag.Reader; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
27 import mde.file.mergetag.Writer; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
28 import mde.file.mergetag.DataSet; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
29 import mde.file.serialize; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 import tango.core.Exception : ArrayBoundsException; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 import tango.util.log.Log : Log, Logger; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
33 private Logger logger; |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
34 static this() { |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
35 logger = Log.getLogger ("mde.lookup.Options"); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
36 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
38 /************************************************************************************************* |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
39 * This class and the OptionChanges class contain all the functionality. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
40 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
41 * Options are stored in derived class instances, tracked by the static portion of Options. Each |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
42 * value is stored in a ValueContent class, whose value can be accessed with opCall, opCast and |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
43 * opAssign. These class objects can be given callbacks called whenever their value is changed. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
44 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
45 * Public static methods allow getting the list of tracked sub-class instances, and loading and saving |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
46 * option values. A public non-static method allows generic access to option variables. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
47 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
48 * Generic access to Options is of most use to a gui, allowing Options to be edited generically. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
49 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
50 * The easiest way to use Options is to use an existing sub-class as a template, e.g. MiscOptions. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
51 *************************************************************************************************/ |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 class Options : IDataSection |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
54 /** Do not instantiate directly; use a sub-class. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
55 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
56 * CTOR adds any created instance to the list of classes tracked statically for loading/saving |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
57 * and generic access. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
58 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
59 * Normally instances are created by a static CTOR. */ |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
60 protected this(char[] name) |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
61 in { |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
62 assert (((cast(ID) name) in subClasses) is null); // Don't allow a silent replacement |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
63 } body { |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
64 subClasses[cast(ID) name] = this; |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
65 } |
84
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
66 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
67 //BEGIN Templates: internal |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
68 package { |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
69 // All supported types, for generic handling via templates. It should be possible to change |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
70 // the supported types simply by changing this list. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
71 template store(A...) { alias A store; } |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
72 alias store!(bool, int, double, char[]) TYPES; // types handled |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
73 |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
74 // Get name of a type. Basically just stringof, but special handling for arrays. |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
75 // Use TName!(T) for a valid symbol name, and T.stringof for a type. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
76 template TName(T : T[]) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
77 const char[] TName = TName!(T) ~ "A"; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
78 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
79 template TName(T) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
80 const char[] TName = T.stringof; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
81 } |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
82 } |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
83 private { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
84 // True if type is one of A |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
85 template TIsIn(T, A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
86 static if (A.length) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
87 static if (is(T == A[0])) |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
88 const bool TIsIn = true; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
89 else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
90 const bool TIsIn = TIsIn!(T,A[1..$]); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
91 } else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
92 const bool TIsIn = false; // no more possibilities |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
93 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
94 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
95 // For addTag |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
96 template addTagMixin(T, A...) { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
97 const char[] ifBlock = `if (tp == "`~T.stringof~`") { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
98 auto p = id in opts; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
99 if (p) { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
100 auto q = cast(`~ContentN!(T)~`) (*p); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
101 if (q) q.assignNoCb = parseTo!(`~T.stringof~`) (dt); |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
102 } |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
103 }`; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
104 static if (A.length) |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
105 const char[] addTagMixin = ifBlock~` else `~addTagMixin!(A).addTagMixin; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
106 else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
107 const char[] addTagMixin = ifBlock; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
108 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
109 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
110 //END Templates: internal |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
111 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
112 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
113 //BEGIN Static |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
114 static { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
115 /** Get the hash map of Options classes. READ-ONLY. */ |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
116 Options[ID] optionsClasses () { |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
117 return subClasses; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
118 } |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
119 |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
120 // Track all sections for saving/loading/other generic handling. |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
121 private Options[ID] subClasses; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
122 private bool changed = false; // any changes at all, i.e. do we need to save? |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
123 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
124 ContentList allContentList; /// Initially null; created by mde.content.Items on use. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
125 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
126 /* Load/save options from file. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
127 * |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
128 * If the file doesn't exist, no reading is attempted (options are left at default values). |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
129 */ |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
130 private const fileName = "options"; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
131 void load () { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
132 try { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
133 IReader reader; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
134 reader = confDir.makeMTReader (fileName, PRIORITY.LOW_HIGH); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
135 reader.dataSecCreator = delegate IDataSection(ID id) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
136 /* Recognise each defined section, and return null for unrecognised sections. */ |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
137 Options* p = id in subClasses; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
138 if (p !is null) return *p; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
139 else return null; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
140 }; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
141 reader.read; |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
142 } catch (NoFileException e) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
143 // Just return. Options file will be created on exit. |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
144 } catch (Exception e) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
145 logger.warn ("Loading options failed: "~e.msg); |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
146 logger.warn ("If warning persists, delete the offending file."); // FIXME - delete the bad file somehow |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
147 } |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
148 foreach (opts; subClasses) |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
149 opts.validate; // post-load checking of variables |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
150 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
151 void save () { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
152 if (!changed) return; // no changes to save |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
153 debug logger.trace ("Saving options..."); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
154 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
155 DataSet ds = new DataSet(); |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
156 foreach (id, subOpts; subClasses) |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
157 ds.sec[id] = subOpts.optionChanges; |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
158 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
159 // Read locally-stored options |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
160 try { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
161 IReader reader; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
162 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
163 reader.dataSecCreator = delegate IDataSection(ID id) { |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
164 debug logger.warn ("New section appearing in options.mtt during save (ignored & overwritten): "~id); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
165 return null; // All recognised sections are already in the dataset. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
166 }; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
167 reader.read; |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
168 } catch (NoFileException) { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
169 // No user file exists; not an error. |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
170 } catch (Exception e) { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
171 // Log a message and continue, overwriting the file: |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
172 logger.error ("Loading options aborted: " ~ e.msg); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
173 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
174 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
175 try { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
176 IWriter writer; |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
177 writer = confDir.makeMTWriter (fileName, ds); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
178 writer.write(); |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
179 } catch (Exception e) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
180 logger.error ("Saving options aborted: "~e.msg); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
181 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
182 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
183 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
184 //END Static |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
185 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
186 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
187 //BEGIN Non-static |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
188 /// Get all Options stored with a ValueContent. |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
189 Content[char[]] content() { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
190 return opts; |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
191 } |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
192 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
193 /** Variable validate function, called when options are loaded from file. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
194 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
195 * This can be overridden to enforce limits on option variables, etc. */ |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
196 protected void validate() {} |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
197 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
198 /** All content in a ContentList. Initially null; mde.content.Items creates this and loads the |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
199 * translation strings of all sub-content upon first request involving this Options instance. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
200 ContentList contentList; |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
102
diff
changeset
|
201 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
202 protected { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
203 OptionChanges optionChanges; // all changes to options (for saving) |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
204 Content[char[]] opts; // generic list of option values |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
205 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
206 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
207 //BEGIN Mergetag loading/saving code |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
208 void addTag (char[] tp, ID id, char[] dt) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
209 mixin(addTagMixin!(TYPES).addTagMixin); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
210 } |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
94
diff
changeset
|
211 // Only OptionChanges writes stuff |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
94
diff
changeset
|
212 void writeAll (ItemDelg dlg) {} |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
213 //END Mergetag loading/saving code |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
214 //END Non-static |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
215 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
216 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
217 //BEGIN Templates: impl & optionsThis |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
218 private { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
219 // Return index of first comma, or halts if not found. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
220 template cIndex(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
221 static if (A.length == 0) |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
222 static assert (false, "Error in implementation"); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
223 else static if (A[0] == ',') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
224 const size_t cIndex = 0; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
225 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
226 const size_t cIndex = 1 + cIndex!(A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
227 } |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
228 // Return index of first semi-colon, or halts if not found. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
229 template scIndex(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
230 static if (A.length == 0) |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
231 static assert (false, "Error: no trailing semi-colon"); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
232 else static if (A[0] == ';') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
233 const size_t scIndex = 0; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
234 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
235 const size_t scIndex = 1 + scIndex!(A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
236 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
237 /* Look for "type symbols;" in A and return symbols as a comma separated list of names |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
238 (even if type is encountered more than once). Output may contain spaces and will have a |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
239 trailing comma unless no match was found in which case an empty string is returned. |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
240 Assumes scIndex always returns less than A.$ . */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
241 template parseT(char[] type, char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
242 static if (A.length < type.length + 1) // end of input, no match |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
243 const char[] parseT = ""; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
244 else static if (A[0] == ' ') // leading whitespace: skip |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
245 const char[] parseT = parseT!(type, A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
246 else static if (A[0..type.length] == type && A[type.length] == ' ') // match |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
247 const char[] parseT = A[type.length+1 .. scIndex!(A)] ~ "," ~ |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
248 parseT!(type, A[scIndex!(A)+1 .. $]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
249 else // no match |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
250 const char[] parseT = parseT!(type, A[scIndex!(A)+1 .. $]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
251 } |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
252 // strip Trailing Comma |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
253 template sTC(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
254 static if (A.length && A[$-1] == ',') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
255 const char[] sTC = A[0..$-1]; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
256 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
257 const char[] sTC = A; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
258 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
259 // if B is empty return an empty string otherswise return what's below: |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
260 template catOrNothing(char[] A,char[] B) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
261 static if (B.length) |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
262 const char[] catOrNothing = A~` `~sTC!(B)~";\n"; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
263 else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
264 const char[] catOrNothing = ``; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
265 } |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
266 // foreach decl... |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
267 template createContents(T, char[] A) { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
268 static if (A.length == 0) |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
269 const char[] createContents = ""; |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
270 else static if (A[0] == ' ') |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
271 const char[] createContents = createContents!(T,A[1..$]); |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
272 else |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
273 const char[] createContents = "opts[\""~A[0..cIndex!(A)]~"\"] = (" ~ A[0..cIndex!(A)]~ " = new "~ContentN!(T)~" (\""~A[0..cIndex!(A)]~"\")).addCallback (&optionChanges.set);\n"~ |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
274 createContents!(T,A[cIndex!(A)+1..$]); |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
275 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
276 // for recursing on TYPES |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
277 template optionsThisInternal(char[] A, B...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
278 static if (B.length) { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
279 const char[] optionsThisInternal = createContents!(B[0],parseT!(B[0].stringof,A))~ |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
280 optionsThisInternal!(A,B[1..$]); |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
281 } else |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
282 const char[] optionsThisInternal = ``; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
283 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
284 template declValsInternal(char[] A, B...) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
285 static if (B.length) { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
286 const char[] declValsInternal = catOrNothing!(ContentN!(B[0]),parseT!(B[0].stringof,A)) ~ declValsInternal!(A,B[1..$]); |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
287 } else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
288 const char[] declValsInternal = ``; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
289 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
290 } protected { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
291 /** Declares the values. |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
292 * |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
293 * Basic types are replaced with a ValueContent class to keep the option synchronized and |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
294 * generalize use. */ |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
295 template declVals(char[] A) { |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
94
diff
changeset
|
296 const char[] declVals = declValsInternal!(A, TYPES); |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
297 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
298 /** Produces the implementation code to go in the constuctor. */ |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
299 template optionsThis(char[] A) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
300 const char[] optionsThis = |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
301 "optionChanges = new OptionChanges;\n" ~ |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
302 "super (name);\n" ~ |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
94
diff
changeset
|
303 optionsThisInternal!(A,TYPES); |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
304 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
305 /+ Needs too many custom parameters to be worth it? Plus makes class less readable. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
306 /** Produces the implementation code to go in the static constuctor. */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
307 template optClassAdd(char[] symb) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
308 const char[] optClassAdd = symb ~ "=new "~classinfo(this).name~";\n";//Options.addOptionsClass("~symb~", );\n"; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
309 }+/ |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
310 /** mixin impl("type symbol[, symbol[...]];[type symbol[...];][...]") |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
311 * |
62
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
312 * Where type is one of bool, int, double, char[]. E.g. |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
313 * --- |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
314 * mixin (impl ("bool a, b; int i;")); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
315 * --- |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
316 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
317 * In case this() needs to be customized, mixin(impl!(A)) is equivalent to: |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
318 * --- |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
319 * mixin (declVals!(A)~` |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
320 this (char[] name) { |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
321 `~optionsThis!(A)~` |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
322 }`); |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
323 * --- |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
324 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
325 * Notes: Only use space as whitespace (no new-lines or tabs). Make sure to add a trailing |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
326 * semi-colon (;) or you'll get told off! :D |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
327 * In general errors aren't reported well. Trial with pragma (msg, impl!(...)); if |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
328 * necessary. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
329 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
330 * Extending: mixins could also be used for the static this() {...} or even the whole |
62
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
331 * class, but doing so would rather decrease readability of any implementation. */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
332 template impl(char[] A /+, char[] symb+/) { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
333 const char[] impl = declVals!(A)~"\nthis(char[] name){\n"~optionsThis!(A)~"}"; |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
334 // ~"\nstatic this(){\n"~optClassAdd!(symb)~"}" |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
335 } |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
336 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
337 //END Templates: impl & optionsThis |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
338 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
339 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
340 /************************************************************************************************* |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
341 * Special class to store all locally changed options. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
342 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
343 * This allows only changed options and those already stored in the user directory to be saved, so |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
344 * that other options can be merged in from a global directory, allowing any options not locally |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
345 * set to be changed globally. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
346 *************************************************************************************************/ |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
347 class OptionChanges : IDataSection |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
348 { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
349 //BEGIN Templates |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
350 private { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
351 alias Options.TName TName; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
352 alias Options.TYPES TYPES; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
353 template Vars(A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
354 static if (A.length) { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
355 const char[] Vars = A[0].stringof~`[ID] `~TName!(A[0])~`s;` ~ Vars!(A[1..$]); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
356 } else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
357 const char[] Vars = ``; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
358 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
359 // For addTag |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
360 template addTagMixin(T, A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
361 const char[] ifBlock = `if (tp == "`~T.stringof~`") { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
362 if ((id in `~TName!(T)~`s) is null) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
363 `~TName!(T)~`s[id] = parseTo!(`~T.stringof~`) (dt); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
364 }`; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
365 static if (A.length) |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
366 const char[] addTagMixin = ifBlock~` else `~addTagMixin!(A).addTagMixin; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
367 else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
368 const char[] addTagMixin = ifBlock; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
369 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
370 // For writeAll |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
371 template writeAllMixin(A...) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
372 static if (A.length) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
373 const char[] writeAllMixin = |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
374 `foreach (id, val; `~TName!(A[0])~`s) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
375 dlg ("`~A[0].stringof~`", id, serialize (val)); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
376 ` ~ writeAllMixin!(A[1..$]); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
377 } else |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
378 const char[] writeAllMixin = ``; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
379 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
380 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
381 //END Templates |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
382 // These store the actual values, but are never accessed directly except when initially added. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
383 // optsX store pointers to each item added along with the ID and are used for access. |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
384 mixin(Vars!(TYPES)); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
385 |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
386 void set (Content c) { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
387 union U { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
388 BoolContent bc; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
389 StringContent sc; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
390 IntContent ic; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
391 DoubleContent dc; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
392 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
393 U u; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
394 if ((u.bc = cast(BoolContent) c) !is null) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
395 bools[u.bc.symbol] = u.bc(); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
396 else if ((u.sc = cast(StringContent) c) !is null) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
397 charAs[u.sc.symbol] = u.sc(); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
398 else if ((u.ic = cast(IntContent) c) !is null) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
399 ints[u.ic.symbol] = u.ic(); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
400 else if ((u.dc = cast(DoubleContent) c) !is null) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
401 doubles[u.dc.symbol] = u.dc(); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
402 Options.changed = true; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
403 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
404 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
405 this () {} |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
406 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
407 //BEGIN Mergetag loading/saving code |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
408 // HIGH_LOW priority: only load symbols not currently existing |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
409 void addTag (char[] tp, ID id, char[] dt) { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
410 mixin (addTagMixin!(TYPES).addTagMixin); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
411 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
412 void writeAll (ItemDelg dlg) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
413 mixin(writeAllMixin!(TYPES)); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
414 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
415 //END Mergetag loading/saving code |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
416 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
417 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
418 /** A home for all miscellaneous options. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
419 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
420 * Also a template for deriving Options; comments explain what does what. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
421 * |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
422 * Translation strings for the options are looked for in data/L10n/SectionName.mtt where |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
423 * this ("SectionName") names the instance. */ |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
424 MiscOptions miscOpts; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
425 class MiscOptions : Options { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
426 /* The key step is to mixin impl. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
427 The syntax is just as simple variables are declared, which is how these options used to be |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
428 stored. Now they're enclosed in ValueContent classes; e.g. "char[] L10n;" is replaced with |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
429 "TextContent L10n;". The pragma statement can be uncommented to see what code gets injected |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
430 (note: pragma () gets called each time the module is imported as well as when it's compiled). |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
431 impl creates a this() function; if you want to include your own CTOR see impl's ddoc. */ |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
432 const A = "bool exitImmediately; int maxThreads, logLevel, logOutput; double pollInterval; char[] L10n;"; |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
433 //pragma (msg, impl!(A)); |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
434 //mixin (impl!(A)); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
435 BoolContent exitImmediately; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
436 IntContent maxThreads, logOutput; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
437 EnumContent logLevel; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
438 DoubleContent pollInterval; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
439 StringContent L10n; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
440 |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
441 this(char[] name){ |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
442 optionChanges = new OptionChanges; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
443 super (name); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
444 opts["exitImmediately"] = (exitImmediately = new BoolContent ("exitImmediately")).addCallback (&optionChanges.set); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
445 opts["maxThreads"] = (maxThreads = new IntContent ("maxThreads")).addCallback (&optionChanges.set); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
446 opts["logLevel"] = (logLevel = new EnumContent ("logLevel", ["Trace", "Info", "Warn", "Error", "Fatal", "None"])).addCallback (&optionChanges.set); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
447 opts["logOutput"] = (logOutput = new IntContent ("logOutput")).addCallback (&optionChanges.set); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
448 opts["pollInterval"] = (pollInterval = new DoubleContent ("pollInterval")).addCallback (&optionChanges.set); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
449 opts["L10n"] = (L10n = new StringContent ("L10n")).addCallback (&optionChanges.set); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
450 } |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
451 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
452 // Overriding validate allows limits to be enforced on variables at load time. Currently |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
453 // there's no infrastructure for enforcing limits when options are set at run-time. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
454 override void validate() { |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
455 // Try to enforce sensible values, whilst being reasonably flexible: |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
456 if (maxThreads() < 1 || maxThreads() > 64) { |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
457 logger.warn ("maxThreads must be in the range 1-64. Defaulting to 4."); |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
458 maxThreads = 4; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
459 } |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
460 if (pollInterval() !<= 0.1 || pollInterval() !>= 0.0) |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
461 pollInterval = 0.01; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
462 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
463 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
464 // A static CTOR is a good place to create the instance (it must be created before init runs). |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
465 static this() { |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
466 // Adds instance to Options's tracking; the string is the section name in the config files. |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
467 miscOpts = new MiscOptions ("MiscOptions"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
468 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
469 } |