changeset 73:08d3b6bcf891

Added a file which should have been in the last commit!
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 07 Jul 2008 15:53:58 +0100
parents 159775502bb4
children cee261eba249
files mde/gui/content/options.d
diffstat 1 files changed, 96 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mde/gui/content/options.d	Mon Jul 07 15:53:58 2008 +0100
@@ -0,0 +1,96 @@
+/* LICENSE BLOCK
+Part of mde: a Modular D game-oriented Engine
+Copyright © 2007-2008 Diggory Hardy
+
+This program is free software: you can redistribute it and/or modify it under the terms
+of the GNU General Public License as published by the Free Software Foundation, either
+version 2 of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+/** Content classes for holding options.
+ *
+ * Currently they use a rather poor implementation: each is responsible for grabbing its value and
+ * updating the option, and cannot be notified if that option is changed externally.
+ */
+module mde.gui.content.options;
+
+import mde.gui.content.Content;
+
+import mde.lookup.Options;
+import mde.lookup.Translation;
+
+class OptionList
+{
+    this (Options opts, char[] i18nOptionsName)
+    in { assert (opts !is null, "OptionList: invalid Options instance"); }
+    body {
+        Translation trans = Translation.load (i18nOptionsName);
+        
+        char[][] list = opts.list!(char[])();
+        
+        textOpts.length = list.length;
+        foreach (i,s; list) {
+            Translation.Entry transled = trans.getStruct (s);
+            textOpts[i] = new ContentOptionText(opts, s, transled.str, transled.desc);
+        }
+    }
+    
+    ContentOption[] list () {
+        return textOpts;
+    }
+    
+    static OptionList trial () {
+        return new OptionList (miscOpts, "OptionsMisc");
+    }
+    
+protected:
+    ContentOption[] textOpts;
+}
+
+class ContentOptionText : ContentOption
+{
+    this (Options o, char[] s, char[] name, char[] desc) {
+        opts = o;
+        symb = s;
+        name_ = name;
+        desc_ = desc;
+    }
+    
+    char[] toString () {
+        return opts.get!(char[])(symb);
+    }
+    void value (char[] v) {
+        opts.set!(char[])(symb, v);
+    }
+}
+
+abstract class ContentOption : IContent
+{
+    abstract char[] toString ();
+    
+    //char[] value ();		/// Get/set the value.
+    void value (char[] v);	/// ditto
+    
+    // Get the symbol name (useful?)
+    
+    /// Get the translated name
+    char[] name () {
+        return name_;
+    }
+    
+    /// Get the description (translated)
+    char[] description () {
+        return desc_;
+    }
+    
+protected:
+    Options opts;	// the set of options within which our option lies
+    char[]  symb;	// the symbol name of our option
+    char[] name_, desc_;// name and description, loaded by lookup.Translation
+}