Commit cded62cb authored by twanvl's avatar twanvl

Added actions for adding/removing keywords

parent 7a33fa32
//+----------------------------------------------------------------------------+
//| 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 <data/action/keyword.hpp>
#include <data/keyword.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
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);
}
}
//+----------------------------------------------------------------------------+
//| 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 <util/prec.hpp>
#include <util/action_stack.hpp>
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
......@@ -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
......
......@@ -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")
*/
......
......@@ -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, <param> tags are used for parameters
......
......@@ -10,6 +10,7 @@
#include <gui/card_select_window.hpp>
#include <gui/util.hpp>
#include <data/set.hpp>
#include <wx/print.h>
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<CardP>& 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) {
......
......@@ -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);
......
......@@ -12,6 +12,7 @@
#include <gui/icon_menu.hpp>
#include <gui/util.hpp>
#include <data/keyword.hpp>
#include <data/action/keyword.hpp>
#include <data/field/text.hpp>
#include <util/window_id.hpp>
#include <wx/listctrl.h>
......@@ -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;
}
}
......
......@@ -875,6 +875,12 @@
<File
RelativePath=".\gui\drop_down_list.hpp">
</File>
<File
RelativePath=".\gui\html_export_window.cpp">
</File>
<File
RelativePath=".\gui\html_export_window.hpp">
</File>
<File
RelativePath=".\gui\image_slice_window.cpp">
</File>
......@@ -1219,6 +1225,48 @@
<Filter
Name="action"
Filter="">
<File
RelativePath=".\data\action\keyword.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Debug Unicode|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release Unicode|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release Profile Unicode|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release Unicode fast build|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath=".\data\action\keyword.hpp">
</File>
<File
RelativePath=".\data\action\set.cpp">
<FileConfiguration
......
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