annotate mde/gui/content/options.d @ 94:9520cc0448e5

Boolean options are now encapsulated within a Content class (currently an experiment). This should facilitate generic option editing widgets.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 23 Oct 2008 17:45:49 +0100
parents 4d5d53e4f881
children 2a364c7d82c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
08d3b6bcf891 Added a file which should have been in the last commit!
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
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
08d3b6bcf891 Added a file which should have been in the last commit!
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;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** Content classes for holding options.
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 *
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 * Currently they use a rather poor implementation: each is responsible for grabbing its value and
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 * updating the option, and cannot be notified if that option is changed externally.
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 */
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 module mde.gui.content.options;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import mde.gui.content.Content;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 import mde.lookup.Options;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import mde.lookup.Translation;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
28 debug {
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
29 import tango.util.log.Log : Log, Logger;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
30 private Logger logger;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
31 static this () {
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
32 logger = Log.getLogger ("mde.gui.content.options");
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
33 }
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
34 }
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
35
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 class OptionList
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 {
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
38 this (char[] optsName)
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
39 {
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
40 auto p = optsName in Options.subClasses;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
41 if (p is null) {
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
42 logger.error ("OptionList created with invalid options class name.");
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
43 return; // list is empty, nothing displayed
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
44 }
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
45 Options opts = *p;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
46
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
47 Translation trans = Translation.load ("L10n/"~optsName);
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
48 char[][] list = opts.list;
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
50 textOpts.length = list.length + opts.content.length;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
51 size_t i;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
52 foreach (s; list) {
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
53 Translation.Entry transled = trans.getStruct (s);
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
54 textOpts[i] = new OptionContent(opts, s, transled.name, transled.desc);
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
55 ++i;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
56 }
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
57 foreach (s, v; opts.content) {
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
58 Translation.Entry transled = trans.getStruct (s);
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
59 v.name (transled.name, transled.desc); // set Content name & desc. Only needs doing once
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
60 textOpts[i++] = v;
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
61 }
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
65 IContent[] list () {
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 return textOpts;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 protected:
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
70 IContent[] textOpts;
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
73 //FIXME - todo.txt
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
74 class OptionContent : IContent
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 this (Options o, char[] s, char[] name, char[] desc) {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 opts = o;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 symb = s;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 name_ = name;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 desc_ = desc;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
83 char[] toString (uint i) {
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
84 if (i == 0)
94
9520cc0448e5 Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
85 return "dummy"; //opts.get!(char[])(symb);
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
86 else if (i == 1)
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
87 return name_;
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
88 else if (i == 2)
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
89 return desc_;
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
90 }
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
91 /+char[] value () {
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 return opts.get!(char[])(symb);
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 void value (char[] v) {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 opts.set!(char[])(symb, v);
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
96 }+/
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 protected:
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 Options opts; // the set of options within which our option lies
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 char[] symb; // the symbol name of our option
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 char[] name_, desc_;// name and description, loaded by lookup.Translation
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 }