Mercurial > projects > mde
annotate mde/gui/content/options.d @ 79:61ea26abe4dd
Moved mde/mergetag/parse/parse(To/From) to mde/mergetag/(de)serialize. Implemented (de)serialization of structs.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 05 Aug 2008 11:51:51 +0100 |
parents | 08d3b6bcf891 |
children | 4d5d53e4f881 |
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 |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
56 class ContentOptionText : ContentOption |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
57 { |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
58 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
|
59 opts = o; |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 symb = s; |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 name_ = name; |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
62 desc_ = desc; |
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 |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 char[] toString () { |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 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
|
67 } |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
68 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
|
69 opts.set!(char[])(symb, v); |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
70 } |
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 |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 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
|
74 { |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
75 abstract char[] toString (); |
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 //char[] value (); /// Get/set the value. |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
78 void value (char[] v); /// ditto |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
79 |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
80 // Get the symbol name (useful?) |
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 /// 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
|
83 char[] name () { |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
84 return name_; |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
85 } |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
86 |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 /// 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
|
88 char[] description () { |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
89 return desc_; |
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 |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
92 protected: |
08d3b6bcf891
Added a file which should have been in the last commit!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 } |