diff --git a/src/data/action/value.cpp b/src/data/action/value.cpp index 1b2882e9..d5c1fdf3 100644 --- a/src/data/action/value.cpp +++ b/src/data/action/value.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include // ----------------------------------------------------------------------------- : ValueAction @@ -30,6 +31,7 @@ inline void swap_value(ColorValue& a, ColorValue ::ValueType& b inline void swap_value(ImageValue& a, ImageValue ::ValueType& b) { swap(a.filename, b); a.last_update.update(); } inline void swap_value(SymbolValue& a, SymbolValue ::ValueType& b) { swap(a.filename, b); a.last_update.update(); } inline void swap_value(TextValue& a, TextValue ::ValueType& b) { swap(a.value, b); a.last_update.update(); } +inline void swap_value(PackageChoiceValue& a, PackageChoiceValue ::ValueType& b) { swap(a.package_name, b); } inline void swap_value(MultipleChoiceValue& a, MultipleChoiceValue::ValueType& b) { swap(a.value, b.value); swap(a.last_change, b.last_change); @@ -68,6 +70,7 @@ ValueAction* value_action(const Card* card, const ChoiceValueP& value, c ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable& new_value) { return new SimpleValueAction (card, value, new_value); } ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction(card, value, new_value); } ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction(card, value, new_value); } +ValueAction* value_action(const Card* card, const PackageChoiceValueP& value, const String& new_value) { return new SimpleValueAction(card, value, new_value); } ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, const Defaultable& new_value, const String& last_change) { MultipleChoiceValue::ValueType v = { new_value, last_change }; return new SimpleValueAction(card, value, v); diff --git a/src/data/action/value.hpp b/src/data/action/value.hpp index 07072355..ad623d3e 100644 --- a/src/data/action/value.hpp +++ b/src/data/action/value.hpp @@ -28,6 +28,7 @@ DECLARE_POINTER_TYPE(MultipleChoiceValue); DECLARE_POINTER_TYPE(ColorValue); DECLARE_POINTER_TYPE(ImageValue); DECLARE_POINTER_TYPE(SymbolValue); +DECLARE_POINTER_TYPE(PackageChoiceValue); // ----------------------------------------------------------------------------- : ValueAction (based class) @@ -50,6 +51,7 @@ ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, c ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable& new_value); ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value); ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value); +ValueAction* value_action(const Card* card, const PackageChoiceValueP& value, const String& new_value); // ----------------------------------------------------------------------------- : Text diff --git a/src/data/field.cpp b/src/data/field.cpp index d4ca08c1..ed98fb0e 100644 --- a/src/data/field.cpp +++ b/src/data/field.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include DECLARE_TYPEOF_COLLECTION(StyleListener*); @@ -80,6 +81,7 @@ intrusive_ptr read_new(Reader& reader) { else if (type == _("symbol")) return new_intrusive(); else if (type == _("color")) return new_intrusive(); else if (type == _("info")) return new_intrusive(); + else if (type == _("package choice")) return new_intrusive(); else if (type.empty()) { reader.warning(_ERROR_1_("expected key", _("type"))); throw ParseError(_ERROR_("aborting parsing")); diff --git a/src/data/field.hpp b/src/data/field.hpp index 0d1b1787..adb9e190 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -253,7 +253,7 @@ inline String type_name(const Value&) { virtual String typeName() const // implement newStyle and newValue -#define IMPLEMENT_FIELD_TYPE(Type) \ +#define IMPLEMENT_FIELD_TYPE(Type, NAME) \ StyleP Type ## Field::newStyle(const FieldP& thisP) const { \ assert(thisP.get() == this); \ return new_intrusive1(static_pointer_cast(thisP));\ @@ -267,6 +267,9 @@ inline String type_name(const Value&) { } \ ValueP Type ## Value::clone() const { \ return new_intrusive1(*this); \ + } \ + String Type ## Field::typeName() const { \ + return _(NAME); \ } #define DECLARE_STYLE_TYPE(Type) \ diff --git a/src/data/field/boolean.cpp b/src/data/field/boolean.cpp index ff72951f..aa77fcc3 100644 --- a/src/data/field/boolean.cpp +++ b/src/data/field/boolean.cpp @@ -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 diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 311b9a46..a357d9bf 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -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); diff --git a/src/data/field/color.cpp b/src/data/field/color.cpp index 62104940..cf8fd342 100644 --- a/src/data/field/color.cpp +++ b/src/data/field/color.cpp @@ -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); diff --git a/src/data/field/image.cpp b/src/data/field/image.cpp index 31b53ea3..648faa99 100644 --- a/src/data/field/image.cpp +++ b/src/data/field/image.cpp @@ -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); diff --git a/src/data/field/information.cpp b/src/data/field/information.cpp index 7766038d..6bc1b77f 100644 --- a/src/data/field/information.cpp +++ b/src/data/field/information.cpp @@ -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); diff --git a/src/data/field/multiple_choice.cpp b/src/data/field/multiple_choice.cpp index 4c9a5ce7..0b582bf5 100644 --- a/src/data/field/multiple_choice.cpp +++ b/src/data/field/multiple_choice.cpp @@ -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); diff --git a/src/data/field/package_choice.cpp b/src/data/field/package_choice.cpp new file mode 100644 index 00000000..07eb9e72 --- /dev/null +++ b/src/data/field/package_choice.cpp @@ -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 +#include + +// ----------------------------------------------------------------------------- : 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) {} diff --git a/src/data/field/package_choice.hpp b/src/data/field/package_choice.hpp new file mode 100644 index 00000000..3091ff19 --- /dev/null +++ b/src/data/field/package_choice.hpp @@ -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 +#include +#include +#include