view mde/gui/content/options.d @ 91:4d5d53e4f881

Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too. Some debugging improvements. When multiple .mtt files are read for merging, files with invalid headers are ignored and no error is thrown so long as at least one file os valid.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 16 Oct 2008 17:43:48 +0100
parents 61ea26abe4dd
children 9520cc0448e5
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;
}

//FIXME - todo.txt
class ContentOptionText : ContentOption
{
    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 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);
    }+/
}

abstract class ContentOption : IContent
{
    // 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
}