view mde/gui/content/options.d @ 95:2a364c7d82c9

Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes. Fixed a minor bug where layouts with the same id but without shared alignments would be messed up. Tracked down the "nothing trawn until a resize" bug (see jobs.txt). If widgets throw during creation they're now replaced by debug widgets. Function pointers are converted to delegates using a safer method.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 06 Nov 2008 11:07:18 +0000
parents 9520cc0448e5
children
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;

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
}