Commit eca74a16 authored by twanvl's avatar twanvl

Added clone() function to Value.

Added support for per-card styling
parent fa4d91f2
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <util/error.hpp> #include <util/error.hpp>
DECLARE_TYPEOF_COLLECTION(IndexMap<FieldP COMMA ValueP>);
// ----------------------------------------------------------------------------- : Add card // ----------------------------------------------------------------------------- : Add card
AddCardAction::AddCardAction(Set& set) AddCardAction::AddCardAction(Set& set)
...@@ -91,13 +93,15 @@ void DisplayChangeAction::perform(bool to_undo) { ...@@ -91,13 +93,15 @@ void DisplayChangeAction::perform(bool to_undo) {
ChangeCardStyleAction::ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet) ChangeCardStyleAction::ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet)
: card(card), stylesheet(stylesheet) : card(card), stylesheet(stylesheet), has_styling(false) // styling_data(empty)
{} {}
String ChangeCardStyleAction::getName(bool to_undo) const { String ChangeCardStyleAction::getName(bool to_undo) const {
return _("Change style"); return _("Change style");
} }
void ChangeCardStyleAction::perform(bool to_undo) { void ChangeCardStyleAction::perform(bool to_undo) {
swap(card->stylesheet, stylesheet); swap(card->stylesheet, stylesheet);
swap(card->has_styling, has_styling);
swap(card->styling_data, styling_data);
} }
...@@ -117,3 +121,21 @@ void ChangeSetStyleAction::perform(bool to_undo) { ...@@ -117,3 +121,21 @@ void ChangeSetStyleAction::perform(bool to_undo) {
set.stylesheet = stylesheet; set.stylesheet = stylesheet;
} }
} }
ChangeCardHasStylingAction::ChangeCardHasStylingAction(Set& set, const CardP& card)
: set(set), card(card)
{
if (!card->has_styling) {
// copy of the set's styling data
styling_data.cloneFrom( set.stylingDataFor(set.stylesheetFor(card)) );
} else {
// the new styling data is empty
}
}
String ChangeCardHasStylingAction::getName(bool to_undo) const {
return _("Use custom style");
}
void ChangeCardHasStylingAction::perform(bool to_undo) {
card->has_styling = !card->has_styling;
swap(card->styling_data, styling_data);
}
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
class Set; class Set;
DECLARE_POINTER_TYPE(Card); DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(StyleSheet); DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
// ----------------------------------------------------------------------------- : Add card // ----------------------------------------------------------------------------- : Add card
...@@ -93,8 +95,10 @@ class ChangeCardStyleAction : public DisplayChangeAction { ...@@ -93,8 +95,10 @@ class ChangeCardStyleAction : public DisplayChangeAction {
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
//private: //private:
CardP card; ///< The affected card CardP card; ///< The affected card
StyleSheetP stylesheet; ///< Its new stylesheet StyleSheetP stylesheet; ///< Its old stylesheet
bool has_styling; ///< Its old has_styling
IndexMap<FieldP,ValueP> styling_data; ///< Its old styling data
}; };
/// Changing the style of a set to that of a card /// Changing the style of a set to that of a card
...@@ -111,5 +115,20 @@ class ChangeSetStyleAction : public DisplayChangeAction { ...@@ -111,5 +115,20 @@ class ChangeSetStyleAction : public DisplayChangeAction {
StyleSheetP stylesheet; ///< The old stylesheet of the set StyleSheetP stylesheet; ///< The old stylesheet of the set
}; };
/// Changing the styling of a card to become custom/non-custom
/** i.e. toggle card->has_styling */
class ChangeCardHasStylingAction : public DisplayChangeAction {
public:
ChangeCardHasStylingAction(Set& set, const CardP& card);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
//private:
Set& set; ///< The set to copy styling from
CardP card; ///< The affected card
IndexMap<FieldP,ValueP> styling_data; ///< The old styling of the card
};
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -19,14 +19,18 @@ DECLARE_TYPEOF_NO_REV(IndexMap<FieldP COMMA ValueP>); ...@@ -19,14 +19,18 @@ DECLARE_TYPEOF_NO_REV(IndexMap<FieldP COMMA ValueP>);
// ----------------------------------------------------------------------------- : Card // ----------------------------------------------------------------------------- : Card
Card::Card() { Card::Card()
: has_styling(false)
{
if (!game_for_reading()) { if (!game_for_reading()) {
throw InternalError(_("game_for_reading not set")); throw InternalError(_("game_for_reading not set"));
} }
data.init(game_for_reading()->card_fields); data.init(game_for_reading()->card_fields);
} }
Card::Card(const Game& game) { Card::Card(const Game& game)
: has_styling(false)
{
data.init(game.card_fields); data.init(game.card_fields);
} }
...@@ -55,6 +59,16 @@ void mark_dependency_member(const Card& card, const String& name, const Dependen ...@@ -55,6 +59,16 @@ void mark_dependency_member(const Card& card, const String& name, const Dependen
IMPLEMENT_REFLECTION(Card) { IMPLEMENT_REFLECTION(Card) {
REFLECT(stylesheet); REFLECT(stylesheet);
REFLECT(has_styling);
if (has_styling) {
if (stylesheet) {
REFLECT_IF_READING styling_data.init(stylesheet->styling_fields);
REFLECT(styling_data);
} else if (stylesheet_for_reading()) {
REFLECT_IF_READING styling_data.init(stylesheet_for_reading()->styling_fields);
REFLECT(styling_data);
}
}
REFLECT(notes); REFLECT(notes);
REFLECT_NO_SCRIPT(extra_data); // don't allow scripts to depend on style specific data REFLECT_NO_SCRIPT(extra_data); // don't allow scripts to depend on style specific data
REFLECT_NAMELESS(data); REFLECT_NAMELESS(data);
......
...@@ -39,6 +39,11 @@ class Card : public IntrusivePtrVirtualBase { ...@@ -39,6 +39,11 @@ class Card : public IntrusivePtrVirtualBase {
/// Alternative style to use for this card /// Alternative style to use for this card
/** Optional; if not set use the card style from the set */ /** Optional; if not set use the card style from the set */
StyleSheetP stylesheet; StyleSheetP stylesheet;
/// Alternative options to use for this card, for this card's stylesheet
/** Optional; if not set use the styling data from the set */
IndexMap<FieldP,ValueP> styling_data;
/// Is the styling_data set?
bool has_styling;
/// Extra values for specitic stylesheets, indexed by stylesheet name /// Extra values for specitic stylesheets, indexed by stylesheet name
DelayedIndexMaps<FieldP,ValueP> extra_data; DelayedIndexMaps<FieldP,ValueP> extra_data;
......
...@@ -172,6 +172,9 @@ class Value : public IntrusivePtrVirtualBase { ...@@ -172,6 +172,9 @@ class Value : public IntrusivePtrVirtualBase {
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) Age last_script_update; ///< When where the scripts last updated? (by calling update)
/// Get a copy of this value
virtual ValueP clone() const = 0;
/// Convert this value to a string for use in tables /// Convert this value to a string for use in tables
virtual String toString() const = 0; virtual String toString() const = 0;
/// Apply scripts to this value, return true if the value has changed /// Apply scripts to this value, return true if the value has changed
...@@ -213,6 +216,9 @@ template <> ValueP read_new<Value>(Reader&); ...@@ -213,6 +216,9 @@ template <> ValueP read_new<Value>(Reader&);
} \ } \
StyleP Type ## Style::clone() const { \ StyleP Type ## Style::clone() const { \
return new_intrusive1<Type ## Style>(*this); \ return new_intrusive1<Type ## Style>(*this); \
} \
ValueP Type ## Value::clone() const { \
return new_intrusive1<Type ## Value>(*this); \
} }
#define DECLARE_STYLE_TYPE(Type) \ #define DECLARE_STYLE_TYPE(Type) \
......
...@@ -52,6 +52,7 @@ class BooleanValue : public ChoiceValue { ...@@ -52,6 +52,7 @@ class BooleanValue : public ChoiceValue {
public: public:
inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {} inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {}
DECLARE_HAS_FIELD(Boolean); DECLARE_HAS_FIELD(Boolean);
virtual ValueP clone() const;
// no extra data // no extra data
......
...@@ -177,6 +177,7 @@ class ChoiceValue : public Value { ...@@ -177,6 +177,7 @@ class ChoiceValue : public Value {
typedef Defaultable<String> ValueType; typedef Defaultable<String> ValueType;
ValueType value; /// The name of the selected choice ValueType value; /// The name of the selected choice
virtual ValueP clone() const;
virtual String toString() const; virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
......
...@@ -83,6 +83,7 @@ class ColorValue : public Value { ...@@ -83,6 +83,7 @@ class ColorValue : public Value {
typedef Defaultable<Color> ValueType; typedef Defaultable<Color> ValueType;
ValueType value; ///< The value ValueType value; ///< The value
virtual ValueP clone() const;
virtual String toString() const; virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
......
...@@ -58,6 +58,7 @@ class ImageValue : public Value { ...@@ -58,6 +58,7 @@ class ImageValue : public Value {
ValueType filename; ///< Filename of the image (in the current package), or "" ValueType filename; ///< Filename of the image (in the current package), or ""
Age last_update; ///< When was the image last changed? Age last_update; ///< When was the image last changed?
virtual ValueP clone() const;
virtual String toString() const; virtual String toString() const;
private: private:
......
...@@ -68,6 +68,7 @@ class InfoValue : public Value { ...@@ -68,6 +68,7 @@ class InfoValue : public Value {
String value; String value;
virtual ValueP clone() const;
virtual String toString() const; virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
......
...@@ -56,6 +56,7 @@ class MultipleChoiceValue : public ChoiceValue { ...@@ -56,6 +56,7 @@ class MultipleChoiceValue : public ChoiceValue {
public: public:
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, false) {} inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, false) {}
DECLARE_HAS_FIELD(MultipleChoice); DECLARE_HAS_FIELD(MultipleChoice);
virtual ValueP clone() const;
String last_change; ///< Which of the choices was selected/deselected last? String last_change; ///< Which of the choices was selected/deselected last?
......
...@@ -69,6 +69,7 @@ class SymbolValue : public Value { ...@@ -69,6 +69,7 @@ class SymbolValue : public Value {
ValueType filename; ///< Filename of the symbol (in the current package) ValueType filename; ///< Filename of the symbol (in the current package)
Age last_update; ///< When was the symbol last changed? Age last_update; ///< When was the symbol last changed?
virtual ValueP clone() const;
virtual String toString() const; virtual String toString() const;
private: private:
......
...@@ -110,6 +110,7 @@ class TextValue : public Value { ...@@ -110,6 +110,7 @@ class TextValue : public Value {
ValueType value; ///< The text of this value ValueType value; ///< The text of this value
Age last_update; ///< When was the text last changed? Age last_update; ///< When was the text last changed?
virtual ValueP clone() const;
virtual String toString() const; virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
......
...@@ -91,6 +91,14 @@ StyleSheetP Set::stylesheetForP(const CardP& card) { ...@@ -91,6 +91,14 @@ StyleSheetP Set::stylesheetForP(const CardP& card) {
else return stylesheet; else return stylesheet;
} }
IndexMap<FieldP, ValueP>& Set::stylingDataFor(const StyleSheet& stylesheet) {
return styling_data.get(stylesheet.name(), stylesheet.styling_fields);
}
IndexMap<FieldP, ValueP>& Set::stylingDataFor(const CardP& card) {
if (card && card->has_styling) return card->styling_data;
else return stylingDataFor(stylesheetFor(card));
}
String Set::typeName() const { return _("set"); } String Set::typeName() const { return _("set"); }
// fix values for versions < 0.2.7 // fix values for versions < 0.2.7
...@@ -144,6 +152,7 @@ IMPLEMENT_REFLECTION(Set) { ...@@ -144,6 +152,7 @@ IMPLEMENT_REFLECTION(Set) {
} }
WITH_DYNAMIC_ARG(game_for_reading, game.get()); WITH_DYNAMIC_ARG(game_for_reading, game.get());
REFLECT(stylesheet); REFLECT(stylesheet);
WITH_DYNAMIC_ARG(stylesheet_for_reading, stylesheet.get());
REFLECT_N("set_info", data); REFLECT_N("set_info", data);
if (stylesheet) { if (stylesheet) {
REFLECT_N("styling", styling_data); REFLECT_N("styling", styling_data);
...@@ -202,12 +211,6 @@ void Set::clearOrderCache() { ...@@ -202,12 +211,6 @@ void Set::clearOrderCache() {
order_cache.clear(); order_cache.clear();
} }
// ----------------------------------------------------------------------------- : Styling
IndexMap<FieldP, ValueP>& Set::stylingDataFor(const StyleSheet& stylesheet) {
return styling_data.get(stylesheet.name(), stylesheet.styling_fields);
}
// ----------------------------------------------------------------------------- : SetView // ----------------------------------------------------------------------------- : SetView
SetView::SetView() {} SetView::SetView() {}
......
...@@ -86,6 +86,8 @@ class Set : public Packaged { ...@@ -86,6 +86,8 @@ class Set : public Packaged {
/// Styling information for a particular stylesheet /// Styling information for a particular stylesheet
IndexMap<FieldP, ValueP>& stylingDataFor(const StyleSheet&); IndexMap<FieldP, ValueP>& stylingDataFor(const StyleSheet&);
/// Styling information for a particular card
IndexMap<FieldP, ValueP>& stylingDataFor(const CardP& card);
/// Find a value in the data by name and type /// Find a value in the data by name and type
template <typename T> T& value(const String& name) { template <typename T> T& value(const String& name) {
......
...@@ -16,6 +16,8 @@ DECLARE_TYPEOF_COLLECTION(FieldP); ...@@ -16,6 +16,8 @@ DECLARE_TYPEOF_COLLECTION(FieldP);
// ----------------------------------------------------------------------------- : StyleSheet // ----------------------------------------------------------------------------- : StyleSheet
IMPLEMENT_DYNAMIC_ARG(StyleSheet*, stylesheet_for_reading, nullptr);
StyleSheet::StyleSheet() StyleSheet::StyleSheet()
: card_width(100), card_height(100) : card_width(100), card_height(100)
, card_dpi(96), card_background(*wxWHITE) , card_dpi(96), card_background(*wxWHITE)
......
...@@ -21,6 +21,9 @@ DECLARE_POINTER_TYPE(Style); ...@@ -21,6 +21,9 @@ DECLARE_POINTER_TYPE(Style);
// ----------------------------------------------------------------------------- : StyleSheet // ----------------------------------------------------------------------------- : StyleSheet
/// Stylesheet of the set that is currently being read/written
DECLARE_DYNAMIC_ARG(StyleSheet*, stylesheet_for_reading);
/// A collection of style information for card and set fields /// A collection of style information for card and set fields
class StyleSheet : public Packaged { class StyleSheet : public Packaged {
public: public:
......
...@@ -197,6 +197,11 @@ void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) { ...@@ -197,6 +197,11 @@ void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) {
setStyles(stylesheet, stylesheet->styling_style); setStyles(stylesheet, stylesheet->styling_style);
setData(set->stylingDataFor(*stylesheet)); setData(set->stylingDataFor(*stylesheet));
} }
void StylingEditor::showCard(const CardP& card) {
StyleSheetP stylesheet = set->stylesheetForP(card);
setStyles(stylesheet, stylesheet->styling_style);
setData(set->stylingDataFor(card));
}
void StylingEditor::onChangeSet() { void StylingEditor::onChangeSet() {
showStylesheet(set->stylesheet); showStylesheet(set->stylesheet);
......
...@@ -68,8 +68,10 @@ class StylingEditor : public NativeLookEditor { ...@@ -68,8 +68,10 @@ class StylingEditor : public NativeLookEditor {
public: public:
StylingEditor(Window* parent, int id, long style = 0); StylingEditor(Window* parent, int id, long style = 0);
/// Show the styling for given stylesheet in the editor /// Show the styling for given stylesheet in the editor
void showStylesheet(const StyleSheetP& stylesheet); void showStylesheet(const StyleSheetP& stylesheet);
/// Show the styling for given card
void showCard(const CardP& card);
protected: protected:
virtual void onChangeSet(); virtual void onChangeSet();
......
...@@ -23,10 +23,11 @@ StylePanel::StylePanel(Window* parent, int id) ...@@ -23,10 +23,11 @@ StylePanel::StylePanel(Window* parent, int id)
: SetWindowPanel(parent, id) : SetWindowPanel(parent, id)
{ {
// init controls // init controls
preview = new CardViewer (this, wxID_ANY); preview = new CardViewer (this, wxID_ANY);
editor = new StylingEditor(this, wxID_ANY, wxNO_BORDER); editor = new StylingEditor(this, wxID_ANY, wxNO_BORDER);
list = new PackageList (this, wxID_ANY); list = new PackageList (this, wxID_ANY);
use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _BUTTON_("use for all cards")); use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _BUTTON_("use for all cards"));
use_custom_options = new wxCheckBox(this, ID_STYLE_USE_CUSTOM, _BUTTON_("use custom styling options"));
// init sizer // init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL); wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(preview, 0, wxRIGHT, 2); s->Add(preview, 0, wxRIGHT, 2);
...@@ -34,7 +35,8 @@ StylePanel::StylePanel(Window* parent, int id) ...@@ -34,7 +35,8 @@ StylePanel::StylePanel(Window* parent, int id)
s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4); s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4);
s2->Add(use_for_all, 0, wxRIGHT | wxBOTTOM | wxALIGN_RIGHT, 4); s2->Add(use_for_all, 0, wxRIGHT | wxBOTTOM | wxALIGN_RIGHT, 4);
wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("styling options")); wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("styling options"));
s3->Add(editor, 2, wxEXPAND, 0); s3->Add(use_custom_options, 0, wxEXPAND, 0);
s3->Add(editor, 2, wxEXPAND, 0);
s2->Add(s3, 1, wxEXPAND | wxALL, 2); s2->Add(s3, 1, wxEXPAND | wxALL, 2);
s->Add(s2, 1, wxEXPAND, 8); s->Add(s2, 1, wxEXPAND, 8);
s->SetSizeHints(this); s->SetSizeHints(this);
...@@ -53,15 +55,22 @@ void StylePanel::onChangeSet() { ...@@ -53,15 +55,22 @@ void StylePanel::onChangeSet() {
void StylePanel::onAction(const Action& action, bool undone) { void StylePanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, ChangeSetStyleAction) { TYPE_CASE_(action, ChangeSetStyleAction) {
list->select(set->stylesheetFor(card).name(), false); list->select(set->stylesheetFor(card).name(), false);
editor->showStylesheet(set->stylesheetForP(card)); editor->showCard(card);
} }
TYPE_CASE(action, ChangeCardStyleAction) { TYPE_CASE(action, ChangeCardStyleAction) {
if (action.card == card) { if (action.card == card) {
list->select(set->stylesheetFor(card).name(), false); list->select(set->stylesheetFor(card).name(), false);
editor->showStylesheet(set->stylesheetForP(card)); editor->showCard(card);
}
}
TYPE_CASE(action, ChangeCardHasStylingAction) {
if (action.card == card) {
editor->showCard(card);
} }
} }
use_for_all->Enable(card && card->stylesheet); use_for_all->Enable(card && card->stylesheet);
use_custom_options->Enable(card);
use_custom_options->SetValue(card->has_styling);
} }
// ----------------------------------------------------------------------------- : Selection // ----------------------------------------------------------------------------- : Selection
...@@ -70,8 +79,11 @@ void StylePanel::selectCard(const CardP& card) { ...@@ -70,8 +79,11 @@ void StylePanel::selectCard(const CardP& card) {
this->card = card; this->card = card;
preview->setCard(card); preview->setCard(card);
editor->showStylesheet(set->stylesheetForP(card)); editor->showStylesheet(set->stylesheetForP(card));
editor->showCard(card);
list->select(set->stylesheetFor(card).name(), false); list->select(set->stylesheetFor(card).name(), false);
use_for_all->Enable(card && card->stylesheet); use_for_all->Enable(card && card->stylesheet);
use_custom_options->Enable(card);
use_custom_options->SetValue(card->has_styling);
} }
// ----------------------------------------------------------------------------- : Events // ----------------------------------------------------------------------------- : Events
...@@ -93,7 +105,12 @@ void StylePanel::onUseForAll(wxCommandEvent&) { ...@@ -93,7 +105,12 @@ void StylePanel::onUseForAll(wxCommandEvent&) {
Layout(); Layout();
} }
void StylePanel::onUseCustom(wxCommandEvent&) {
set->actions.add(new ChangeCardHasStylingAction(*set, card));
}
BEGIN_EVENT_TABLE(StylePanel, wxPanel) BEGIN_EVENT_TABLE(StylePanel, wxPanel)
EVT_GALLERY_SELECT(wxID_ANY, StylePanel::onStyleSelect) EVT_GALLERY_SELECT(wxID_ANY, StylePanel::onStyleSelect)
EVT_BUTTON (ID_STYLE_USE_FOR_ALL, StylePanel::onUseForAll) EVT_BUTTON (ID_STYLE_USE_FOR_ALL, StylePanel::onUseForAll)
EVT_CHECKBOX (ID_STYLE_USE_CUSTOM, StylePanel::onUseCustom)
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -36,10 +36,12 @@ class StylePanel : public SetWindowPanel { ...@@ -36,10 +36,12 @@ class StylePanel : public SetWindowPanel {
PackageList* list; ///< List of stylesheets PackageList* list; ///< List of stylesheets
StylingEditor* editor; ///< Editor for styling information StylingEditor* editor; ///< Editor for styling information
wxButton* use_for_all; wxButton* use_for_all;
wxCheckBox* use_custom_options;
CardP card; ///< Card we are working on CardP card; ///< Card we are working on
void onStyleSelect(wxCommandEvent&); void onStyleSelect(wxCommandEvent&);
void onUseForAll(wxCommandEvent&); void onUseForAll(wxCommandEvent&);
void onUseCustom(wxCommandEvent&);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -72,11 +72,14 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) { ...@@ -72,11 +72,14 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) {
} }
} }
Context& SetScriptContext::getContext(const CardP& card) { Context& SetScriptContext::getContext(const CardP& card) {
Context& ctx = getContext(set.stylesheetForP(card)); StyleSheetP stylesheet = set.stylesheetForP(card);
Context& ctx = getContext(stylesheet);
if (card) { if (card) {
ctx.setVariable(_("card"), to_script(card)); ctx.setVariable(_("card"), to_script(card));
ctx.setVariable(_("styling"), to_script(&set.stylingDataFor(card)));
} else { } else {
ctx.setVariable(_("card"), ScriptValueP()); ctx.setVariable(_("card"), ScriptValueP());
ctx.setVariable(_("styling"), to_script(&set.stylingDataFor(*stylesheet)));
} }
return ctx; return ctx;
} }
......
...@@ -114,10 +114,19 @@ class IndexMap : private vector<Value> { ...@@ -114,10 +114,19 @@ class IndexMap : private vector<Value> {
return end(); return end();
} }
inline void swap(IndexMap& b) {
vector<Value>::swap(b);
}
private: private:
using vector<Value>::operator []; using vector<Value>::operator [];
}; };
template <typename Key, typename Value>
inline void swap(IndexMap<Key,Value>& a, IndexMap<Key,Value>& b) {
a.swap(b);
}
// ----------------------------------------------------------------------------- : DelayedIndexMaps // ----------------------------------------------------------------------------- : DelayedIndexMaps
......
...@@ -92,6 +92,9 @@ String tr(const SymbolFont&, const String& key, const String& def); ...@@ -92,6 +92,9 @@ String tr(const SymbolFont&, const String& key, const String& def);
/// A localized string for tooltip text, with 1 argument (printf style) /// A localized string for tooltip text, with 1 argument (printf style)
#define _TOOLTIP_1_(s,a) format_string(_TOOLTIP_(s), a) #define _TOOLTIP_1_(s,a) format_string(_TOOLTIP_(s), a)
/// A localized string for button text, with 1 argument (printf style)
#define _BUTTON_1_(s,a) format_string(_BUTTON_(s), a)
/// A localized string for error messages, with 1 argument (printf style) /// A localized string for error messages, with 1 argument (printf style)
#define _ERROR_1_(s,a) format_string(_ERROR_(s), a) #define _ERROR_1_(s,a) format_string(_ERROR_(s), a)
/// A localized string for error messages, with 2 argument (printf style) /// A localized string for error messages, with 2 argument (printf style)
......
...@@ -154,6 +154,7 @@ enum ChildMenuID { ...@@ -154,6 +154,7 @@ enum ChildMenuID {
// Style panel // Style panel
, ID_STYLE_USE_FOR_ALL = 3011 , ID_STYLE_USE_FOR_ALL = 3011
, ID_STYLE_USE_CUSTOM
// Keywords panel // Keywords panel
, ID_KEYWORD_ADD_PARAM = 3021 , ID_KEYWORD_ADD_PARAM = 3021
......
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