paritially implemented MultipleChoice viewer/editor

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@222 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-03-21 18:04:09 +00:00
parent fddc389e24
commit 0c6068d6a2
14 changed files with 139 additions and 25 deletions
+8 -5
View File
@@ -212,11 +212,14 @@ IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
}
IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
VALUE_N("text", RENDER_TEXT);
VALUE_N("image", RENDER_IMAGE);
VALUE_N("both", RENDER_BOTH);
VALUE_N("hidden", RENDER_HIDDEN);
VALUE_N("image hidden", RENDER_HIDDEN_IMAGE);
VALUE_N("text", RENDER_TEXT);
VALUE_N("image", RENDER_IMAGE);
VALUE_N("both", RENDER_BOTH);
VALUE_N("hidden", RENDER_HIDDEN);
VALUE_N("image hidden", RENDER_HIDDEN_IMAGE);
VALUE_N("checklist", RENDER_TEXT_CHECKLIST);
VALUE_N("image checklist", RENDER_IMAGE_CHECKLIST);
VALUE_N("both checklist", RENDER_BOTH_CHECKLIST);
}
IMPLEMENT_REFLECTION(ChoiceStyle) {
+11 -7
View File
@@ -103,11 +103,15 @@ enum ChoicePopupStyle
};
// How should a choice value be rendered?
enum ChoiceRenderStyle
{ RENDER_TEXT = 0x01 // render the name as text
, RENDER_IMAGE = 0x10 // render an image
, RENDER_BOTH = RENDER_TEXT | RENDER_IMAGE
, RENDER_HIDDEN = 0x20 // don't render anything, only have a menu
, RENDER_HIDDEN_IMAGE = RENDER_HIDDEN | RENDER_IMAGE
{ RENDER_TEXT = 0x01 // render the name as text
, RENDER_IMAGE = 0x10 // render an image
, RENDER_HIDDEN = 0x20 // don't render anything, only have a menu
, RENDER_CHECKLIST = 0x100 // render as a checklist, intended for multiple choice
, RENDER_BOTH = RENDER_TEXT | RENDER_IMAGE
, RENDER_HIDDEN_IMAGE = RENDER_HIDDEN | RENDER_IMAGE
, RENDER_TEXT_CHECKLIST = RENDER_CHECKLIST | RENDER_TEXT
, RENDER_IMAGE_CHECKLIST = RENDER_CHECKLIST | RENDER_IMAGE
, RENDER_BOTH_CHECKLIST = RENDER_CHECKLIST | RENDER_BOTH
};
/// The Style for a ChoiceField
@@ -147,9 +151,9 @@ class ChoiceStyle : public Style {
/// The Value in a ChoiceField
class ChoiceValue : public Value {
public:
inline ChoiceValue(const ChoiceFieldP& field)
inline ChoiceValue(const ChoiceFieldP& field, bool initial_empty = false)
: Value(field)
, value(field->initial.empty()
, value(field->initial.empty() && !initial_empty
? field->choices->choiceName(0) // first choice
: field->initial, true)
{}
+19
View File
@@ -51,3 +51,22 @@ IMPLEMENT_REFLECTION(MultipleChoiceStyle) {
IMPLEMENT_REFLECTION_NAMELESS(MultipleChoiceValue) {
REFLECT_BASE(ChoiceValue);
}
void MultipleChoiceValue::get(vector<String>& out) const {
// split the value
out.clear();
bool is_new = true;
FOR_EACH_CONST(c, value()) {
if (c == _(',')) {
is_new = true;
} else if (is_new) {
if (c != _(' ')) { // ignore whitespace after ,
is_new = false;
out.push_back(String(1, c));
}
} else {
assert(!out.empty());
out.back() += c;
}
}
}
+2 -2
View File
@@ -57,13 +57,13 @@ class MultipleChoiceStyle : public ChoiceStyle {
*/
class MultipleChoiceValue : public ChoiceValue {
public:
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field) {}
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, true) {}
DECLARE_HAS_FIELD(MultipleChoice);
// no extra data
/// Splits the value, stores the selected choices in the out parameter
void get(vector<String>& out);
void get(vector<String>& out) const;
private:
DECLARE_REFLECTION();