Commit 263c2ca9 authored by twanvl's avatar twanvl

Dependency following now works

parent b51d7fae
...@@ -31,6 +31,14 @@ String Card::identification() const { ...@@ -31,6 +31,14 @@ String Card::identification() const {
return _("TODO"); return _("TODO");
} }
void mark_dependency_member(const CardP& card, const String& name, const Dependency& dep) {
// Find field with that name
IndexMap<FieldP,ValueP>::const_iterator it = card->data.find(name);
if (it != card->data.end()) {
(*it)->fieldP->dependent_scripts.push_back(dep);
}
}
IMPLEMENT_REFLECTION(Card) { IMPLEMENT_REFLECTION(Card) {
REFLECT(stylesheet); REFLECT(stylesheet);
REFLECT(notes); REFLECT(notes);
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <util/reflect.hpp> #include <util/reflect.hpp>
class Game; class Game;
class Dependency;
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(StyleSheet); DECLARE_POINTER_TYPE(StyleSheet);
...@@ -43,5 +45,7 @@ class Card { ...@@ -43,5 +45,7 @@ class Card {
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
void mark_dependency_member(const CardP& value, const String& name, const Dependency& dep);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -95,6 +95,13 @@ void Set::validate(Version file_app_version) { ...@@ -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 // in scripts, set.something is read from the set_info
template <typename Tag> template <typename Tag>
void reflect_set_info_get_member(Tag& tag, const IndexMap<FieldP, ValueP>& data) {} void reflect_set_info_get_member(Tag& tag, const IndexMap<FieldP, ValueP>& data) {}
......
...@@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(Value); ...@@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(Keyword); DECLARE_POINTER_TYPE(Keyword);
class ScriptManager; class ScriptManager;
class Context; class Context;
class Dependency;
// ----------------------------------------------------------------------------- : Set // ----------------------------------------------------------------------------- : Set
...@@ -82,6 +83,9 @@ inline int item_count(const Set& set) { ...@@ -82,6 +83,9 @@ inline int item_count(const Set& set) {
return (int)set.cards.size(); 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 // ----------------------------------------------------------------------------- : SetView
/// A 'view' of a Set, is notified when the Set is updated /// A 'view' of a Set, is notified when the Set is updated
......
...@@ -145,7 +145,7 @@ DisplayPreferencesPage::DisplayPreferencesPage(Window* parent) ...@@ -145,7 +145,7 @@ DisplayPreferencesPage::DisplayPreferencesPage(Window* parent)
s5->Add(new wxStaticText(this, wxID_ANY, _("Columns: ")), 0, wxALL & ~wxLEFT | wxEXPAND, 4); s5->Add(new wxStaticText(this, wxID_ANY, _("Columns: ")), 0, wxALL & ~wxLEFT | wxEXPAND, 4);
s5->Add(columns); s5->Add(columns);
s4->Add(s5, 0, wxEXPAND | wxALL, 4); 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); s->SetSizeHints(this);
SetSizer(s); SetSizer(s);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <gui/about_window.hpp> #include <gui/about_window.hpp>
#include <gui/update_checker.hpp> #include <gui/update_checker.hpp>
#include <gui/new_window.hpp> #include <gui/new_window.hpp>
#include <gui/preferences_window.hpp>
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <data/game.hpp> #include <data/game.hpp>
...@@ -487,7 +488,8 @@ void SetWindow::onReplaceAll(wxFindDialogEvent&) { ...@@ -487,7 +488,8 @@ void SetWindow::onReplaceAll(wxFindDialogEvent&) {
} }
void SetWindow::onEditPreferences(wxCommandEvent&) { void SetWindow::onEditPreferences(wxCommandEvent&) {
// SettingsWindow wnd(this); PreferencesWindow wnd(this);
wnd.ShowModal();
// if (wnd.ShowModal() == wxID_OK) { // if (wnd.ShowModal() == wxID_OK) {
// // render settings may have changed, notify all windows // // render settings may have changed, notify all windows
// FOR_EACH(m, setWindows) { // FOR_EACH(m, setWindows) {
......
...@@ -580,6 +580,12 @@ ...@@ -580,6 +580,12 @@
<File <File
RelativePath=".\gui\drop_down_list.hpp"> RelativePath=".\gui\drop_down_list.hpp">
</File> </File>
<File
RelativePath=".\gui\image_slice_window.cpp">
</File>
<File
RelativePath=".\gui\image_slice_window.hpp">
</File>
<File <File
RelativePath=".\gui\new_window.cpp"> RelativePath=".\gui\new_window.cpp">
</File> </File>
......
...@@ -18,7 +18,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) { ...@@ -18,7 +18,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
double margin = 0; double margin = 0;
if (style().render_style & RENDER_IMAGE) { if (style().render_style & RENDER_IMAGE) {
// draw image // draw image
map<String,ScriptableImage>::iterator it = style().choice_images.find(value().value()); map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(value().value()));
if (it != style().choice_images.end()) { if (it != style().choice_images.end()) {
ScriptableImage& img = it->second; ScriptableImage& img = it->second;
ScriptImageP i; ScriptImageP i;
......
...@@ -208,6 +208,24 @@ SCRIPT_FUNCTION(set_mask) { ...@@ -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) { SCRIPT_FUNCTION(buildin_image) {
if (last_update_age() == 0) { if (last_update_age() == 0) {
SCRIPT_PARAM(String, input); SCRIPT_PARAM(String, input);
...@@ -223,5 +241,6 @@ void init_script_image_functions(Context& ctx) { ...@@ -223,5 +241,6 @@ void init_script_image_functions(Context& ctx) {
ctx.setVariable(_("linear blend"), script_linear_blend); ctx.setVariable(_("linear blend"), script_linear_blend);
ctx.setVariable(_("masked blend"), script_masked_blend); ctx.setVariable(_("masked blend"), script_masked_blend);
ctx.setVariable(_("set mask"), script_set_mask); ctx.setVariable(_("set mask"), script_set_mask);
ctx.setVariable(_("set combine"), script_set_combine);
ctx.setVariable(_("buildin image"), script_buildin_image); ctx.setVariable(_("buildin image"), script_buildin_image);
} }
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <data/game.hpp> #include <data/game.hpp>
#include <data/card.hpp> #include <data/card.hpp>
#include <data/field.hpp> #include <data/field.hpp>
#include <data/action/set.hpp>
#include <data/action/value.hpp>
#include <util/error.hpp> #include <util/error.hpp>
typedef map<const StyleSheet*,Context*> Contexts; typedef map<const StyleSheet*,Context*> Contexts;
...@@ -32,7 +34,10 @@ void init_script_image_functions(Context& ctx); ...@@ -32,7 +34,10 @@ void init_script_image_functions(Context& ctx);
ScriptManager::ScriptManager(Set& set) ScriptManager::ScriptManager(Set& set)
: set(set) : set(set)
{} {
// add as an action listener for the set, so we receive actions
set.actions.addListener(this);
}
ScriptManager::~ScriptManager() { ScriptManager::~ScriptManager() {
set.actions.removeListener(this); set.actions.removeListener(this);
...@@ -40,8 +45,6 @@ ScriptManager::~ScriptManager() { ...@@ -40,8 +45,6 @@ ScriptManager::~ScriptManager() {
FOR_EACH(sc, contexts) { FOR_EACH(sc, contexts) {
delete sc.second; 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) { Context& ScriptManager::getContext(const StyleSheetP& stylesheet) {
...@@ -116,11 +119,19 @@ void ScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) { ...@@ -116,11 +119,19 @@ void ScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
// ----------------------------------------------------------------------------- : ScriptManager : updating // ----------------------------------------------------------------------------- : ScriptManager : updating
void ScriptManager::onAction(const Action& action, bool undone) { void ScriptManager::onAction(const Action& action, bool undone) {
// TODO TYPE_CASE(action, ValueAction) {
// TYPE_CASE(action, ValueAction) { // find the affected card
// } FOR_EACH(card, set.cards) {
// TYPE_CASE(action, CardListAction) { 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) { void ScriptManager::updateStyles(const CardP& card) {
...@@ -196,8 +207,14 @@ void ScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependen ...@@ -196,8 +207,14 @@ void ScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependen
FOR_EACH_CONST(d, deps) { FOR_EACH_CONST(d, deps) {
switch (d.type) { switch (d.type) {
case DEP_SET_FIELD: { case DEP_SET_FIELD: {
ValueP value = set.data.at(d.index);
to_update.push_back(ToUpdate(value.get(), CardP()));
break; break;
} case DEP_CARD_FIELD: { } case DEP_CARD_FIELD: {
if (card) {
ValueP value = card->data.at(d.index);
to_update.push_back(ToUpdate(value.get(), card));
}
break; break;
} case DEP_CARDS_FIELD: { } case DEP_CARDS_FIELD: {
break; break;
......
...@@ -64,6 +64,7 @@ class ScriptManager : public ActionListener { ...@@ -64,6 +64,7 @@ class ScriptManager : public ActionListener {
// Something that needs to be updated // Something that needs to be updated
struct ToUpdate { struct ToUpdate {
ToUpdate(Value* value, CardP card) : value(value), card(card) {}
Value* value; ///< value to update Value* value; ///< value to update
CardP card; ///< card the value is in, or CadP() if it is not a card field CardP card; ///< card the value is in, or CadP() if it is not a card field
}; };
......
...@@ -164,7 +164,7 @@ class ScriptString : public ScriptValue { ...@@ -164,7 +164,7 @@ class ScriptString : public ScriptValue {
return l; return l;
} else if (value == _("yes") || value == _("true")) { } else if (value == _("yes") || value == _("true")) {
return true; return true;
} else if (value == _("no") || value == _("false")) { } else if (value == _("no") || value == _("false") || value.empty()) {
return false; return false;
} else { } else {
throw ScriptError(_("Not a number: '") + value + _("'")); throw ScriptError(_("Not a number: '") + value + _("'"));
......
...@@ -220,6 +220,10 @@ int item_count(const T& v) { ...@@ -220,6 +220,10 @@ int item_count(const T& v) {
return -1; return -1;
} }
/// Mark a dependency on a member of value, can be overloaded
template <typename T>
void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {}
/// Script value containing an object (pointer) /// Script value containing an object (pointer)
template <typename T> template <typename T>
class ScriptObject : public ScriptValue { class ScriptObject : public ScriptValue {
...@@ -245,6 +249,10 @@ 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 { virtual int itemCount() const {
int i = item_count(*value); int i = item_count(*value);
return i >= 0 ? i : ScriptValue::itemCount(); return i >= 0 ? i : ScriptValue::itemCount();
......
...@@ -39,6 +39,7 @@ class IndexMap : private vector<Value> { ...@@ -39,6 +39,7 @@ class IndexMap : private vector<Value> {
using vector<Value>::const_reference; using vector<Value>::const_reference;
using vector<Value>::begin; using vector<Value>::begin;
using vector<Value>::end; using vector<Value>::end;
using vector<Value>::at; // for using numeric indices directly
/// Initialize this map with default values given a list of keys /// Initialize this map with default values given a list of keys
/** has no effect if already initialized with the given keys */ /** has no effect if already initialized with the given keys */
......
...@@ -227,6 +227,11 @@ void Reader::handle(IndexMap<K,V>& m) { ...@@ -227,6 +227,11 @@ void Reader::handle(IndexMap<K,V>& m) {
/* warning: unknown value */ \ /* warning: unknown value */ \
warning(_("Unrecognized value: ") + 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 /// 'Tag' to be used when reflecting enumerations for Reader
......
...@@ -178,6 +178,20 @@ enum ControlID { ...@@ -178,6 +178,20 @@ enum ControlID {
, ID_NOTEBOOK , ID_NOTEBOOK
, ID_APPRENTICE_BROWSE , ID_APPRENTICE_BROWSE
, ID_CHECK_UPDATES_NOW , 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 // ----------------------------------------------------------------------------- : EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment