adding & editing custom pack types now works.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1328 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2009-01-10 01:37:03 +00:00
parent d3922cb59d
commit e3cdb2bea7
11 changed files with 152 additions and 23 deletions
+31
View File
@@ -10,11 +10,13 @@
#include <data/action/set.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/pack.hpp>
#include <data/stylesheet.hpp>
#include <util/error.hpp>
DECLARE_TYPEOF_COLLECTION(IndexMap<FieldP COMMA ValueP>);
DECLARE_TYPEOF_COLLECTION(CardP);
DECLARE_TYPEOF_COLLECTION(PackTypeP);
DECLARE_TYPEOF_COLLECTION(int);
// ----------------------------------------------------------------------------- : Add card
@@ -135,3 +137,32 @@ void ChangeCardHasStylingAction::perform(bool to_undo) {
card->has_styling = !card->has_styling;
swap(card->styling_data, styling_data);
}
// ----------------------------------------------------------------------------- : Pack types
AddPackAction::AddPackAction(AddingOrRemoving ar, Set& set, const PackTypeP& pack)
: PackTypesAction(set)
, action(ar, pack, set.pack_types)
{}
String AddPackAction::getName(bool to_undo) const {
return action.getName();
}
void AddPackAction::perform(bool to_undo) {
action.perform(set.pack_types, to_undo);
}
ChangePackAction::ChangePackAction(Set& set, size_t pos, const PackTypeP& pack)
: PackTypesAction(set)
, pos(pos), pack(pack)
{}
String ChangePackAction::getName(bool to_undo) const {
return _ACTION_1_("change",type_name(pack));
}
void ChangePackAction::perform(bool to_undo) {
swap(set.pack_types.at(pos), pack);
}
+40
View File
@@ -23,7 +23,9 @@ DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(PackType);
DECLARE_TYPEOF_COLLECTION(GenericAddAction<CardP>::Step);
DECLARE_TYPEOF_COLLECTION(GenericAddAction<PackTypeP>::Step);
// ----------------------------------------------------------------------------- : Add card
@@ -119,5 +121,43 @@ class ChangeCardHasStylingAction : public DisplayChangeAction {
IndexMap<FieldP,ValueP> styling_data; ///< The old styling of the card
};
// ----------------------------------------------------------------------------- : Pack types
/// An Action the changes the pack types of a set
class PackTypesAction : public Action {
public:
inline PackTypesAction(Set& set) : set(set) {}
protected:
Set& set; // the set owns this action, so the set will not be destroyed before this
// therefore we don't need a smart pointer
};
/// Adding/removing a pack from a Set
class AddPackAction : public PackTypesAction {
public:
/// Add a newly allocated card
AddPackAction(AddingOrRemoving, Set& set, const PackTypeP& pack);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
const GenericAddAction<PackTypeP> action;
};
/// Updating a pack in a Set
class ChangePackAction : public PackTypesAction {
public:
/// Add a newly allocated card
ChangePackAction(Set& set, size_t pos, const PackTypeP& new_pack);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
PackTypeP pack;
size_t pos;
};
// ----------------------------------------------------------------------------- : EOF
#endif