From 8dcda6fd93311ce416a9913f989cc1e056d35a26 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 25 Nov 2006 22:48:14 +0000 Subject: [PATCH] Dependency following now works git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@95 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/card.cpp | 8 ++++++++ src/data/card.hpp | 4 ++++ src/data/set.cpp | 7 +++++++ src/data/set.hpp | 4 ++++ src/gui/preferences_window.cpp | 2 +- src/gui/set/window.cpp | 4 +++- src/mse.vcproj | 6 ++++++ src/render/value/choice.cpp | 2 +- src/script/image.cpp | 19 +++++++++++++++++++ src/script/script_manager.cpp | 33 +++++++++++++++++++++++++-------- src/script/script_manager.hpp | 1 + src/script/value.cpp | 2 +- src/script/value.hpp | 8 ++++++++ src/util/index_map.hpp | 1 + src/util/io/reader.hpp | 5 +++++ src/util/window_id.hpp | 14 ++++++++++++++ 16 files changed, 108 insertions(+), 12 deletions(-) diff --git a/src/data/card.cpp b/src/data/card.cpp index d68e707c..ee0d9a82 100644 --- a/src/data/card.cpp +++ b/src/data/card.cpp @@ -31,6 +31,14 @@ String Card::identification() const { return _("TODO"); } +void mark_dependency_member(const CardP& card, const String& name, const Dependency& dep) { + // Find field with that name + IndexMap::const_iterator it = card->data.find(name); + if (it != card->data.end()) { + (*it)->fieldP->dependent_scripts.push_back(dep); + } +} + IMPLEMENT_REFLECTION(Card) { REFLECT(stylesheet); REFLECT(notes); diff --git a/src/data/card.hpp b/src/data/card.hpp index ba1cc350..c7372ea3 100644 --- a/src/data/card.hpp +++ b/src/data/card.hpp @@ -13,6 +13,8 @@ #include class Game; +class Dependency; +DECLARE_POINTER_TYPE(Card); DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(StyleSheet); @@ -43,5 +45,7 @@ class Card { DECLARE_REFLECTION(); }; +void mark_dependency_member(const CardP& value, const String& name, const Dependency& dep); + // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/data/set.cpp b/src/data/set.cpp index 178c6687..2aff7189 100644 --- a/src/data/set.cpp +++ b/src/data/set.cpp @@ -95,6 +95,13 @@ void Set::validate(Version file_app_version) { */ } } +void mark_dependency_member(Set* value, const String& name, const Dependency& dep) { + // TODO +} +void mark_dependency_member(const SetP& value, const String& name, const Dependency& dep) { + mark_dependency_member(value.get(), name, dep); +} + // in scripts, set.something is read from the set_info template void reflect_set_info_get_member(Tag& tag, const IndexMap& data) {} diff --git a/src/data/set.hpp b/src/data/set.hpp index d190d51e..a72a898f 100644 --- a/src/data/set.hpp +++ b/src/data/set.hpp @@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Keyword); class ScriptManager; class Context; +class Dependency; // ----------------------------------------------------------------------------- : Set @@ -82,6 +83,9 @@ inline int item_count(const Set& set) { return (int)set.cards.size(); } +void mark_dependency_member(const SetP& value, const String& name, const Dependency& dep); +void mark_dependency_member(Set* value, const String& name, const Dependency& dep); + // ----------------------------------------------------------------------------- : SetView /// A 'view' of a Set, is notified when the Set is updated diff --git a/src/gui/preferences_window.cpp b/src/gui/preferences_window.cpp index 5dffa3c8..86774bcd 100644 --- a/src/gui/preferences_window.cpp +++ b/src/gui/preferences_window.cpp @@ -145,7 +145,7 @@ DisplayPreferencesPage::DisplayPreferencesPage(Window* parent) s5->Add(new wxStaticText(this, wxID_ANY, _("Columns: ")), 0, wxALL & ~wxLEFT | wxEXPAND, 4); s5->Add(columns); s4->Add(s5, 0, wxEXPAND | wxALL, 4); - s->Add(s, 0, wxEXPAND | wxALL & ~wxTOP, 8); + s->Add(s4, 0, wxEXPAND | wxALL & ~wxTOP, 8); s->SetSizeHints(this); SetSizer(s); } diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 5642a0a2..c02fc306 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -487,7 +488,8 @@ void SetWindow::onReplaceAll(wxFindDialogEvent&) { } void SetWindow::onEditPreferences(wxCommandEvent&) { -// SettingsWindow wnd(this); + PreferencesWindow wnd(this); + wnd.ShowModal(); // if (wnd.ShowModal() == wxID_OK) { // // render settings may have changed, notify all windows // FOR_EACH(m, setWindows) { diff --git a/src/mse.vcproj b/src/mse.vcproj index 3e7dc3d4..ffbb390c 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -580,6 +580,12 @@ + + + + diff --git a/src/render/value/choice.cpp b/src/render/value/choice.cpp index 0523fc80..a742475c 100644 --- a/src/render/value/choice.cpp +++ b/src/render/value/choice.cpp @@ -18,7 +18,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) { double margin = 0; if (style().render_style & RENDER_IMAGE) { // draw image - map::iterator it = style().choice_images.find(value().value()); + map::iterator it = style().choice_images.find(cannocial_name_form(value().value())); if (it != style().choice_images.end()) { ScriptableImage& img = it->second; ScriptImageP i; diff --git a/src/script/image.cpp b/src/script/image.cpp index abc37ac8..803af797 100644 --- a/src/script/image.cpp +++ b/src/script/image.cpp @@ -208,6 +208,24 @@ SCRIPT_FUNCTION(set_mask) { } } +bool parse_enum(const String&, ImageCombine& out); + +SCRIPT_FUNCTION(set_combine) { + if (last_update_age() == 0) { + SCRIPT_PARAM(String, combine); + ScriptImageP image = to_script_image(ctx.getVariable(_("input"))); + // parse and set combine + if (!parse_enum(combine, image->combine)) { + throw ScriptError(_("Not a valid combine mode: '") + combine + _("'")); + } + return image; + } else { + SCRIPT_RETURN( + script_image_up_to_date(ctx.getVariable(_("input"))) + ); + } +} + SCRIPT_FUNCTION(buildin_image) { if (last_update_age() == 0) { SCRIPT_PARAM(String, input); @@ -223,5 +241,6 @@ void init_script_image_functions(Context& ctx) { ctx.setVariable(_("linear blend"), script_linear_blend); ctx.setVariable(_("masked blend"), script_masked_blend); ctx.setVariable(_("set mask"), script_set_mask); + ctx.setVariable(_("set combine"), script_set_combine); ctx.setVariable(_("buildin image"), script_buildin_image); } diff --git a/src/script/script_manager.cpp b/src/script/script_manager.cpp index 4476ac08..8a23abc0 100644 --- a/src/script/script_manager.cpp +++ b/src/script/script_manager.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include typedef map Contexts; @@ -32,7 +34,10 @@ void init_script_image_functions(Context& ctx); ScriptManager::ScriptManager(Set& set) : set(set) -{} +{ + // add as an action listener for the set, so we receive actions + set.actions.addListener(this); +} ScriptManager::~ScriptManager() { set.actions.removeListener(this); @@ -40,8 +45,6 @@ ScriptManager::~ScriptManager() { FOR_EACH(sc, contexts) { delete sc.second; } - // add as an action listener for the set, so we receive actions - set.actions.addListener(this); } Context& ScriptManager::getContext(const StyleSheetP& stylesheet) { @@ -116,11 +119,19 @@ void ScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) { // ----------------------------------------------------------------------------- : ScriptManager : updating void ScriptManager::onAction(const Action& action, bool undone) { - // TODO -// TYPE_CASE(action, ValueAction) { -// } -// TYPE_CASE(action, CardListAction) { -// } + TYPE_CASE(action, ValueAction) { + // find the affected card + FOR_EACH(card, set.cards) { + if (card->data.contains(action.valueP)) { + updateValue(*action.valueP, card); + return; + } + } + updateValue(*action.valueP, CardP()); + } + TYPE_CASE_(action, CardListAction) { + updateAllDependend(set.game->dependent_scripts_cards); + } } void ScriptManager::updateStyles(const CardP& card) { @@ -196,8 +207,14 @@ void ScriptManager::alsoUpdate(deque& to_update, const vectordata.at(d.index); + to_update.push_back(ToUpdate(value.get(), card)); + } break; } case DEP_CARDS_FIELD: { break; diff --git a/src/script/script_manager.hpp b/src/script/script_manager.hpp index 3a0df2fc..ff0ed3c0 100644 --- a/src/script/script_manager.hpp +++ b/src/script/script_manager.hpp @@ -64,6 +64,7 @@ class ScriptManager : public ActionListener { // Something that needs to be updated struct ToUpdate { + ToUpdate(Value* value, CardP card) : value(value), card(card) {} Value* value; ///< value to update CardP card; ///< card the value is in, or CadP() if it is not a card field }; diff --git a/src/script/value.cpp b/src/script/value.cpp index 5a747bf5..19e3507e 100644 --- a/src/script/value.cpp +++ b/src/script/value.cpp @@ -164,7 +164,7 @@ class ScriptString : public ScriptValue { return l; } else if (value == _("yes") || value == _("true")) { return true; - } else if (value == _("no") || value == _("false")) { + } else if (value == _("no") || value == _("false") || value.empty()) { return false; } else { throw ScriptError(_("Not a number: '") + value + _("'")); diff --git a/src/script/value.hpp b/src/script/value.hpp index 9d2a945f..a2255ee1 100644 --- a/src/script/value.hpp +++ b/src/script/value.hpp @@ -220,6 +220,10 @@ int item_count(const T& v) { return -1; } +/// Mark a dependency on a member of value, can be overloaded +template +void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {} + /// Script value containing an object (pointer) template class ScriptObject : public ScriptValue { @@ -245,6 +249,10 @@ class ScriptObject : public ScriptValue { } } } + virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const { + mark_dependency_member(value, name, dep); + return getMember(name); + } virtual int itemCount() const { int i = item_count(*value); return i >= 0 ? i : ScriptValue::itemCount(); diff --git a/src/util/index_map.hpp b/src/util/index_map.hpp index 675f2605..fd1c016d 100644 --- a/src/util/index_map.hpp +++ b/src/util/index_map.hpp @@ -39,6 +39,7 @@ class IndexMap : private vector { using vector::const_reference; using vector::begin; using vector::end; + using vector::at; // for using numeric indices directly /// Initialize this map with default values given a list of keys /** has no effect if already initialized with the given keys */ diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index f9859cd0..2bde403a 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -227,6 +227,11 @@ void Reader::handle(IndexMap& m) { /* warning: unknown value */ \ warning(_("Unrecognized value: ") + value); \ } \ + } \ + bool parse_enum(const String& value, Enum& out) { \ + EnumReader reader(value); \ + reflect_ ## Enum(out, reader); \ + return reader.isDone(); \ } /// 'Tag' to be used when reflecting enumerations for Reader diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index ba12f0fd..09087f4d 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -178,6 +178,20 @@ enum ControlID { , ID_NOTEBOOK , ID_APPRENTICE_BROWSE , ID_CHECK_UPDATES_NOW + // Image slicer +, ID_PREVIEW +, ID_SELECTOR +, ID_SIZE +, ID_LEFT +, ID_TOP +, ID_WIDTH +, ID_HEIGHT +, ID_FIX_ASPECT +, ID_ZOOM +, ID_ZOOM_X +, ID_ZOOM_Y +, ID_SHARPEN +, ID_SHARPEN_AMOUNT }; // ----------------------------------------------------------------------------- : EOF