Mercurial > projects > mde
annotate mde/content/Items.d @ 128:41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
WMScreen.init removed; code moved to this() since class is now created by main() instead of a static this().
Fix for SwitchWidget not passing events. Still some resizing bugs evident in SwitchWidget :-(
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Wed, 14 Jan 2009 20:24:14 +0000 |
parents | c9843fbaac88 |
children | 264028f4115a |
rev | line source |
---|---|
62
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
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 |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
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; |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
16 /************************************************************************************************** |
108
c9fc2d303178
Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
107
diff
changeset
|
17 * A generic way to access content items. Also loads translations on-demand. |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
18 *************************************************************************************************/ |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
19 module mde.content.Items; |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
20 |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
21 import mde.content.miscContent; |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
22 import mde.gui.exception; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
23 |
113
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
24 import imde = mde.imde; |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
25 import mde.lookup.Options; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
26 import mde.lookup.Translation; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
27 |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
28 debug { |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
29 import tango.util.log.Log : Log, Logger; |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
30 private Logger logger; |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
31 static this () { |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
32 logger = Log.getLogger ("mde.gui.content.Items"); |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
33 } |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
34 } |
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
35 |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
36 /** Get a specific content item. |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
37 * |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
38 * loadTranslation() $(B must) be called before this function. |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
39 * |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
40 * E.g. get ("Options.MiscOptions.L10n") returns miscOpts.L10n, |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
41 * Items.get ("Options.MiscOptions") returns a ContentList of all misc options. */ |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
42 Content get (char[] item) { |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
43 assert (currentL10n is miscOpts.L10n(), "must call loadTranslation (code error)"); |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
44 char[] orig = item; // item is modified by head() |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
45 |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
46 char[] h = head (item); |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
47 if (h == "Options") { |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
48 if (item is null) |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
49 return Options.allContentList; |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
50 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
51 h = head (item); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
52 auto p = h in Options.optionsClasses; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
53 if (p) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
54 if (item == null) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
55 return p.contentList; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
56 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
57 auto q = (h = head (item)) in p.content; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
58 if (q && item is null) // enforce item is an exact match |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
59 return *q; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
104
diff
changeset
|
60 } |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
61 } else if (h == "imde") { |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
62 h = head (item); |
113
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
63 if (h == "menu" && item is null) |
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
64 return imde.menu; |
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
65 else if (h == "quit" && item is null) |
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
66 return imde.quit; |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
67 } else if (h == "dynamic") { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
68 auto i = head (item) in items; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
69 if (i) return *i; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
70 } |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
71 |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
72 return new ErrorContent ("Error: bad content specifier", orig); |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
73 } |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
74 |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
75 /** Creates some content on first run (required by get()). |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
76 * |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
77 * If the correct translation strings are not loaded, this loads them. */ |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
78 void loadTranslation () { |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
79 if (currentL10n is miscOpts.L10n()) return; |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
80 |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
81 // Create Option classes' ContentLists if necessary: |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
82 if (Options.allContentList is null) { |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
83 Content[] list; |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
84 list.length = Options.optionsClasses.length; |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
85 size_t i; |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
86 foreach (n,opts; Options.optionsClasses) { |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
87 opts.contentList = new ContentList (n, opts.content); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
88 list[i++] = opts.contentList; |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
89 } |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
90 Options.allContentList = new ContentList ("Options", list); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
91 } |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
92 |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
93 Translation trl; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
94 Translation.Entry trle; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
95 |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
96 // Translate Options: |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
97 with (Options.allContentList) { |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
98 trle = Translation.get (symbol).getStruct (symbol); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
99 name (trle.name, trle.desc); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
100 } |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
101 foreach (n,opts; Options.optionsClasses) { |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
102 trl = Translation.get (n); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
103 trle = trl.getStruct (n); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
104 opts.contentList.name (trle.name, trle.desc); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
105 foreach (s, v; opts.content) { |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
106 trle = trl.getStruct (s); |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
107 v.name (trle.name, trle.desc); |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
108 IContentList cl = cast(IContentList) v; |
115
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
109 if (cl) { |
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
110 foreach (i,c; cl.list) { |
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
111 trle = trl.getStruct (c.symbol); |
1b1e2297e2fc
Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
112 c.name (trle.name, trle.desc); |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
113 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
114 } |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
115 } |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
116 } |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
117 |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
118 // Translate imde: |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
119 trl = Translation.get ("imde"); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
120 trle = trl.getStruct ("menu"); |
113
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
121 imde.menu.name (trle.name, trle.desc); |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
122 trle = trl.getStruct ("quit"); |
113
9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
123 imde.quit.name (trle.name, trle.desc); |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
124 |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
125 // Translate dynamic content: |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
126 if (items.length) { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
127 trl = Translation.get ("dynamic"); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
128 foreach (n,item; items) { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
129 trle = trl.getStruct (n); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
130 item.name (trle.name, trle.desc); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
131 IContentList cl = cast(IContentList) item; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
132 if (cl) { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
133 foreach (i,c; cl.list) { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
134 trle = trl.getStruct (c.symbol); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
135 c.name (trle.name, trle.desc); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
136 } |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
137 } |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
138 } |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
139 } |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
140 |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
141 currentL10n = miscOpts.L10n(); |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
142 } |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
143 |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
144 /** Add content c with name c.symbol, so that translations are loaded for it and it can be |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
145 * returned by get ("dynamic."~c.symbol). */ |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
146 Content addContent (Content c) { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
147 items[c.symbol] = c; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
148 return c; |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
149 } |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
150 |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
151 private: |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
152 // NOTE: possibly add all content to this list. Lookups would be faster. |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
153 Content[char[]] items; // dynamically added content |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
154 |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
155 /** Takes the string "head.tail" where tail may contain '.' but head does not, returns "head", |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
156 * with str set to "tail". */ |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
157 char[] head (ref char[] str) { |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
158 size_t i = 0; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
159 while (i < str.length && str[i] != '.') |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
160 ++i; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
161 char[] ret = str[0..i]; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
162 if (i == str.length) |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
163 str = null; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
164 else |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
165 str = str[i+1..$]; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
166 return ret; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
167 } |
104
ee209602770d
Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
168 |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
108
diff
changeset
|
169 char[] currentL10n; // Strings will be reloaded if this is not miscOpts.L10n(). |