diff mde/lookup/Options.d @ 105:08651e8a8c51

Quit button, big changes to content system. Moved mde.gui.content to mde.content to reflect it's not only used by the gui. Split Content module into Content and AStringContent. New AContent and EventContent class. Callbacks are now generic and implemented in AContent. Renamed TextContent to StringContent and ValueContent to AStringContent.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 29 Nov 2008 12:36:39 +0000
parents ee209602770d
children fe061009029d
line wrap: on
line diff
--- a/mde/lookup/Options.d	Wed Nov 26 13:07:46 2008 +0000
+++ b/mde/lookup/Options.d	Sat Nov 29 12:36:39 2008 +0000
@@ -20,7 +20,7 @@
 import mde.setup.paths;
 import mde.exception;
 
-public import mde.gui.content.Content;
+public import mde.content.AStringContent;
 
 import mde.file.mergetag.Reader;
 import mde.file.mergetag.Writer;
@@ -96,8 +96,8 @@
             const char[] ifBlock = `if (tp == "`~T.stringof~`") {
     auto p = id in opts;
     if (p) {
-        auto q = cast(`~VContentN!(T)~`) (*p);
-        if (q) q.assignNoCB = parseTo!(`~T.stringof~`) (dt);
+        auto q = cast(`~ContentN!(T)~`) (*p);
+        if (q) q.assignNoCb = parseTo!(`~T.stringof~`) (dt);
     }
 }`;
             static if (A.length)
@@ -120,6 +120,8 @@
         private Options[ID] subClasses;
         private bool changed = false;	// any changes at all, i.e. do we need to save?
 	
+	ContentList allContentList;	/// Initially null; created by mde.content.Items on use.
+	
     	/* Load/save options from file.
          *
          * If the file doesn't exist, no reading is attempted (options are left at default values).
@@ -183,7 +185,7 @@
     
     //BEGIN Non-static
     /// Get all Options stored with a ValueContent.
-    ValueContent[char[]] content() {
+    AContent[char[]] content() {
         return opts;
     }
     
@@ -192,13 +194,13 @@
      * This can be overridden to enforce limits on option variables, etc. */
     protected void validate() {}
     
-    /** Translated name and description of the instance. mde.gui.content.Items loads these and the
-     * translation strings of all enclosed options simultaneously. */
-    char[] name, desc;
+    /** All content in a ContentList. Initially null; mde.content.Items creates this and loads the
+    * translation strings of all sub-content upon first request involving this Options instance. */
+    ContentList contentList;
     
     protected {
         OptionChanges optionChanges;	// all changes to options (for saving)
-        ValueContent[char[]] opts;	// generic list of option values
+	AContent[char[]] opts;	// generic list of option values
     }
     
     //BEGIN Mergetag loading/saving code
@@ -267,7 +269,7 @@
             else static if (A[0] == ' ')
                 const char[] createContents = createContents!(T,A[1..$]);
             else
-                const char[] createContents = "opts[\""~A[0..cIndex!(A)]~"\"] = " ~ A[0..cIndex!(A)]~ " = (new "~VContentN!(T)~" (\""~A[0..cIndex!(A)]~"\")).addChangeCb (&optionChanges.set);\n"~
+                const char[] createContents = "opts[\""~A[0..cIndex!(A)]~"\"] = (" ~ A[0..cIndex!(A)]~ " = new "~ContentN!(T)~" (\""~A[0..cIndex!(A)]~"\")).addCallback (&optionChanges.set);\n"~
                 createContents!(T,A[cIndex!(A)+1..$]);
         }
         // for recursing on TYPES
@@ -280,7 +282,7 @@
         }
         template declValsInternal(char[] A, B...) {
             static if (B.length) {
-                const char[] declValsInternal = catOrNothing!(VContentN!(B[0]),parseT!(B[0].stringof,A)) ~ declValsInternal!(A,B[1..$]);
+                const char[] declValsInternal = catOrNothing!(ContentN!(B[0]),parseT!(B[0].stringof,A)) ~ declValsInternal!(A,B[1..$]);
             } else
                 const char[] declValsInternal = ``;
         }
@@ -353,17 +355,6 @@
             } else
                 const char[] Vars = ``;
         }
-        // For set
-        template Set(A...) {
-            static if (A.length) {
-                const char[] Set= `void set (char[] s,`~A[0].stringof~` v) {
-   Options.changed = true;
-   `~TName!(A[0])~`s[s] = v;
-}`~ Set!(A[1..$]);
-            } else
-                const char[] Set = ``;
-        }
-        
         // For addTag
         template addTagMixin(T, A...) {
             const char[] ifBlock = `if (tp == "`~T.stringof~`") {
@@ -390,9 +381,26 @@
     // These store the actual values, but are never accessed directly except when initially added.
     // optsX store pointers to each item added along with the ID and are used for access.
     mixin(Vars!(TYPES));
-    // set (char[] symbol, T value);    (not templates but for each type T)
-    mixin(Set!(TYPES));
     
+    void set (AContent c) {
+	union U {
+	    BoolContent bc;
+	    StringContent sc;
+	    IntContent ic;
+	    DoubleContent dc;
+	}
+	U u;
+	if ((u.bc = cast(BoolContent) c) !is null)
+	    bools[u.bc.symbol] = u.bc();
+	else if ((u.sc = cast(StringContent) c) !is null)
+	    charAs[u.sc.symbol] = u.sc();
+	else if ((u.ic = cast(IntContent) c) !is null)
+	    ints[u.ic.symbol] = u.ic();
+	else if ((u.dc = cast(DoubleContent) c) !is null)
+	    doubles[u.dc.symbol] = u.dc();
+	Options.changed = true;
+    }
+	
     this () {}
     
     //BEGIN Mergetag loading/saving code