made dependency analysis work without errors for magic-new (except for a few script functions); implemented the rest of the ScriptManager

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@71 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-11-01 16:41:50 +00:00
parent 2dd93a91fb
commit f18bdafab1
17 changed files with 280 additions and 45 deletions
+8
View File
@@ -99,6 +99,14 @@ template <> StyleP read_new<Style>(Reader&) {
throw InternalError(_("IndexMap contains nullptr StyleP the application should have crashed already"));
}
bool Style::update(Context& ctx) {
return left .update(ctx)
| top .update(ctx)
| width .update(ctx)
| height .update(ctx)
| visible.update(ctx);
}
void Style::initDependencies(Context& ctx, const Dependency& dep) const {
left .initDependencies(ctx,dep);
top .initDependencies(ctx,dep);
+8 -2
View File
@@ -12,6 +12,7 @@
#include <util/prec.hpp>
#include <util/reflect.hpp>
#include <util/alignment.hpp>
#include <util/age.hpp>
#include <script/scriptable.hpp>
#include <script/dependency.hpp>
@@ -96,6 +97,8 @@ class Style {
/** thisP is a smart pointer to this */
virtual ValueEditorP makeEditor(DataEditor& parent, const StyleP& thisP) = 0;
/// Update scripted values of this style, return true if anything has changed
virtual bool update(Context&);
/// Add the given dependency to the dependet_scripts list for the variables this style depends on
virtual void initDependencies(Context&, const Dependency&) const;
@@ -116,10 +119,13 @@ class Value {
inline Value(const FieldP& field) : fieldP(field) {}
virtual ~Value();
const FieldP fieldP; ///< Field this value is for, should have the right type!
const FieldP fieldP; ///< Field this value is for, should have the right type!
Age last_script_update; ///< When where the scripts last updated? (by calling update)
/// Convert this value to a string for use in tables
virtual String toString() const = 0;
/// Apply scripts to this value, return true if the value has changed
virtual bool update(Context&) { last_script_update.update(); return false; }
private:
DECLARE_REFLECTION_VIRTUAL();
+31
View File
@@ -9,6 +9,8 @@
#include <data/field/choice.hpp>
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
typedef map<String,ScriptableImage> map_String_ScriptableImage;
DECLARE_TYPEOF(map_String_ScriptableImage);
// ----------------------------------------------------------------------------- : ChoiceField
@@ -23,6 +25,12 @@ String ChoiceField::typeName() const {
return _("choice");
}
void ChoiceField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(ChoiceField) {
REFLECT_BASE(Field);
REFLECT_N("choices", choices->choices);
@@ -156,6 +164,24 @@ ChoiceStyle::ChoiceStyle(const ChoiceFieldP& field)
, colors_card_list(false)
{}
// TODO
/*
void ChoiceStyle::invalidate() {
// rebuild choice images
}
}
*/
bool ChoiceStyle::update(Context& ctx) {
// Don't update the choice images, leave that to invalidate()
return Style::update(ctx);
}
void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style::initDependencies(ctx, dep);
FOR_EACH_CONST(ci, choice_images) {
ci.second.initDependencies(ctx, dep);
}
}
IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
VALUE_N("dropdown", POPUP_DROPDOWN);
VALUE_N("menu", POPUP_MENU);
@@ -190,6 +216,11 @@ IMPLEMENT_REFLECTION(ChoiceStyle) {
String ChoiceValue::toString() const {
return value();
}
bool ChoiceValue::update(Context& ctx) {
Value::update(ctx);
return field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
}
IMPLEMENT_REFLECTION_NAMELESS(ChoiceValue) {
REFLECT_NAMELESS(value);
+7 -1
View File
@@ -36,7 +36,9 @@ class ChoiceField : public Field {
OptionalScript default_script; ///< Script that generates the default value
String initial; ///< Initial choice of a new value, or ""
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
@@ -123,6 +125,9 @@ class ChoiceStyle : public Style {
ImageCombine combine; ///< Combining mode for drawing the images
Alignment alignment; ///< Alignment of images
virtual bool update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
@@ -138,6 +143,7 @@ class ChoiceValue : public Value {
Defaultable<String> value; /// The name of the selected choice
virtual String toString() const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
+5
View File
@@ -46,6 +46,11 @@ Context& Set::getContext(const Card& card) {
return script_manager->getContext(card.stylesheet ? card.stylesheet : stylesheet);
}
StyleSheetP Set::stylesheetFor(const CardP& card) {
if (card && card->stylesheet) return card->stylesheet;
else return stylesheet;
}
String Set::typeName() const { return _("set"); }
// fix values for versions < 0.2.7
+3 -1
View File
@@ -54,11 +54,13 @@ class Set : public Packaged {
/// A context for performing scripts
/** Should only be used from the main thread! */
Context& getContext();
/// A context for performing scripts on a particular card
/** Should only be used from the main thread! */
Context& getContext(const Card& card);
/// Stylesheet to use for a particular card
StyleSheetP stylesheetFor(const CardP& card);
protected:
virtual String typeName() const;
virtual void validate(Version);