Added clone() function to Value.

Added support for per-card styling

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@430 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-06-24 01:30:34 +00:00
parent df9bb78e51
commit f0628317a3
25 changed files with 147 additions and 21 deletions
+24 -2
View File
@@ -12,6 +12,8 @@
#include <data/stylesheet.hpp>
#include <util/error.hpp>
DECLARE_TYPEOF_COLLECTION(IndexMap<FieldP COMMA ValueP>);
// ----------------------------------------------------------------------------- : Add card
AddCardAction::AddCardAction(Set& set)
@@ -91,13 +93,15 @@ void DisplayChangeAction::perform(bool to_undo) {
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 {
return _("Change style");
}
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) {
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);
}
+21 -2
View File
@@ -20,6 +20,8 @@
class Set;
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
// ----------------------------------------------------------------------------- : Add card
@@ -93,8 +95,10 @@ class ChangeCardStyleAction : public DisplayChangeAction {
virtual void perform(bool to_undo);
//private:
CardP card; ///< The affected card
StyleSheetP stylesheet; ///< Its new stylesheet
CardP card; ///< The affected card
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
@@ -111,5 +115,20 @@ class ChangeSetStyleAction : public DisplayChangeAction {
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
#endif
+16 -2
View File
@@ -19,14 +19,18 @@ DECLARE_TYPEOF_NO_REV(IndexMap<FieldP COMMA ValueP>);
// ----------------------------------------------------------------------------- : Card
Card::Card() {
Card::Card()
: has_styling(false)
{
if (!game_for_reading()) {
throw InternalError(_("game_for_reading not set"));
}
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);
}
@@ -55,6 +59,16 @@ void mark_dependency_member(const Card& card, const String& name, const Dependen
IMPLEMENT_REFLECTION(Card) {
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_NO_SCRIPT(extra_data); // don't allow scripts to depend on style specific data
REFLECT_NAMELESS(data);
+5
View File
@@ -39,6 +39,11 @@ class Card : public IntrusivePtrVirtualBase {
/// Alternative style to use for this card
/** Optional; if not set use the card style from the set */
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
DelayedIndexMaps<FieldP,ValueP> extra_data;
+6
View File
@@ -172,6 +172,9 @@ class Value : public IntrusivePtrVirtualBase {
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)
/// Get a copy of this value
virtual ValueP clone() const = 0;
/// 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
@@ -213,6 +216,9 @@ template <> ValueP read_new<Value>(Reader&);
} \
StyleP Type ## Style::clone() const { \
return new_intrusive1<Type ## Style>(*this); \
} \
ValueP Type ## Value::clone() const { \
return new_intrusive1<Type ## Value>(*this); \
}
#define DECLARE_STYLE_TYPE(Type) \
+1
View File
@@ -52,6 +52,7 @@ class BooleanValue : public ChoiceValue {
public:
inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {}
DECLARE_HAS_FIELD(Boolean);
virtual ValueP clone() const;
// no extra data
+1
View File
@@ -177,6 +177,7 @@ class ChoiceValue : public Value {
typedef Defaultable<String> ValueType;
ValueType value; /// The name of the selected choice
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
+1
View File
@@ -83,6 +83,7 @@ class ColorValue : public Value {
typedef Defaultable<Color> ValueType;
ValueType value; ///< The value
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
+1
View File
@@ -58,6 +58,7 @@ class ImageValue : public Value {
ValueType filename; ///< Filename of the image (in the current package), or ""
Age last_update; ///< When was the image last changed?
virtual ValueP clone() const;
virtual String toString() const;
private:
+1
View File
@@ -68,6 +68,7 @@ class InfoValue : public Value {
String value;
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
+1
View File
@@ -56,6 +56,7 @@ class MultipleChoiceValue : public ChoiceValue {
public:
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, false) {}
DECLARE_HAS_FIELD(MultipleChoice);
virtual ValueP clone() const;
String last_change; ///< Which of the choices was selected/deselected last?
+1
View File
@@ -69,6 +69,7 @@ class SymbolValue : public Value {
ValueType filename; ///< Filename of the symbol (in the current package)
Age last_update; ///< When was the symbol last changed?
virtual ValueP clone() const;
virtual String toString() const;
private:
+1
View File
@@ -110,6 +110,7 @@ class TextValue : public Value {
ValueType value; ///< The text of this value
Age last_update; ///< When was the text last changed?
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
+9 -6
View File
@@ -91,6 +91,14 @@ StyleSheetP Set::stylesheetForP(const CardP& card) {
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"); }
// fix values for versions < 0.2.7
@@ -144,6 +152,7 @@ IMPLEMENT_REFLECTION(Set) {
}
WITH_DYNAMIC_ARG(game_for_reading, game.get());
REFLECT(stylesheet);
WITH_DYNAMIC_ARG(stylesheet_for_reading, stylesheet.get());
REFLECT_N("set_info", data);
if (stylesheet) {
REFLECT_N("styling", styling_data);
@@ -202,12 +211,6 @@ void Set::clearOrderCache() {
order_cache.clear();
}
// ----------------------------------------------------------------------------- : Styling
IndexMap<FieldP, ValueP>& Set::stylingDataFor(const StyleSheet& stylesheet) {
return styling_data.get(stylesheet.name(), stylesheet.styling_fields);
}
// ----------------------------------------------------------------------------- : SetView
SetView::SetView() {}
+2
View File
@@ -86,6 +86,8 @@ class Set : public Packaged {
/// Styling information for a particular 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
template <typename T> T& value(const String& name) {
+2
View File
@@ -16,6 +16,8 @@ DECLARE_TYPEOF_COLLECTION(FieldP);
// ----------------------------------------------------------------------------- : StyleSheet
IMPLEMENT_DYNAMIC_ARG(StyleSheet*, stylesheet_for_reading, nullptr);
StyleSheet::StyleSheet()
: card_width(100), card_height(100)
, card_dpi(96), card_background(*wxWHITE)
+3
View File
@@ -21,6 +21,9 @@ DECLARE_POINTER_TYPE(Style);
// ----------------------------------------------------------------------------- : 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
class StyleSheet : public Packaged {
public: