mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-13 05:57:00 -04:00
Card list colors are determined by a script instead of card_list_colors of a choice field (although that is still the default)
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@454 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+22
-1
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <data/game.hpp>
|
#include <data/game.hpp>
|
||||||
#include <data/field.hpp>
|
#include <data/field.hpp>
|
||||||
|
#include <data/field/choice.hpp>
|
||||||
#include <data/keyword.hpp>
|
#include <data/keyword.hpp>
|
||||||
#include <data/statistics.hpp>
|
#include <data/statistics.hpp>
|
||||||
#include <data/pack.hpp>
|
#include <data/pack.hpp>
|
||||||
@@ -46,6 +47,7 @@ IMPLEMENT_REFLECTION(Game) {
|
|||||||
}
|
}
|
||||||
REFLECT_NO_SCRIPT(default_set_style);
|
REFLECT_NO_SCRIPT(default_set_style);
|
||||||
REFLECT_NO_SCRIPT(card_fields);
|
REFLECT_NO_SCRIPT(card_fields);
|
||||||
|
REFLECT_NO_SCRIPT(card_list_color_script);
|
||||||
REFLECT_NO_SCRIPT(statistics_dimensions);
|
REFLECT_NO_SCRIPT(statistics_dimensions);
|
||||||
REFLECT_NO_SCRIPT(statistics_categories);
|
REFLECT_NO_SCRIPT(statistics_categories);
|
||||||
REFLECT_NO_SCRIPT(pack_types);
|
REFLECT_NO_SCRIPT(pack_types);
|
||||||
@@ -79,7 +81,26 @@ void Game::validate(Version v) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addStatsDimensionsForFields();
|
void Game::initCardListColorScript() {
|
||||||
|
if (card_list_color_script) return; // already done
|
||||||
|
// find a field with choice_colors_cardlist
|
||||||
|
FOR_EACH(s, card_fields) {
|
||||||
|
ChoiceFieldP cf = dynamic_pointer_cast<ChoiceField>(s);
|
||||||
|
if (cf && !cf->choice_colors_cardlist.empty()) {
|
||||||
|
// found the field to use
|
||||||
|
// initialize script: field.colors[card.field-name] or else rgb(0,0,0)
|
||||||
|
Script& s = card_list_color_script.getScript();
|
||||||
|
s.addInstruction(I_PUSH_CONST, to_script(&cf->choice_colors_cardlist));
|
||||||
|
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
|
||||||
|
s.addInstruction(I_MEMBER_C, cf->name);
|
||||||
|
s.addInstruction(I_BINARY, I_MEMBER);
|
||||||
|
s.addInstruction(I_PUSH_CONST, to_script(Color(0,0,0)));
|
||||||
|
s.addInstruction(I_BINARY, I_OR_ELSE);
|
||||||
|
s.addInstruction(I_RET);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// special behaviour of reading/writing GamePs: only read/write the name
|
// special behaviour of reading/writing GamePs: only read/write the name
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class Game : public Packaged {
|
|||||||
vector<FieldP> set_fields; ///< Fields for set information
|
vector<FieldP> set_fields; ///< Fields for set information
|
||||||
IndexMap<FieldP,StyleP> default_set_style; ///< Default style for the set fields, because it is often the same
|
IndexMap<FieldP,StyleP> default_set_style; ///< Default style for the set fields, because it is often the same
|
||||||
vector<FieldP> card_fields; ///< Fields on each card
|
vector<FieldP> card_fields; ///< Fields on each card
|
||||||
|
OptionalScript card_list_color_script; ///< Script that determines the color of items in the card list
|
||||||
vector<StatsDimensionP> statistics_dimensions; ///< (Additional) statistics dimensions
|
vector<StatsDimensionP> statistics_dimensions; ///< (Additional) statistics dimensions
|
||||||
vector<StatsCategoryP> statistics_categories; ///< (Additional) statistics categories
|
vector<StatsCategoryP> statistics_categories; ///< (Additional) statistics categories
|
||||||
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
||||||
@@ -59,6 +60,9 @@ class Game : public Packaged {
|
|||||||
/// Is this Magic the Gathering?
|
/// Is this Magic the Gathering?
|
||||||
bool isMagic() const;
|
bool isMagic() const;
|
||||||
|
|
||||||
|
/// Initialize card_list_color_script
|
||||||
|
void initCardListColorScript();
|
||||||
|
|
||||||
static String typeNameStatic();
|
static String typeNameStatic();
|
||||||
virtual String typeName() const;
|
virtual String typeName() const;
|
||||||
|
|
||||||
|
|||||||
+10
-8
@@ -14,6 +14,8 @@ DECLARE_TYPEOF_COLLECTION(String);
|
|||||||
DECLARE_TYPEOF_COLLECTION(StatsDimensionP);
|
DECLARE_TYPEOF_COLLECTION(StatsDimensionP);
|
||||||
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
|
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
|
||||||
|
|
||||||
|
extern ScriptValueP script_primary_choice;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Statistics dimension
|
// ----------------------------------------------------------------------------- : Statistics dimension
|
||||||
|
|
||||||
StatsDimension::StatsDimension()
|
StatsDimension::StatsDimension()
|
||||||
@@ -44,19 +46,19 @@ StatsDimension::StatsDimension(const Field& field)
|
|||||||
FOR_EACH_CONST(g, choice_field->choices->choices) {
|
FOR_EACH_CONST(g, choice_field->choices->choices) {
|
||||||
groups.push_back(g->name);
|
groups.push_back(g->name);
|
||||||
}
|
}
|
||||||
// initialize script, primary_choice(card.{field_name})
|
// initialize script: primary_choice(card.{field_name})
|
||||||
Script& s = script.getScript();
|
Script& s = script.getScript();
|
||||||
s.addInstruction(I_GET_VAR, string_to_variable(_("primary choice")));
|
s.addInstruction(I_PUSH_CONST, script_primary_choice);
|
||||||
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
|
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
|
||||||
s.addInstruction(I_MEMBER_C, field.name);
|
s.addInstruction(I_MEMBER_C, field.name);
|
||||||
s.addInstruction(I_CALL, 1);
|
s.addInstruction(I_CALL, 1);
|
||||||
s.addInstruction(I_NOP, string_to_variable(_("input")));
|
s.addInstruction(I_NOP, string_to_variable(_("input")));
|
||||||
s.addInstruction(I_RET);
|
s.addInstruction(I_RET);
|
||||||
} else {
|
} else {
|
||||||
// initialize script, card.{field_name}
|
// initialize script, card.{field_name}
|
||||||
Script& s = script.getScript();
|
Script& s = script.getScript();
|
||||||
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
|
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
|
||||||
s.addInstruction(I_MEMBER_C, field.name);
|
s.addInstruction(I_MEMBER_C, field.name);
|
||||||
s.addInstruction(I_RET);
|
s.addInstruction(I_RET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,6 +185,8 @@ void CardListBase::rebuild() {
|
|||||||
selected_item_pos = -1;
|
selected_item_pos = -1;
|
||||||
onRebuild();
|
onRebuild();
|
||||||
if (!set) return;
|
if (!set) return;
|
||||||
|
// init stuff
|
||||||
|
set->game->initCardListColorScript();
|
||||||
// determine column order
|
// determine column order
|
||||||
map<int,FieldP> new_column_fields;
|
map<int,FieldP> new_column_fields;
|
||||||
FOR_EACH(f, set->game->card_fields) {
|
FOR_EACH(f, set->game->card_fields) {
|
||||||
@@ -205,8 +207,6 @@ void CardListBase::rebuild() {
|
|||||||
align, cs.width);
|
align, cs.width);
|
||||||
column_fields.push_back(f.second);
|
column_fields.push_back(f.second);
|
||||||
}
|
}
|
||||||
// find field that determines color
|
|
||||||
color_field = findColorField();
|
|
||||||
// determine sort settings
|
// determine sort settings
|
||||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
sort_ascending = gs.sort_cards_ascending;
|
sort_ascending = gs.sort_cards_ascending;
|
||||||
@@ -224,16 +224,6 @@ void CardListBase::rebuild() {
|
|||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChoiceFieldP CardListBase::findColorField() {
|
|
||||||
FOR_EACH(s, set->game->card_fields) {
|
|
||||||
ChoiceFieldP cf = dynamic_pointer_cast<ChoiceField>(s);
|
|
||||||
if (cf && !cf->choice_colors_cardlist.empty()) {
|
|
||||||
return cf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ChoiceFieldP();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : CardListBase : Columns
|
// ----------------------------------------------------------------------------- : CardListBase : Columns
|
||||||
|
|
||||||
void CardListBase::storeColumns() {
|
void CardListBase::storeColumns() {
|
||||||
@@ -279,10 +269,9 @@ int CardListBase::OnGetItemImage(long pos) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxListItemAttr* CardListBase::OnGetItemAttr(long pos) const {
|
wxListItemAttr* CardListBase::OnGetItemAttr(long pos) const {
|
||||||
if (!color_field) return nullptr;
|
if (!set->game->card_list_color_script) return nullptr;
|
||||||
ChoiceValueP val = static_pointer_cast<ChoiceValue>( getCard(pos)->data[color_field]);
|
Context& ctx = set->getContext(getCard(pos));
|
||||||
assert(val);
|
item_attr.SetTextColour(*set->game->card_list_color_script.invoke(ctx));
|
||||||
item_attr.SetTextColour(color_field->choice_colors_cardlist[val->value()]); // if it doesn't exist we get black
|
|
||||||
return &item_attr;
|
return &item_attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,14 +104,10 @@ class CardListBase : public ItemList, public SetView {
|
|||||||
// --------------------------------------------------- : Data
|
// --------------------------------------------------- : Data
|
||||||
private:
|
private:
|
||||||
// display stuff
|
// display stuff
|
||||||
ChoiceFieldP color_field; ///< Field to use for text color (optional)
|
vector<FieldP> column_fields; ///< The field to use for each column (by column index)
|
||||||
vector<FieldP> column_fields; ///< The field to use for each column (by column index)
|
|
||||||
|
|
||||||
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
||||||
|
|
||||||
/// Find the field that determines the color, if any.
|
|
||||||
ChoiceFieldP findColorField();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Open a dialog for selecting columns to be shown
|
/// Open a dialog for selecting columns to be shown
|
||||||
void selectColumns();
|
void selectColumns();
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ class ScriptDelayedError : public ScriptValue {
|
|||||||
ScriptError error; // the error message
|
ScriptError error; // the error message
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline ScriptValueP delayError(const String& m) {
|
||||||
|
return new_intrusive1<ScriptDelayedError>(ScriptError(m));
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Iterators
|
// ----------------------------------------------------------------------------- : Iterators
|
||||||
|
|
||||||
@@ -129,7 +132,7 @@ ScriptValueP get_member(const map<String,V>& m, const String& name) {
|
|||||||
if (it != m.end()) {
|
if (it != m.end()) {
|
||||||
return to_script(it->second);
|
return to_script(it->second);
|
||||||
} else {
|
} else {
|
||||||
throw ScriptError(_ERROR_2_("has no member", _TYPE_("collection"), name));
|
return delayError(_ERROR_2_("has no member", _TYPE_("collection"), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +142,7 @@ ScriptValueP get_member(const IndexMap<K,V>& m, const String& name) {
|
|||||||
if (it != m.end()) {
|
if (it != m.end()) {
|
||||||
return to_script(*it);
|
return to_script(*it);
|
||||||
} else {
|
} else {
|
||||||
throw ScriptError(_ERROR_2_("has no member", _TYPE_("collection"), name));
|
return delayError(_ERROR_2_("has no member", _TYPE_("collection"), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,6 @@
|
|||||||
// ----------------------------------------------------------------------------- : ScriptValue
|
// ----------------------------------------------------------------------------- : ScriptValue
|
||||||
// Base cases
|
// Base cases
|
||||||
|
|
||||||
inline ScriptValueP delayError(const String& m) {
|
|
||||||
return new_intrusive1<ScriptDelayedError>(ScriptError(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptValue::operator String() const { return _("[[") + typeName() + _("]]"); }
|
ScriptValue::operator String() const { return _("[[") + typeName() + _("]]"); }
|
||||||
ScriptValue::operator int() const { throw ScriptError(_ERROR_2_("can't convert", typeName(), _TYPE_("integer" ))); }
|
ScriptValue::operator int() const { throw ScriptError(_ERROR_2_("can't convert", typeName(), _TYPE_("integer" ))); }
|
||||||
ScriptValue::operator double() const { throw ScriptError(_ERROR_2_("can't convert", typeName(), _TYPE_("real" ))); }
|
ScriptValue::operator double() const { throw ScriptError(_ERROR_2_("can't convert", typeName(), _TYPE_("real" ))); }
|
||||||
|
|||||||
Reference in New Issue
Block a user