comparison mde/content/Content.d @ 110:6acd96f8685f

Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui. Gave AContent support for multiple callbacks. New locale: "en".
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 05 Dec 2008 11:29:39 +0000
parents 08651e8a8c51
children fe061009029d
comparison
equal deleted inserted replaced
109:2a1428ec5344 110:6acd96f8685f
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15 15
16 /** The content system − common interface and a few classes without external dependencies. 16 /** The content system − common interface and a few classes without external dependencies.
17 */ 17 */
18 module mde.content.Content; 18 module mde.content.Content;
19
20 import util = mde.util;
19 21
20 debug { 22 debug {
21 import tango.util.log.Log : Log, Logger; 23 import tango.util.log.Log : Log, Logger;
22 private Logger logger; 24 private Logger logger;
23 static this () { 25 static this () {
66 void name (char[] n, char[] d = null) { 68 void name (char[] n, char[] d = null) {
67 name_ = n; 69 name_ = n;
68 desc_ = d; 70 desc_ = d;
69 } 71 }
70 72
71 /// Current implementation has 1 callback; can be changed to allow many. 73 /** Add a callback. Callbacks are called in the order added. */
72 EventContent addCallback (void delegate (AContent) cb) { 74 EventContent addCallback (void delegate (AContent) cb) {
73 this.cb = cb; 75 this.cb ~= cb;
76 return this;
77 }
78 /// ditto
79 EventContent addCallback (void function (AContent) cb) {
80 this.cb ~= util.toDg (cb);
74 return this; 81 return this;
75 } 82 }
76 83
77 char[] toString (uint i) { 84 char[] toString (uint i) {
78 return i == 0 ? "No value" 85 return i == 0 ? "No value"
81 : null; 88 : null;
82 } 89 }
83 90
84 /// End of an event, e.g. a button release or end of an edit (calls callbacks). 91 /// End of an event, e.g. a button release or end of an edit (calls callbacks).
85 void endEvent () { 92 void endEvent () {
86 if (cb) 93 foreach (dg; cb)
87 cb (this); 94 dg (this);
88 } 95 }
89 96
90 final char[] symbol; // Symbol name for this content 97 final char[] symbol; // Symbol name for this content
91 protected: 98 protected:
92 char[] name_, desc_; // name and description 99 char[] name_, desc_; // name and description
93 void delegate (AContent) cb; 100 void delegate (AContent) cb[];
94 } 101 }
95 102
96 // FIXME: needs changes to allow updating translated strings. Move to Content and extend AContent?
97 /** A generic way to handle a list of type IContent. */ 103 /** A generic way to handle a list of type IContent. */
98 class ContentList : AContent 104 class ContentList : AContent
99 { 105 {
100 this (char[] symbol, AContent[] list = null) { 106 this (char[] symbol, AContent[] list = null) {
101 list_.length = list.length; 107 list_.length = list.length;