view mde/gui/content/options.d @ 79:61ea26abe4dd

Moved mde/mergetag/parse/parse(To/From) to mde/mergetag/(de)serialize. Implemented (de)serialization of structs.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 05 Aug 2008 11:51:51 +0100
parents 08d3b6bcf891
children 4d5d53e4f881
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;

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.name, transled.desc);
        }
    }
    
    ContentOption[] list () {
        return textOpts;
    }
    
    static OptionList trial () {
        return new OptionList (miscOpts, "L10n/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
}