mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
added multiple choice field
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@35 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -11,9 +11,9 @@
|
||||
// ----------------------------------------------------------------------------- : BooleanField
|
||||
|
||||
BooleanField::BooleanField() {
|
||||
// choices->choices.push_back(new_shared1<Choice>(_("yes")));
|
||||
// choices->choices.push_back(new_shared1<Choice>(_("no")));
|
||||
// choices->initIds();
|
||||
choices->choices.push_back(new_shared1<Choice>(_("yes")));
|
||||
choices->choices.push_back(new_shared1<Choice>(_("no")));
|
||||
choices->initIds();
|
||||
}
|
||||
|
||||
StyleP BooleanField::newStyle(const FieldP& thisP) const {
|
||||
|
||||
@@ -43,6 +43,9 @@ IMPLEMENT_REFLECTION(ChoiceField) {
|
||||
ChoiceField::Choice::Choice()
|
||||
: first_id(0)
|
||||
{}
|
||||
ChoiceField::Choice::Choice(const String& name)
|
||||
: first_id(0), name(name)
|
||||
{}
|
||||
|
||||
|
||||
bool ChoiceField::Choice::isGroup() const {
|
||||
|
||||
@@ -42,6 +42,9 @@ class ChoiceField : public Field {
|
||||
/// An item that can be chosen for this field
|
||||
class ChoiceField::Choice {
|
||||
public:
|
||||
Choice();
|
||||
Choice(const String& name);
|
||||
|
||||
String name; ///< Name/value of the item
|
||||
String default_name; ///< A default item, if this is a group and default_name.empty() there is no default
|
||||
vector<ChoiceP> choices; ///< Choices and sub groups in this group
|
||||
@@ -51,8 +54,6 @@ class ChoiceField::Choice {
|
||||
*/
|
||||
int first_id;
|
||||
|
||||
Choice();
|
||||
|
||||
/// Is this a group?
|
||||
bool isGroup() const;
|
||||
/// Can this Choice itself be chosen?
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/field/multiple_choice.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceField
|
||||
|
||||
MultipleChoiceField::MultipleChoiceField()
|
||||
: minimum_selection(0)
|
||||
, maximum_selection(1000000)
|
||||
{}
|
||||
|
||||
StyleP MultipleChoiceField::newStyle(const FieldP& thisP) const {
|
||||
return new_shared<MultipleChoiceStyle>();
|
||||
}
|
||||
|
||||
ValueP MultipleChoiceField::newValue(const FieldP& thisP) const {
|
||||
return new_shared<MultipleChoiceValue>();
|
||||
}
|
||||
|
||||
String MultipleChoiceField::typeName() const {
|
||||
return _("multiple choice");
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(MultipleChoiceField) {
|
||||
REFLECT_BASE(ChoiceField);
|
||||
REFLECT(minimum_selection);
|
||||
REFLECT(maximum_selection);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceStyle
|
||||
|
||||
MultipleChoiceStyle::MultipleChoiceStyle()
|
||||
: direction(HORIZONTAL)
|
||||
, spacing(0)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(Direction) {
|
||||
VALUE_N("horizontal", HORIZONTAL);
|
||||
VALUE_N("vertical", VERTICAL);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(MultipleChoiceStyle) {
|
||||
REFLECT_BASE(ChoiceStyle);
|
||||
REFLECT(direction);
|
||||
REFLECT(spacing);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceValue
|
||||
|
||||
IMPLEMENT_REFLECTION_NAMELESS(MultipleChoiceValue) {
|
||||
REFLECT_BASE(ChoiceValue);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#ifndef HEADER_DATA_FIELD_MULTIPLE_CHOICE
|
||||
#define HEADER_DATA_FIELD_MULTIPLE_CHOICE
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <data/field/choice.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceField
|
||||
|
||||
/// A ChoiceField where multiple choices can be selected simultaniously
|
||||
class MultipleChoiceField : public ChoiceField {
|
||||
public:
|
||||
MultipleChoiceField();
|
||||
|
||||
UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously?
|
||||
|
||||
virtual ValueP newValue(const FieldP& thisP) const;
|
||||
virtual StyleP newStyle(const FieldP& thisP) const;
|
||||
virtual String typeName() const;
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceStyle
|
||||
|
||||
enum Direction {
|
||||
HORIZONTAL, VERTICAL
|
||||
};
|
||||
|
||||
/// The Style for a MultipleChoiceField
|
||||
class MultipleChoiceStyle : public ChoiceStyle {
|
||||
public:
|
||||
MultipleChoiceStyle();
|
||||
|
||||
Direction direction; ///< In what direction are choices layed out?
|
||||
double spacing; ///< Spacing between choices (images) in pixels
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceValue
|
||||
|
||||
/// The Value in a MultipleChoiceField
|
||||
/** The value is stored as "<choice>, <choice>, <choice>"
|
||||
* The choices must be ordered by id
|
||||
*/
|
||||
class MultipleChoiceValue : public ChoiceValue {
|
||||
public:
|
||||
// no extra data
|
||||
|
||||
/// Splits the value, stores the selected choices in the out parameter
|
||||
void get(vector<String>& out);
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
Reference in New Issue
Block a user