Mercurial > projects > mde
view mde/gui/content/options.d @ 94:9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
This should facilitate generic option editing widgets.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 17:45:49 +0100 |
parents | 4d5d53e4f881 |
children | 2a364c7d82c9 |
line wrap: on
line source
/* 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; debug { import tango.util.log.Log : Log, Logger; private Logger logger; static this () { logger = Log.getLogger ("mde.gui.content.options"); } } class OptionList { this (char[] optsName) { auto p = optsName in Options.subClasses; if (p is null) { logger.error ("OptionList created with invalid options class name."); return; // list is empty, nothing displayed } Options opts = *p; Translation trans = Translation.load ("L10n/"~optsName); char[][] list = opts.list; textOpts.length = list.length + opts.content.length; size_t i; foreach (s; list) { Translation.Entry transled = trans.getStruct (s); textOpts[i] = new OptionContent(opts, s, transled.name, transled.desc); ++i; } foreach (s, v; opts.content) { Translation.Entry transled = trans.getStruct (s); v.name (transled.name, transled.desc); // set Content name & desc. Only needs doing once textOpts[i++] = v; } } IContent[] list () { return textOpts; } protected: IContent[] textOpts; } //FIXME - todo.txt class OptionContent : IContent { this (Options o, char[] s, char[] name, char[] desc) { opts = o; symb = s; name_ = name; desc_ = desc; } char[] toString (uint i) { if (i == 0) return "dummy"; //opts.get!(char[])(symb); else if (i == 1) return name_; else if (i == 2) return desc_; } /+char[] value () { return opts.get!(char[])(symb); } void value (char[] v) { opts.set!(char[])(symb, v); }+/ 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 }