From b6c7e5bd012d02cbf6dd319c312cbef70f05a65f Mon Sep 17 00:00:00 2001 From: twanvl Date: Mon, 9 Oct 2006 16:21:38 +0000 Subject: [PATCH] start with implementing fields git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@12 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/card.hpp | 2 - src/data/field.cpp | 34 +++++++++- src/data/field.hpp | 63 ++++++++++++++++++- src/data/game.cpp | 18 +++++- src/data/game.hpp | 1 + src/data/settings.cpp | 125 +++++++++++++++++++++++++++++++++++++ src/data/settings.hpp | 134 ++++++++++++++++++++++++++++++++++++++++ src/data/stylesheet.cpp | 11 ++++ src/data/stylesheet.hpp | 27 ++++++++ src/gfx/bezier.hpp | 2 +- src/gui/set/panel.cpp | 15 +++++ src/gui/set/window.cpp | 6 +- src/mse.vcproj | 12 +++- src/util/error.hpp | 8 +-- src/util/io/reader.hpp | 11 +++- src/util/real_point.hpp | 5 ++ 16 files changed, 453 insertions(+), 21 deletions(-) create mode 100644 src/data/settings.cpp create mode 100644 src/data/settings.hpp create mode 100644 src/data/stylesheet.cpp create mode 100644 src/data/stylesheet.hpp create mode 100644 src/gui/set/panel.cpp diff --git a/src/data/card.hpp b/src/data/card.hpp index b84aac8d..56314e1f 100644 --- a/src/data/card.hpp +++ b/src/data/card.hpp @@ -14,9 +14,7 @@ #include class Game; -#ifndef HEADER_DATA_GAME DECLARE_POINTER_TYPE(Field); -#endif DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(CardStyle); diff --git a/src/data/field.cpp b/src/data/field.cpp index 9d0c9aea..2991cedf 100644 --- a/src/data/field.cpp +++ b/src/data/field.cpp @@ -9,8 +9,38 @@ #include // ----------------------------------------------------------------------------- : Field + +IMPLEMENT_REFLECTION(Field) { +} + +template <> +shared_ptr read_new(Reader& reader) { + // there must be a type specified + String type; + reader.handle(_("type"), type); +// if (type == _("text")) { +// } else { + throw "TODO"; +// } +} + + + +// ----------------------------------------------------------------------------- : Style + +IMPLEMENT_REFLECTION(Style) { +} + +void initObject(const FieldP& field, StyleP& style) { + style = field->newStyle(field); +} + // ----------------------------------------------------------------------------- : Value -void initObject(const FieldP& field, ValueP& value) { - value = new_shared(); +IMPLEMENT_REFLECTION(Value) { } + +void initObject(const FieldP& field, ValueP& value) { + value = field->newValue(field); +} + diff --git a/src/data/field.hpp b/src/data/field.hpp index 35f6940a..0b00d4e1 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -10,20 +10,77 @@ // ----------------------------------------------------------------------------- : Includes #include +#include -#ifndef HEADER_DATA_CARD DECLARE_POINTER_TYPE(Field); +DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Value); -#endif // ----------------------------------------------------------------------------- : Field +/// Information on how to store a value class Field { public: - UInt index; // used by IndexMap + Field(); + virtual ~Field(); + + UInt index; ///< Used by IndexMap + String name; ///< Name of the field, for refering to it from scripts and files + String description; ///< Description, used in status bar + bool editable; ///< Can values of this field be edited? + bool saveValue; ///< Should values of this field be written to files? Can be false for script generated fields. + bool showStatistics; ///< Should this field appear as a group by choice in the statistics panel? + bool identifying; ///< Does this field give Card::identification()? + int cardListColumn; ///< What column to use in the card list? -1 = don't list + UInt cardListWidth; ///< Width of the card list column (pixels). + bool cardListAllow; ///< Is this field allowed to appear in the card list. + String cardListName; ///< Alternate name to use in card list. +// Alignment cardListAlign; ///< Alignment of the card list colummn. + int tabIndex; ///< Tab index in editor +// Vector dependendScripts; // scripts that depend on values of this field + + /// Creates a new Value corresponding to this Field + /** thisP is a smart pointer to this */ + virtual ValueP newValue(FieldP thisP) = 0; + /// Creates a new Style corresponding to this Field + /** thisP is a smart pointer to this */ + virtual StyleP newStyle(FieldP thisP) = 0; + /// create a copy of this field + virtual FieldP clone() = 0; + /// Type of this field + virtual String typeName() = 0; + + private: + DECLARE_REFLECTION_VIRTUAL(); }; +template <> +shared_ptr read_new(Reader& reader); + + +// ----------------------------------------------------------------------------- : Style + +class Style { + public: + virtual ~Style(); + + private: + DECLARE_REFLECTION_VIRTUAL(); +}; + +void initObject(const FieldP&, StyleP&); + +// ----------------------------------------------------------------------------- : Value + class Value { + public: + virtual ~Value(); + + /// Create a copy of this value + virtual ValueP clone() = 0; + + private: + DECLARE_REFLECTION_VIRTUAL(); }; void initObject(const FieldP&, ValueP&); diff --git a/src/data/game.cpp b/src/data/game.cpp index df810319..7e3599ba 100644 --- a/src/data/game.cpp +++ b/src/data/game.cpp @@ -7,6 +7,7 @@ // ----------------------------------------------------------------------------- : Includes #include +#include #include // ----------------------------------------------------------------------------- : Game @@ -22,6 +23,19 @@ bool Game::isMagic() const { String Game::typeName() const { return _("game"); } IMPLEMENT_REFLECTION(Game) { - REFLECT_N("full name", fullName); - REFLECT_N("icon", iconFilename); +// ioMseVersion(io, fileName, fileVersion); + REFLECT_N("full name", fullName); + REFLECT_N("icon", iconFilename); +// REFLECT_N("init script", initScript); + REFLECT_N("set field", setFields); + REFLECT_N("card field", cardFields); +// REFLECT_N("keyword parameter type", keywordParams); +// REFLECT_N("keyword separator type", keywordSeparators); +// REFLECT_N("keyword", keywords); +// REFLECT_N("word list", wordLists); +} + +void Game::validate() { + // a default for the full name + if (fullName.empty()) fullName = name(); } \ No newline at end of file diff --git a/src/data/game.hpp b/src/data/game.hpp index b094ad28..b648eb61 100644 --- a/src/data/game.hpp +++ b/src/data/game.hpp @@ -32,6 +32,7 @@ class Game : public Packaged { protected: String typeName() const; + void validate(); DECLARE_REFLECTION(); }; diff --git a/src/data/settings.cpp b/src/data/settings.cpp new file mode 100644 index 00000000..ada38498 --- /dev/null +++ b/src/data/settings.cpp @@ -0,0 +1,125 @@ +//+----------------------------------------------------------------------------+ +//| 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 +#include +#include +#include + +// ----------------------------------------------------------------------------- : Extra types + +IMPLEMENT_REFLECTION_ENUM(CheckUpdates) { + VALUE_N("if connected", CHECK_IF_CONNECTED); //default + VALUE_N("always", CHECK_ALWAYS); + VALUE_N("never", CHECK_NEVER); +} + +IMPLEMENT_REFLECTION(ColumnSettings) { + REFLECT(width); + REFLECT(position); + REFLECT(visible); +} + +IMPLEMENT_REFLECTION(GameSettings) { + REFLECT_N("default style", defaultStyle); + REFLECT_N("default export", defaultExport); +// REFLECT_N("cardlist columns", columns); + REFLECT_N("sort cards by", sortCardsBy); + REFLECT_N("sort cards ascending", sortCardsAscending); +} + +IMPLEMENT_REFLECTION(StyleSettings) { + // TODO +} + +// ----------------------------------------------------------------------------- : Settings + +Settings settings; + +Settings::Settings() + : setWindowMaximized (false) + , setWindowWidth (790) + , setWindowHeight (300) + , cardNotesHeight (40) + , updatesUrl (_("http://magicseteditor.sourceforge.net/updates")) + , checkUpdates (CHECK_IF_CONNECTED) +{} + +void Settings::addRecentFile(const String& filename) { + // get absolute path + wxFileName fn(filename); + fn.Normalize(); + String filenameAbs = fn.GetFullPath(); + // remove duplicates + recentSets.erase( + remove(recentSets.begin(), recentSets.end(), filenameAbs), + recentSets.end() + ); + // add to front of list + recentSets.insert(recentSets.begin(), filenameAbs); + // enforce size limit + if (recentSets.size() > maxRecentSets) recentSets.resize(maxRecentSets); +} + +GameSettings& Settings::gameSettingsFor(const Game& game) { + GameSettingsP& gs = settings.gameSettings[game.name()]; + if (!gs) gs.reset(new GameSettings); + return *gs; +} +/* +StyleSettings& Settings::styleSettingsFor(const CardStyle& style) { + StyleSettingsP& ss = settings.styleSettings#(style.name()); + if (!ss) ss = new_shared(); + ss->useDefault(defaultStyleSettings); // update default settings + return *ss; +} +*/ + +String userSettingsDir() { + return _(""); // TODO +} + +String Settings::settingsFile() { +// return userSettingsDir() + _("mse.config"); + return userSettingsDir() + _("mse8.config"); // use different file during development of C++ port +} + +IMPLEMENT_REFLECTION(Settings) { +// ioMseVersion(io, "settings", fileVersion); + REFLECT_N("recent set", recentSets); + REFLECT_N("window maximized", setWindowMaximized); + REFLECT_N("window width", setWindowWidth); + REFLECT_N("window height", setWindowHeight); + REFLECT_N("card notes height", cardNotesHeight); + REFLECT_N("default game", defaultGame); + REFLECT_N("apprentice location", apprenticeLocation); + REFLECT_N("updates url", updatesUrl); + REFLECT_N("check updates", checkUpdates); +// ioAll(io, "game settings", gameSettings); +// ioStyleSettings(io); + REFLECT_N("default style settings", defaultStyleSettings); +} + +void Settings::read() { + String filename = settingsFile(); + if (wxFileExists(filename)) { + // settings file not existing is not an error + shared_ptr file = new_shared1(filename); + if (!file->Ok()) return; // failure is not an error + Reader reader(file, filename); + reader.handle(*this); + } +} + +void Settings::write() { + Writer writer(new_shared1(settingsFile())); + writer.handle(*this); +} diff --git a/src/data/settings.hpp b/src/data/settings.hpp new file mode 100644 index 00000000..8bd5b388 --- /dev/null +++ b/src/data/settings.hpp @@ -0,0 +1,134 @@ +//+----------------------------------------------------------------------------+ +//| 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_SETTINGS +#define HEADER_DATA_SETTINGS + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +class Game; +class CardStyle; + +DECLARE_POINTER_TYPE(GameSettings); +DECLARE_POINTER_TYPE(StyleSettings); + +// ----------------------------------------------------------------------------- : Extra data structures + +/// When to check for updates? +enum CheckUpdates +{ CHECK_ALWAYS +, CHECK_IF_CONNECTED +, CHECK_NEVER +}; + +/// Settings of a single column in the card list +class ColumnSettings { + public: + UInt width; + int position; + bool visible; + + DECLARE_REFLECTION(); +}; + +/// Settings for a Game +class GameSettings { + public: + String defaultStyle; + String defaultExport; + map columns; + String sortCardsBy; + bool sortCardsAscending; + + DECLARE_REFLECTION(); +}; + +/// Settings for a Style +class StyleSettings { + public: + // Rendering/display settings +/* SimpleDefaultable cardZoom = 1.0; + SimpleDefaultable cardAngle = 0; + SimpleDefaultable cardAntiAlias = true; + SimpleDefaultable cardBorders = true; + SimpleDefaultable cardNormalExport = true; +*/ + DECLARE_REFLECTION(); + +// /// Where the settings are the default, use the value from ss +// void useDefault(const StyleSettings& ss); +}; + +// ----------------------------------------------------------------------------- : Settings + +/// Class that holds MSE settings. +/** There is a single global instance of this class. + * Settings are loaded at startup, and stored at shutdown. + */ +class Settings { + public: + /// Default constructor initializes default settings + Settings(); + + // --------------------------------------------------- : Recently opened sets + vector recentSets; + static const UInt maxRecentSets = 4; // store this many recent sets + + /// Add a file to the list of recent files + void addRecentFile(const String& filename); + + // --------------------------------------------------- : Set window size + bool setWindowMaximized; + UInt setWindowWidth; + UInt setWindowHeight; + UInt cardNotesHeight; + + // --------------------------------------------------- : Default pacakge selections + String defaultGame; + + // --------------------------------------------------- : Game/style specific + + /// Get the settings object for a specific game + GameSettings& gameSettingsFor(const Game& game); + /// Get the settings object for a specific style + StyleSettings& styleSettingsFor(const CardStyle& style); + + private: + map gameSettings; + map styleSettings; + StyleSettings defaultStyleSettings; + public: + + // --------------------------------------------------- : Special game stuff + String apprenticeLocation; + String mwsLocation; + + // --------------------------------------------------- : Update checking + String updatesUrl; + CheckUpdates checkUpdates; + + // --------------------------------------------------- : The io + + /// Read the settings file from the standard location + void read(); + /// Store the settings in the standard location + void write(); + + private: + /// Name of the settings file + String settingsFile(); + + DECLARE_REFLECTION(); +}; + +/// The global settings object +extern Settings settings; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/data/stylesheet.cpp b/src/data/stylesheet.cpp new file mode 100644 index 00000000..4384411b --- /dev/null +++ b/src/data/stylesheet.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/data/stylesheet.hpp b/src/data/stylesheet.hpp new file mode 100644 index 00000000..53ee35e4 --- /dev/null +++ b/src/data/stylesheet.hpp @@ -0,0 +1,27 @@ +//+----------------------------------------------------------------------------+ +//| 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_STYLESHEET +#define HEADER_DATA_STYLESHEET + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +DECLARE_POINTER_TYPE(Game); + +// ----------------------------------------------------------------------------- : StyleSheet + +/// A collection of style information for card and set fields +class StyleSheet : Packaged { + public: + GameP game; + private: +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/gfx/bezier.hpp b/src/gfx/bezier.hpp index 68a88a9e..f7e54e40 100644 --- a/src/gfx/bezier.hpp +++ b/src/gfx/bezier.hpp @@ -37,7 +37,7 @@ class BezierCurve { return d + (c + (b + a * t) * t) * t; } - /// Return the tangent on this curve at time t in [0...1) + /// Return the tangent on this curve at time t in [0...1) inline Vector2D tangentAt(double t) const { return c + ((b * 2) + (a * 3) * t) * t; } diff --git a/src/gui/set/panel.cpp b/src/gui/set/panel.cpp new file mode 100644 index 00000000..72af32bc --- /dev/null +++ b/src/gui/set/panel.cpp @@ -0,0 +1,15 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : SetWindowPanel + +SetWindowPanel::SetWindowPanel(Window* parent, int id, bool autoTabbing) + : wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, autoTabbing ? wxTAB_TRAVERSAL : 0) +{} diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 4b77e9c9..ff748c53 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -40,10 +40,10 @@ SetWindow::SetWindow(Window* parent, const SetP& set) menuFile->Append(ID_FILE_SAVE_AS, _("Save &As...\tF12"), _("Save the set with a new name")); IconMenu* menuExport = new IconMenu(); menuExport->Append(ID_FILE_EXPORT_HTML, _("&HTML..."), _("Export the set to a HTML file")); - menuExport->Append(ID_FILE_EXPORT_IMAGE, _("Card &Image::.."), _("Export the selected card to an image file")); + menuExport->Append(ID_FILE_EXPORT_IMAGE, _("Card &Image..."), _("Export the selected card to an image file")); menuExport->Append(ID_FILE_EXPORT_IMAGES, _("All Card I&mages..."), _("Export images for all cards")); - menuExport->Append(ID_FILE_EXPORT_APPR, _("&Apprentice::.."), _("Export the set so it can be played with in Apprentice")); - menuExport->Append(ID_FILE_EXPORT_MWS, _("Magic &Workstation::.."), _("Export the set so it can be played with in Magic Workstation")); + menuExport->Append(ID_FILE_EXPORT_APPR, _("&Apprentice..."), _("Export the set so it can be played with in Apprentice")); + menuExport->Append(ID_FILE_EXPORT_MWS, _("Magic &Workstation..."), _("Export the set so it can be played with in Magic Workstation")); menuFile->Append(ID_FILE_EXPORT, _("&Export"), _("Export the set..."), menuExport); menuFile->AppendSeparator(); menuFile->Append(ID_FILE_INSPECT, _("Inspect Internal Data..."), _("Shows a the data in the set using a tree structure")); diff --git a/src/mse.vcproj b/src/mse.vcproj index 16496345..5eb8a089 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -555,9 +555,6 @@ - - @@ -585,6 +582,12 @@ + + + + + + diff --git a/src/util/error.hpp b/src/util/error.hpp index d4359709..1928e37a 100644 --- a/src/util/error.hpp +++ b/src/util/error.hpp @@ -7,15 +7,15 @@ #ifndef HEADER_UTIL_ERROR #define HEADER_UTIL_ERROR -// ----------------------------------------------------------------------------- : Includes - -#include - /** @file util/error.hpp * * @brief Classes and functions for handling errors/exceptions. */ +// ----------------------------------------------------------------------------- : Includes + +#include + // ----------------------------------------------------------------------------- : Error types /// Our own exception class diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index 2d597db0..ed553c0a 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -99,6 +99,15 @@ class Reader { // ----------------------------------------------------------------------------- : Container types +/// Construct a new type, possibly reading something in the process. +/** By default just creates a new object. + * This function can be overloaded to provide different behaviour + */ +template +shared_ptr read_new(Reader& reader) { + return new_shared(); +} + template void Reader::handle(vector& vector) { String vectorKey = key; @@ -111,7 +120,7 @@ void Reader::handle(vector& vector) { template void Reader::handle(shared_ptr& pointer) { - if (!pointer) pointer.reset(new T); + if (!pointer) pointer = read_new(*this); handle(*pointer); } diff --git a/src/util/real_point.hpp b/src/util/real_point.hpp index 87845643..7a2e30fe 100644 --- a/src/util/real_point.hpp +++ b/src/util/real_point.hpp @@ -7,6 +7,11 @@ #ifndef HEADER_UTIL_REAL_POINT #define HEADER_UTIL_REAL_POINT +/** @file util/real_point.hpp + * + * @brief Points and sizes with floating point (real) coordinates. + */ + // ----------------------------------------------------------------------------- : Includes #include