- Added 'package list' field type

- Some refactoring of the other field types

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@790 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-26 23:37:45 +00:00
parent 7b340db04f
commit d493394519
32 changed files with 573 additions and 94 deletions
+1 -5
View File
@@ -16,11 +16,7 @@ BooleanField::BooleanField() {
choices->initIds();
}
IMPLEMENT_FIELD_TYPE(Boolean)
String BooleanField::typeName() const {
return _("boolean");
}
IMPLEMENT_FIELD_TYPE(Boolean, "boolean");
IMPLEMENT_REFLECTION(BooleanField) {
REFLECT_BASE(Field); // NOTE: don't reflect as a ChoiceField
+1 -5
View File
@@ -20,11 +20,7 @@ ChoiceField::ChoiceField()
, default_name(_("Default"))
{}
IMPLEMENT_FIELD_TYPE(Choice)
String ChoiceField::typeName() const {
return _("choice");
}
IMPLEMENT_FIELD_TYPE(Choice, "choice");
void ChoiceField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
+1 -5
View File
@@ -18,11 +18,7 @@ ColorField::ColorField()
, default_name(_("Default"))
{}
IMPLEMENT_FIELD_TYPE(Color)
String ColorField::typeName() const {
return _("color");
}
IMPLEMENT_FIELD_TYPE(Color, "color");
void ColorField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
+1 -5
View File
@@ -10,11 +10,7 @@
// ----------------------------------------------------------------------------- : ImageField
IMPLEMENT_FIELD_TYPE(Image)
String ImageField::typeName() const {
return _("image");
}
IMPLEMENT_FIELD_TYPE(Image, "image");
IMPLEMENT_REFLECTION(ImageField) {
REFLECT_BASE(Field);
+1 -5
View File
@@ -11,11 +11,7 @@
// ----------------------------------------------------------------------------- : InfoField
IMPLEMENT_FIELD_TYPE(Info)
String InfoField::typeName() const {
return _("info");
}
IMPLEMENT_FIELD_TYPE(Info, "info");
void InfoField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
+1 -5
View File
@@ -15,11 +15,7 @@ MultipleChoiceField::MultipleChoiceField()
, maximum_selection(1000000)
{}
IMPLEMENT_FIELD_TYPE(MultipleChoice)
String MultipleChoiceField::typeName() const {
return _("multiple choice");
}
IMPLEMENT_FIELD_TYPE(MultipleChoice, "multiple choice");
IMPLEMENT_REFLECTION(MultipleChoiceField) {
REFLECT_BASE(ChoiceField);
+83
View File
@@ -0,0 +1,83 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <data/field/package_choice.hpp>
#include <util/io/package_manager.hpp>
// ----------------------------------------------------------------------------- : PackageChoiceField
IMPLEMENT_FIELD_TYPE(PackageChoice, "package choice");
void PackageChoiceField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script. initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(PackageChoiceField) {
REFLECT_BASE(Field);
REFLECT(script);
REFLECT(match);
REFLECT(initial);
REFLECT(required);
}
// ----------------------------------------------------------------------------- : PackageChoiceStyle
PackageChoiceStyle::PackageChoiceStyle(const PackageChoiceFieldP& field)
: Style(field)
{}
int PackageChoiceStyle::update(Context& ctx) {
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
}
/*void PackageChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
}*/
IMPLEMENT_REFLECTION(PackageChoiceStyle) {
REFLECT_BASE(Style);
REFLECT(font);
}
// ----------------------------------------------------------------------------- : PackageChoiceValue
String PackageChoiceValue::toString() const {
PackagedP pack = getPackage();
if (pack) return pack->short_name;
else return _("");
}
PackagedP PackageChoiceValue::getPackage() const {
if (package_name.empty()) return nullptr;
else return packages.openAny(package_name, true);
}
bool PackageChoiceValue::update(Context& ctx) {
bool change = field().script.invokeOn(ctx, package_name);
Value::update(ctx);
return change;
}
void PackageChoiceValue::reflect(Reader& tag) {
REFLECT_NAMELESS(package_name);
}
void PackageChoiceValue::reflect(Writer& tag) {
REFLECT_NAMELESS(package_name);
}
void PackageChoiceValue::reflect(GetDefaultMember& tag) {
if (!package_name.empty() && package_name != field().initial) {
// add a space to the name, to indicate the dependency doesn't have to be marked
// see also SymbolFontRef::loadFont
REFLECT_NAMELESS(_(" ") + package_name);
} else {
REFLECT_NAMELESS(package_name);
}
}
void PackageChoiceValue::reflect(GetMember& tag) {}
+69
View File
@@ -0,0 +1,69 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_FIELD_PACKAGE_CHOICE
#define HEADER_DATA_FIELD_PACKAGE_CHOICE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field.hpp>
#include <data/font.hpp>
#include <script/scriptable.hpp>
DECLARE_POINTER_TYPE(Packaged);
// ----------------------------------------------------------------------------- : PackageChoiceField
DECLARE_POINTER_TYPE(PackageChoiceField);
DECLARE_POINTER_TYPE(PackageChoiceStyle);
DECLARE_POINTER_TYPE(PackageChoiceValue);
/// A field for PackageChoice values, it contains a list of choices for PackageChoices
class PackageChoiceField : public Field {
public:
PackageChoiceField() : required(true) {}
DECLARE_FIELD_TYPE(PackageChoice);
OptionalScript script; ///< Script to apply to all values
String match; ///< Package filenames to match
String initial; ///< Initial value
bool required; ///< Is selecting a package required?
virtual void initDependencies(Context&, const Dependency&) const;
};
// ----------------------------------------------------------------------------- : PackageChoiceStyle
/// The Style for a PackageChoiceField
class PackageChoiceStyle : public Style {
public:
PackageChoiceStyle(const PackageChoiceFieldP& field);
DECLARE_STYLE_TYPE(PackageChoice);
Font font; ///< Font to use for the text
virtual int update(Context&);
};
// ----------------------------------------------------------------------------- : PackageChoiceValue
/// The Value in a PackageChoiceField
class PackageChoiceValue : public Value {
public:
PackageChoiceValue(const PackageChoiceFieldP& field) : Value(field), package_name(field->initial) {}
DECLARE_VALUE_TYPE(PackageChoice, String);
ValueType package_name; ///< The selected package
/// Get the package (if it is set)
PackagedP getPackage() const;
virtual bool update(Context&);
};
// ----------------------------------------------------------------------------- : EOF
#endif
+1 -5
View File
@@ -11,11 +11,7 @@
// ----------------------------------------------------------------------------- : SymbolField
IMPLEMENT_FIELD_TYPE(Symbol)
String SymbolField::typeName() const {
return _("symbol");
}
IMPLEMENT_FIELD_TYPE(Symbol, "symbol");
IMPLEMENT_REFLECTION(SymbolField) {
REFLECT_BASE(Field);
+1 -5
View File
@@ -17,11 +17,7 @@ TextField::TextField()
, default_name(_("Default"))
{}
IMPLEMENT_FIELD_TYPE(Text)
String TextField::typeName() const {
return _("text");
}
IMPLEMENT_FIELD_TYPE(Text, "text");
void TextField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);