diff --git a/src/data/action/keyword.cpp b/src/data/action/keyword.cpp new file mode 100644 index 00000000..936ab1de --- /dev/null +++ b/src/data/action/keyword.cpp @@ -0,0 +1,71 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include +#include + +DECLARE_TYPEOF_COLLECTION(KeywordModeP); + +// ----------------------------------------------------------------------------- : Add Keyword + +AddKeywordAction::AddKeywordAction(Set& set) + : KeywordListAction(set), keyword(new Keyword()) +{ + // find default mode + FOR_EACH(mode, set.game->keyword_modes) { + if (mode->is_default) { + keyword->mode = mode->name; + break; + } + } +} + +AddKeywordAction::AddKeywordAction(Set& set, const KeywordP& keyword) + : KeywordListAction(set), keyword(keyword) +{} + +String AddKeywordAction::getName(bool to_undo) const { + return _("Add keyword"); +} + +void AddKeywordAction::perform(bool to_undo) { + if (!to_undo) { + set.keywords.push_back(keyword); + } else { + assert(!set.keywords.empty()); + set.keywords.pop_back(); + } +} + +// ----------------------------------------------------------------------------- : Remove Keyword + +RemoveKeywordAction::RemoveKeywordAction(Set& set, const KeywordP& keyword) + : KeywordListAction(set), keyword(keyword) + // find the keyword_id of the keyword we want to remove + , keyword_id(find(set.keywords.begin(), set.keywords.end(), keyword) - set.keywords.begin()) +{ + if (keyword_id >= set.keywords.size()) { + throw InternalError(_("Keyword to remove not found in set")); + } +} + +String RemoveKeywordAction::getName(bool to_undo) const { + return _("Remove keyword"); +} + +void RemoveKeywordAction::perform(bool to_undo) { + if (!to_undo) { + assert(keyword_id < set.keywords.size()); + set.keywords.erase(set.keywords.begin() + keyword_id); + } else { + assert(keyword_id <= set.keywords.size()); + set.keywords.insert(set.keywords.begin() + keyword_id, keyword); + } +} diff --git a/src/data/action/keyword.hpp b/src/data/action/keyword.hpp new file mode 100644 index 00000000..02add172 --- /dev/null +++ b/src/data/action/keyword.hpp @@ -0,0 +1,66 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_DATA_ACTION_KEYWORD +#define HEADER_DATA_ACTION_KEYWORD + +/** @file data/action/keyword.hpp + * + * Actions operating on Keywords and the keyword list of a set + */ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +class Set; +DECLARE_POINTER_TYPE(Keyword); + +// ----------------------------------------------------------------------------- : Add Keyword + +/// An Action the changes the keyword list of a set +class KeywordListAction : public Action { + public: + inline KeywordListAction(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 a new keyword to a set +class AddKeywordAction : public KeywordListAction { + public: + AddKeywordAction(Set& set); + AddKeywordAction(Set& set, const KeywordP& keyword); + + virtual String getName(bool to_undo) const; + virtual void perform(bool to_undo); + + //private: + const KeywordP keyword; ///< The new keyword +}; + +// ----------------------------------------------------------------------------- : Remove Keyword + +/// Removing a keyword from a set +class RemoveKeywordAction : public KeywordListAction { + public: + RemoveKeywordAction(Set& set, const KeywordP& keyword); + + virtual String getName(bool to_undo) const; + virtual void perform(bool to_undo); + + //private: + const KeywordP keyword; ///< The removed keyword + const size_t keyword_id; ///< Position of the keyword in the set +}; + +// ----------------------------------------------------------------------------- : Changing keywords + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/data/action/set.hpp b/src/data/action/set.hpp index 73ec61d4..0c4f8de8 100644 --- a/src/data/action/set.hpp +++ b/src/data/action/set.hpp @@ -30,6 +30,7 @@ class CardListAction : public Action { 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 a new card to a set diff --git a/src/data/action/value.hpp b/src/data/action/value.hpp index 16e971e1..8a9486f1 100644 --- a/src/data/action/value.hpp +++ b/src/data/action/value.hpp @@ -7,7 +7,7 @@ #ifndef HEADER_DATA_ACTION_VALUE #define HEADER_DATA_ACTION_VALUE -/** @file data/action/set.hpp +/** @file data/action/value.hpp * * Actions operating on Values (and derived classes, "*Value") */ diff --git a/src/data/keyword.hpp b/src/data/keyword.hpp index c56c542d..bbf5cdf3 100644 --- a/src/data/keyword.hpp +++ b/src/data/keyword.hpp @@ -39,6 +39,7 @@ class KeywordParam { /// Information on when and how to use a keyword class KeywordMode { + public: String name; ///< Name of the mode String description; ///< Description of the type bool is_default; ///< This is the default mode for new keywords @@ -51,6 +52,8 @@ class KeywordMode { /// A keyword for a set or a game class Keyword { public: + Keyword() : fixed(false) {} + String keyword; ///< The keyword, only for human use String rules; ///< Rules/explanation String match; ///< String to match, tags are used for parameters diff --git a/src/gui/print_window.cpp b/src/gui/print_window.cpp index c5cb60a8..e32e74c1 100644 --- a/src/gui/print_window.cpp +++ b/src/gui/print_window.cpp @@ -10,6 +10,7 @@ #include #include #include +#include DECLARE_TYPEOF_COLLECTION(CardP); @@ -88,8 +89,42 @@ void TextBufferDC::drawToDevice(DC& dc, int x, int y) { } } +// ----------------------------------------------------------------------------- : Layout + +/// Layout of a page of cards +class PageLayout { + public: + RealSize card_size; ///< Size of a card + RealSize card_space; ///< Spacing between cards + double margin_left, margin_right, margin_top, margin_bottom; ///< Page margins + int rows, cols; ///< Number of rows/columns of cards + bool landscape; ///< Are cards rotated to landscape orientation? +}; + // ----------------------------------------------------------------------------- : Printout +/// A printout object specifying how to print a specified set of cards +class CardsPrintout : wxPrintout { + public: + CardsPrintout(const SetP& set, const vector& cards); + /// Determine card size, cards per row + void OnPreparePrinting(); + /// Number of pages, and something else I don't understand... + void GetPageInfo(int* pageMin, int* pageMax, int* pageFrom, int* pageTo); + /// Again, 'number of pages', strange wx interface + bool HasPage(int page); + /// Print a page + bool OnPrintPage(int page); + + private: + PageLayout layout; + + /// Draw a card, that is card_nr on this page, find the postion by asking the layout + void drawCard(DC& dc, const CardP& card, UInt card_nr); + /// Draw a card at the specified coordinates + void drawCard(DC& dc, const CardP& card, double x, double y, int rotation = 0); +}; + // ----------------------------------------------------------------------------- : PrintWindow void print_preview(Window* parent, const SetP& set) { diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index 111b644a..81b5425a 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -30,7 +30,7 @@ CardsPanel::CardsPanel(Window* parent, int id) editor = new CardEditor(this, ID_EDITOR); splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0); card_list = new ImageCardList(splitter, ID_CARD_LIST); - notesP = new Panel(splitter, wxID_ANY); + notesP = new Panel(splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* no tab traversal*/); notes = new TextCtrl(notesP, ID_NOTES, true); collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour); collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); diff --git a/src/gui/set/keywords_panel.cpp b/src/gui/set/keywords_panel.cpp index b183543d..c58b3ca4 100644 --- a/src/gui/set/keywords_panel.cpp +++ b/src/gui/set/keywords_panel.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,7 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id) // init controls splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0); list = new KeywordList(splitter, wxID_ANY); - panel = new Panel(splitter, wxID_ANY); + panel = new Panel(splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* no tab traversal*/); keyword = new TextCtrl(panel, wxID_ANY, false); match = new TextCtrl(panel, wxID_ANY, false); reminder = new TextCtrl(panel, wxID_ANY, false); @@ -114,10 +115,13 @@ void KeywordsPanel::onCommand(int id) { list->selectNext(); break; case ID_KEYWORD_ADD: -// set->actions.add(new AddKeywordAction(*set)); + set->actions.add(new AddKeywordAction(*set)); break; case ID_KEYWORD_REMOVE: -// set->actions.add(new RemoveKeywordAction(*set, list->getKeyword())); + if (!list->getKeyword()->fixed) { + // only remove set keywords + set->actions.add(new RemoveKeywordAction(*set, list->getKeyword())); + } break; } } diff --git a/src/mse.vcproj b/src/mse.vcproj index 09f2f8ef..4b629202 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -875,6 +875,12 @@ + + + + @@ -1219,6 +1225,48 @@ + + + + + + + + + + + + + + + + + + + + + +