comparison mde/gui/content/Items.d @ 104:ee209602770d

Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options. Tweaked translation strings (added name and desc to Options classes). Replaced Options.addSubClass (class, "name") with Options.this("name").
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 26 Nov 2008 13:07:46 +0000
parents 42e241e7be3e
children
comparison
equal deleted inserted replaced
103:42e241e7be3e 104:ee209602770d
22 import mde.gui.exception; 22 import mde.gui.exception;
23 23
24 import mde.lookup.Options; 24 import mde.lookup.Options;
25 import mde.lookup.Translation; 25 import mde.lookup.Translation;
26 26
27 debug {
28 import tango.util.log.Log : Log, Logger;
29 private Logger logger;
30 static this () {
31 logger = Log.getLogger ("mde.gui.content.Items");
32 }
33 }
34
27 /** Get a specific content item. 35 /** Get a specific content item.
28 * 36 *
29 * E.g. get ("Options.MiscOptions.L10n") returns miscOpts.L10n, 37 * E.g. get ("Options.MiscOptions.L10n") returns miscOpts.L10n,
30 * Items.get ("Options.MiscOptions") returns a ContentList of all misc options. */ 38 * Items.get ("Options.MiscOptions") returns a ContentList of all misc options. */
31 IContent get (char[] item) { 39 IContent get (char[] item) {
35 throw new ContentItemException (h); 43 throw new ContentItemException (h);
36 } 44 }
37 45
38 /** Same as calling get("Options."~item). */ 46 /** Same as calling get("Options."~item). */
39 IContent getOptions (char[] item) { 47 IContent getOptions (char[] item) {
48 if (item is null) {
49 IContent[] list;
50 list.length = Options.optionsClasses.length;
51 size_t i;
52 foreach (n,opts; Options.optionsClasses) {
53 if (opts.name is null) loadTransl (opts, n);
54 list[i++] = new ContentList (opts.content, opts.name, opts.desc);
55 }
56
57 return new ContentList (list, "Options");
58 }
40 char[] h = head (item); 59 char[] h = head (item);
41 auto p = h in Options.optionsClasses; 60 auto p = h in Options.optionsClasses;
42 if (p) { 61 if (p) {
43 if (!p.transLoaded) { 62 if (p.name is null) loadTransl (*p, h);
44 Translation trans = Translation.load ("L10n/"~h);
45 foreach (s, v; p.content) {
46 Translation.Entry transled = trans.getStruct (s);
47 v.name (transled.name, transled.desc);
48 }
49 p.transLoaded = true;
50 }
51 63
52 if (item == null) 64 if (item == null)
53 return new ContentList (p.content); 65 return new ContentList (p.content, p.name, p.desc);
54 66
55 auto q = (h = head (item)) in p.content; 67 auto q = (h = head (item)) in p.content;
56 if (q && item is null) // enforce item is an exact match 68 if (q && item is null) // enforce item is an exact match
57 return *q; 69 return *q;
58 } 70 }
71 str = null; 83 str = null;
72 else 84 else
73 str = str[i+1..$]; 85 str = str[i+1..$];
74 return ret; 86 return ret;
75 } 87 }
88
89 void loadTransl (Options p, char[] n) {
90 debug logger.trace ("Loading translation strings for Options."~n);
91 Translation trans = Translation.load ("L10n/"~n);
92 Translation.Entry transled = trans.getStruct (n);
93 p.name = transled.name;
94 p.desc = transled.desc;
95 foreach (s, v; p.content) {
96 transled = trans.getStruct (s);
97 v.name (transled.name, transled.desc);
98 }
99 }