mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Scripts depending on content_something are re-updating after updating the content properties
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@480 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+2
-2
@@ -53,8 +53,8 @@ Context& Set::getContext(const CardP& card) {
|
||||
assert(wxThread::IsMain());
|
||||
return script_manager->getContext(card);
|
||||
}
|
||||
void Set::updateStyles(const CardP& card) {
|
||||
script_manager->updateStyles(card);
|
||||
void Set::updateStyles(const CardP& card, bool only_content_dependent) {
|
||||
script_manager->updateStyles(card, only_content_dependent);
|
||||
}
|
||||
void Set::updateDelayed() {
|
||||
script_manager->updateDelayed();
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ class Set : public Packaged {
|
||||
/** Should only be used from the main thread! */
|
||||
Context& getContext(const CardP& card);
|
||||
/// Update styles and extra_card_fields for a card
|
||||
void updateStyles(const CardP& card);
|
||||
void updateStyles(const CardP& card, bool only_content_dependent);
|
||||
/// Update scripts that were delayed
|
||||
void updateDelayed();
|
||||
/// A context for performing scripts
|
||||
|
||||
+27
-15
@@ -40,30 +40,23 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
||||
// fill with background color
|
||||
clearDC(dc.getDC(), background);
|
||||
// update style scripts
|
||||
try {
|
||||
if (card) {
|
||||
set->updateStyles(card);
|
||||
} else {
|
||||
Context& ctx = getContext();
|
||||
FOR_EACH(v, viewers) {
|
||||
if (v->getStyle()->update(ctx)) {
|
||||
v->getStyle()->tellListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const Error& e) {
|
||||
handle_error(e, false, false);
|
||||
}
|
||||
updateStyles(false);
|
||||
// prepare viewers
|
||||
bool changed_content_properties = false;
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
if (v->getStyle()->visible) {
|
||||
try {
|
||||
v->prepare(dc);
|
||||
if (v->prepare(dc)) {
|
||||
changed_content_properties = true;
|
||||
}
|
||||
} catch (const Error& e) {
|
||||
handle_error(e, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed_content_properties) {
|
||||
updateStyles(true);
|
||||
}
|
||||
// draw viewers
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
if (v->getStyle()->visible) {// visible
|
||||
@@ -80,6 +73,25 @@ void DataViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
v.draw(dc);
|
||||
}
|
||||
|
||||
void DataViewer::updateStyles(bool only_content_dependent) {
|
||||
try {
|
||||
if (card) {
|
||||
set->updateStyles(card, only_content_dependent);
|
||||
} else {
|
||||
Context& ctx = getContext();
|
||||
FOR_EACH(v, viewers) {
|
||||
Style& s = *v->getStyle();
|
||||
if (only_content_dependent && !s.content_dependent) continue;
|
||||
if (s.update(ctx)) {
|
||||
s.tellListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const Error& e) {
|
||||
handle_error(e, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Utility for ValueViewers
|
||||
|
||||
bool DataViewer::nativeLook() const { return false; }
|
||||
|
||||
@@ -75,6 +75,8 @@ class DataViewer : public SetView {
|
||||
private:
|
||||
/// Create some viewers for the given styles
|
||||
void addStyles(IndexMap<FieldP,StyleP>& styles);
|
||||
/// Update style scripts
|
||||
void updateStyles(bool only_content_dependent);
|
||||
protected:
|
||||
/// Set the styles for the data to be shown, recreating the viewers
|
||||
void setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles, IndexMap<FieldP,StyleP>* extra_styles = nullptr);
|
||||
|
||||
@@ -131,12 +131,15 @@ void TextViewer::drawSeparators(RotatedDC& dc) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
||||
bool TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
||||
if (lines.empty()) {
|
||||
// not prepared yet
|
||||
Rotater r(dc, style.getRotation());
|
||||
prepareElements(text, style, ctx);
|
||||
prepareLines(dc, text, style, ctx);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void TextViewer::reset() {
|
||||
|
||||
@@ -54,7 +54,8 @@ class TextViewer {
|
||||
void drawSeparators(RotatedDC& dc);
|
||||
|
||||
/// Prepare the text for drawing, if it is not already prepared
|
||||
void prepare(RotatedDC& dc, const String& text, TextStyle& style, Context&);
|
||||
/** Returns true if something has been done */
|
||||
bool prepare(RotatedDC& dc, const String& text, TextStyle& style, Context&);
|
||||
/// Reset the cached data, at a new call to draw it will be recalculated
|
||||
void reset();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextValueViewer
|
||||
|
||||
void TextValueViewer::prepare(RotatedDC& dc) {
|
||||
bool TextValueViewer::prepare(RotatedDC& dc) {
|
||||
if (!style().mask_filename.empty() && !style().mask.ok()) {
|
||||
// load contour mask
|
||||
Image image;
|
||||
@@ -22,6 +22,7 @@ void TextValueViewer::prepare(RotatedDC& dc) {
|
||||
}
|
||||
}
|
||||
v.prepare(dc, value().value(), style(), viewer.getContext());
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextValueViewer::draw(RotatedDC& dc) {
|
||||
|
||||
@@ -21,7 +21,7 @@ class TextValueViewer : public ValueViewer {
|
||||
public:
|
||||
DECLARE_VALUE_VIEWER(Text) : ValueViewer(parent,style) {}
|
||||
|
||||
virtual void prepare(RotatedDC& dc);
|
||||
virtual bool prepare(RotatedDC& dc);
|
||||
virtual void draw(RotatedDC& dc);
|
||||
virtual void onValueChange();
|
||||
virtual void onStyleChange();
|
||||
|
||||
@@ -40,8 +40,9 @@ class ValueViewer : public StyleListener {
|
||||
inline const ValueP& getValue() const { return valueP; }
|
||||
|
||||
/// Prepare before drawing.
|
||||
/** Scripts are updated after preparing, allowing */
|
||||
virtual void prepare(RotatedDC& dc) {};
|
||||
/** Should return true if a content property has changed
|
||||
* Scripts are re-updated after preparing if they depend on content properties. */
|
||||
virtual bool prepare(RotatedDC& dc) { return false; };
|
||||
/// Draw this value
|
||||
virtual void draw(RotatedDC& dc) = 0;
|
||||
|
||||
|
||||
@@ -139,6 +139,12 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
|
||||
s->checkContentDependencies(ctx, test);
|
||||
if (test.index) s->content_dependent = true;
|
||||
}
|
||||
FOR_EACH(s, stylesheet.extra_card_style) {
|
||||
// are there dependencies of this style on other style properties?
|
||||
Dependency test(DEP_DUMMY, false);
|
||||
s->checkContentDependencies(ctx, test);
|
||||
if (test.index) s->content_dependent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ScriptManager : updating
|
||||
@@ -199,21 +205,24 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
}
|
||||
|
||||
void SetScriptManager::updateStyles(const CardP& card) {
|
||||
void SetScriptManager::updateStyles(const CardP& card, bool only_content_dependent) {
|
||||
assert(card);
|
||||
const StyleSheet& stylesheet = set.stylesheetFor(card);
|
||||
Context& ctx = getContext(card);
|
||||
// update extra card fields
|
||||
IndexMap<FieldP,ValueP>& extra_data = card->extraDataFor(stylesheet);
|
||||
FOR_EACH(v, extra_data) {
|
||||
v->update(ctx);
|
||||
if (!only_content_dependent) {
|
||||
// update extra card fields
|
||||
IndexMap<FieldP,ValueP>& extra_data = card->extraDataFor(stylesheet);
|
||||
FOR_EACH(v, extra_data) {
|
||||
v->update(ctx);
|
||||
}
|
||||
}
|
||||
// update all styles
|
||||
updateStyles(ctx, stylesheet.card_style);
|
||||
updateStyles(ctx, stylesheet.extra_card_style);
|
||||
updateStyles(ctx, stylesheet.card_style, only_content_dependent);
|
||||
updateStyles(ctx, stylesheet.extra_card_style, only_content_dependent);
|
||||
}
|
||||
void SetScriptManager::updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles) {
|
||||
void SetScriptManager::updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles, bool only_content_dependent) {
|
||||
FOR_EACH_CONST(s, styles) {
|
||||
if (only_content_dependent && !s->content_dependent) continue;
|
||||
try {
|
||||
if (s->update(ctx)) {
|
||||
// style has changed, tell listeners
|
||||
|
||||
@@ -61,7 +61,7 @@ class SetScriptManager : public SetScriptContext, public ActionListener {
|
||||
~SetScriptManager();
|
||||
|
||||
/// Update all styles for a particular card
|
||||
void updateStyles(const CardP& card);
|
||||
void updateStyles(const CardP& card, bool only_content_dependent);
|
||||
|
||||
/// Update expensive things that were previously delayed
|
||||
void updateDelayed();
|
||||
@@ -79,7 +79,7 @@ class SetScriptManager : public SetScriptContext, public ActionListener {
|
||||
void initDependencies(Context&, StyleSheet&);
|
||||
|
||||
/// Update a map of styles
|
||||
void updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles);
|
||||
void updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles, bool only_content_dependent);
|
||||
/// 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