Mercurial > projects > mde
comparison 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 |
comparison
equal
deleted
inserted
replaced
93:08a4ae11454b | 94:9520cc0448e5 |
---|---|
23 import mde.gui.content.Content; | 23 import mde.gui.content.Content; |
24 | 24 |
25 import mde.lookup.Options; | 25 import mde.lookup.Options; |
26 import mde.lookup.Translation; | 26 import mde.lookup.Translation; |
27 | 27 |
28 debug { | |
29 import tango.util.log.Log : Log, Logger; | |
30 private Logger logger; | |
31 static this () { | |
32 logger = Log.getLogger ("mde.gui.content.options"); | |
33 } | |
34 } | |
35 | |
28 class OptionList | 36 class OptionList |
29 { | 37 { |
30 this (Options opts, char[] i18nOptionsName) | 38 this (char[] optsName) |
31 in { assert (opts !is null, "OptionList: invalid Options instance"); } | 39 { |
32 body { | 40 auto p = optsName in Options.subClasses; |
33 Translation trans = Translation.load (i18nOptionsName); | 41 if (p is null) { |
42 logger.error ("OptionList created with invalid options class name."); | |
43 return; // list is empty, nothing displayed | |
44 } | |
45 Options opts = *p; | |
34 | 46 |
35 char[][] list = opts.list!(char[])(); | 47 Translation trans = Translation.load ("L10n/"~optsName); |
48 char[][] list = opts.list; | |
36 | 49 |
37 textOpts.length = list.length; | 50 textOpts.length = list.length + opts.content.length; |
38 foreach (i,s; list) { | 51 size_t i; |
52 foreach (s; list) { | |
39 Translation.Entry transled = trans.getStruct (s); | 53 Translation.Entry transled = trans.getStruct (s); |
40 textOpts[i] = new ContentOptionText(opts, s, transled.name, transled.desc); | 54 textOpts[i] = new OptionContent(opts, s, transled.name, transled.desc); |
55 ++i; | |
41 } | 56 } |
57 foreach (s, v; opts.content) { | |
58 Translation.Entry transled = trans.getStruct (s); | |
59 v.name (transled.name, transled.desc); // set Content name & desc. Only needs doing once | |
60 textOpts[i++] = v; | |
61 } | |
62 | |
42 } | 63 } |
43 | 64 |
44 ContentOption[] list () { | 65 IContent[] list () { |
45 return textOpts; | 66 return textOpts; |
46 } | 67 } |
47 | 68 |
48 static OptionList trial () { | |
49 return new OptionList (miscOpts, "L10n/OptionsMisc"); | |
50 } | |
51 | |
52 protected: | 69 protected: |
53 ContentOption[] textOpts; | 70 IContent[] textOpts; |
54 } | 71 } |
55 | 72 |
56 //FIXME - todo.txt | 73 //FIXME - todo.txt |
57 class ContentOptionText : ContentOption | 74 class OptionContent : IContent |
58 { | 75 { |
59 this (Options o, char[] s, char[] name, char[] desc) { | 76 this (Options o, char[] s, char[] name, char[] desc) { |
60 opts = o; | 77 opts = o; |
61 symb = s; | 78 symb = s; |
62 name_ = name; | 79 name_ = name; |
63 desc_ = desc; | 80 desc_ = desc; |
64 } | 81 } |
65 | 82 |
66 char[] toString (uint i) { | 83 char[] toString (uint i) { |
67 if (i == 0) | 84 if (i == 0) |
68 return opts.get!(char[])(symb); | 85 return "dummy"; //opts.get!(char[])(symb); |
69 else if (i == 1) | 86 else if (i == 1) |
70 return name_; | 87 return name_; |
71 else if (i == 2) | 88 else if (i == 2) |
72 return desc_; | 89 return desc_; |
73 } | 90 } |
75 return opts.get!(char[])(symb); | 92 return opts.get!(char[])(symb); |
76 } | 93 } |
77 void value (char[] v) { | 94 void value (char[] v) { |
78 opts.set!(char[])(symb, v); | 95 opts.set!(char[])(symb, v); |
79 }+/ | 96 }+/ |
80 } | |
81 | |
82 abstract class ContentOption : IContent | |
83 { | |
84 // Get the symbol name (useful?) | |
85 /+ | |
86 /// Get the translated name | |
87 char[] name () { | |
88 return name_; | |
89 } | |
90 | |
91 /// Get the description (translated) | |
92 char[] description () { | |
93 return desc_; | |
94 } | |
95 +/ | |
96 protected: | 97 protected: |
97 Options opts; // the set of options within which our option lies | 98 Options opts; // the set of options within which our option lies |
98 char[] symb; // the symbol name of our option | 99 char[] symb; // the symbol name of our option |
99 char[] name_, desc_;// name and description, loaded by lookup.Translation | 100 char[] name_, desc_;// name and description, loaded by lookup.Translation |
100 } | 101 } |