mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Support for extra card fields in stylesheets;
Fixed some bugs: - Missing choice images can crash mse. - The wrong style is used for making preview choice images on style panel. FOR_EACH(x, *y.z) should now work without parentheses on linux as well. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@389 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -19,6 +19,7 @@ enum DependencyType
|
||||
, DEP_CARDS_FIELD ///< dependency of a script in a "card" field for all cards
|
||||
, DEP_SET_FIELD ///< dependency of a script in a "set" field
|
||||
, DEP_STYLE ///< dependency of a script in a "style" property, data gives the stylesheet
|
||||
, DEP_EXTRA_CARD_FIELD ///< dependency of a script in an extra stylesheet specific card field
|
||||
, DEP_CARD_COPY_DEP ///< copy the dependencies from a card field
|
||||
, DEP_SET_COPY_DEP ///< copy the dependencies from a set field
|
||||
};
|
||||
|
||||
@@ -123,6 +123,10 @@ void SetScriptManager::initDependencies(Context& ctx, Game& game) {
|
||||
void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
|
||||
if (stylesheet.dependencies_initialized) return;
|
||||
stylesheet.dependencies_initialized = true;
|
||||
// find dependencies of extra card fields
|
||||
/*FOR_EACH(f, stylesheet.extra_card_fields) {
|
||||
f->initDependencies(ctx, Dependency(DEP_EXTRA_CARD_FIELD, f->index, &stylesheet));
|
||||
}*/
|
||||
// find dependencies of choice images and other style stuff
|
||||
FOR_EACH(s, stylesheet.card_style) {
|
||||
s->initDependencies(ctx, Dependency(DEP_STYLE, s->fieldP->index, &stylesheet));
|
||||
@@ -188,11 +192,20 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
|
||||
void SetScriptManager::updateStyles(const CardP& card) {
|
||||
// lastUpdatedCard = card;
|
||||
assert(card);
|
||||
const StyleSheet& stylesheet = set.stylesheetFor(card);
|
||||
Context& ctx = getContext(card);
|
||||
// update extra card fields
|
||||
card->extra_data.init(stylesheet.extra_card_fields);
|
||||
FOR_EACH(v, card->extra_data) {
|
||||
v->update(ctx);
|
||||
}
|
||||
// update all styles
|
||||
FOR_EACH_CONST(s, stylesheet.card_style) {
|
||||
updateStyles(ctx, stylesheet.card_style);
|
||||
updateStyles(ctx, stylesheet.extra_card_style);
|
||||
}
|
||||
void SetScriptManager::updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles) {
|
||||
FOR_EACH_CONST(s, styles) {
|
||||
if (s->update(ctx)) {
|
||||
// style has changed, tell listeners
|
||||
s->tellListeners();
|
||||
@@ -313,6 +326,17 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen
|
||||
ScriptStyleEvent change(stylesheet, style.get());
|
||||
set.actions.tellListeners(change, false);
|
||||
break;
|
||||
/*} case DEP_EXTRA_CARD_FIELD: {
|
||||
// Not needed, extra card fields are handled in updateStyles()
|
||||
if (card) {
|
||||
StyleSheet* stylesheet = reinterpret_cast<StyleSheet*>(d.data);
|
||||
StyleSheet* stylesheet_card = &set.stylesheetFor(card);
|
||||
if (stylesheet == stylesheet_card) {
|
||||
ValueP value = card->extra_data.at(d.index);
|
||||
to_update.push_back(ToUpdate(value.get(), card));
|
||||
}
|
||||
}
|
||||
break;*/
|
||||
} case DEP_CARD_COPY_DEP: {
|
||||
// propagate dependencies from another field
|
||||
FieldP f = set.game->card_fields[d.index];
|
||||
|
||||
@@ -21,6 +21,8 @@ class Value;
|
||||
DECLARE_POINTER_TYPE(Game);
|
||||
DECLARE_POINTER_TYPE(StyleSheet);
|
||||
DECLARE_POINTER_TYPE(Card);
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
|
||||
// ----------------------------------------------------------------------------- : SetScriptContext
|
||||
|
||||
@@ -76,6 +78,8 @@ class SetScriptManager : public SetScriptContext, public ActionListener {
|
||||
void initDependencies(Context&, Game&);
|
||||
void initDependencies(Context&, StyleSheet&);
|
||||
|
||||
/// Update a map of styles
|
||||
void updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles);
|
||||
/// Updates scripts, starting at some value
|
||||
/** if the value changes any dependend values are updated as well */
|
||||
void updateValue(Value& value, const CardP& card);
|
||||
|
||||
Reference in New Issue
Block a user