annotate mde/gui/content/options.d @ 91:4d5d53e4f881

Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too. Some debugging improvements. When multiple .mtt files are read for merging, files with invalid headers are ignored and no error is thrown so long as at least one file os valid.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 16 Oct 2008 17:43:48 +0100
parents 61ea26abe4dd
children 9520cc0448e5
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
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 class OptionList
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 this (Options opts, char[] i18nOptionsName)
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 in { assert (opts !is null, "OptionList: invalid Options instance"); }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 body {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 Translation trans = Translation.load (i18nOptionsName);
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 char[][] list = opts.list!(char[])();
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 textOpts.length = list.length;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 foreach (i,s; list) {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 Translation.Entry transled = trans.getStruct (s);
79
61ea26abe4dd Moved mde/mergetag/parse/parse(To/From) to mde/mergetag/(de)serialize. Implemented (de)serialization of structs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 73
diff changeset
40 textOpts[i] = new ContentOptionText(opts, s, transled.name, transled.desc);
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 ContentOption[] list () {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 return textOpts;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 static OptionList trial () {
79
61ea26abe4dd Moved mde/mergetag/parse/parse(To/From) to mde/mergetag/(de)serialize. Implemented (de)serialization of structs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 73
diff changeset
49 return new OptionList (miscOpts, "L10n/OptionsMisc");
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 protected:
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 ContentOption[] textOpts;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55
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
56 //FIXME - todo.txt
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 class ContentOptionText : ContentOption
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 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
60 opts = o;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 symb = s;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 name_ = name;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 desc_ = desc;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65
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
66 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
67 if (i == 0)
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
68 return opts.get!(char[])(symb);
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
69 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
70 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
71 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
72 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
73 }
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 79
diff changeset
74 /+char[] value () {
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 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
76 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 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
78 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
79 }+/
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 }
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 abstract class ContentOption : IContent
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 // Get the symbol name (useful?)
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
85 /+
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 /// Get the translated name
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 char[] name () {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 return name_;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 }
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 /// Get the description (translated)
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 char[] description () {
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 return desc_;
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 }
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
95 +/
73
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 protected:
08d3b6bcf891 Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 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
98 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
99 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
100 }