Commit 07d69616 authored by twanvl's avatar twanvl

start with implementing fields

parent 9ca309c6
......@@ -14,9 +14,7 @@
#include <util/dynamic_arg.hpp>
class Game;
#ifndef HEADER_DATA_GAME
DECLARE_POINTER_TYPE(Field);
#endif
DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(CardStyle);
......
......@@ -9,8 +9,38 @@
#include <data/field.hpp>
// ----------------------------------------------------------------------------- : Field
IMPLEMENT_REFLECTION(Field) {
}
template <>
shared_ptr<Field> read_new<Field>(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
IMPLEMENT_REFLECTION(Value) {
}
void initObject(const FieldP& field, ValueP& value) {
value = new_shared<Value>();
value = field->newValue(field);
}
......@@ -10,20 +10,77 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/reflect.hpp>
#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<DependendScript> 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<Field> read_new<Field>(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&);
......
......@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/game.hpp>
#include <data/field.hpp>
#include <util/io/package_manager.hpp>
// ----------------------------------------------------------------------------- : 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
......@@ -32,6 +32,7 @@ class Game : public Packaged {
protected:
String typeName() const;
void validate();
DECLARE_REFLECTION();
};
......
//+----------------------------------------------------------------------------+
//| 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/settings.hpp>
#include <data/game.hpp>
#include <util/reflect.hpp>
#include <util/io/reader.hpp>
#include <util/io/writer.hpp>
#include <wx/filename.h>
#include <wx/wfstream.h>
// ----------------------------------------------------------------------------- : 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<StyleSettings>();
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<wxFileInputStream> file = new_shared1<wxFileInputStream>(filename);
if (!file->Ok()) return; // failure is not an error
Reader reader(file, filename);
reader.handle(*this);
}
}
void Settings::write() {
Writer writer(new_shared1<wxFileOutputStream>(settingsFile()));
writer.handle(*this);
}
//+----------------------------------------------------------------------------+
//| 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 <util/prec.hpp>
#include <util/reflect.hpp>
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<String, ColumnSettings> columns;
String sortCardsBy;
bool sortCardsAscending;
DECLARE_REFLECTION();
};
/// Settings for a Style
class StyleSettings {
public:
// Rendering/display settings
/* SimpleDefaultable<double> cardZoom = 1.0;
SimpleDefaultable<int> cardAngle = 0;
SimpleDefaultable<bool> cardAntiAlias = true;
SimpleDefaultable<bool> cardBorders = true;
SimpleDefaultable<bool> 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<String> 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<String,GameSettingsP> gameSettings;
map<String,StyleSettingsP> 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
//+----------------------------------------------------------------------------+
//| 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/stylesheet.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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 <util/prec.hpp>
#include <util/io/package.hpp>
DECLARE_POINTER_TYPE(Game);
// ----------------------------------------------------------------------------- : StyleSheet
/// A collection of style information for card and set fields
class StyleSheet : Packaged {
public:
GameP game;
private:
};
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -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;
}
......
//+----------------------------------------------------------------------------+
//| 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 <gui/set/panel.hpp>
// ----------------------------------------------------------------------------- : SetWindowPanel
SetWindowPanel::SetWindowPanel(Window* parent, int id, bool autoTabbing)
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, autoTabbing ? wxTAB_TRAVERSAL : 0)
{}
......@@ -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"));
......
......@@ -555,9 +555,6 @@
<File
RelativePath=".\data\card.hpp">
</File>
<File
RelativePath=".\data\card_style.hpp">
</File>
<File
RelativePath=".\data\field.cpp">
</File>
......@@ -585,6 +582,12 @@
<File
RelativePath=".\data\settings.hpp">
</File>
<File
RelativePath=".\data\stylesheet.cpp">
</File>
<File
RelativePath=".\data\stylesheet.hpp">
</File>
<File
RelativePath=".\data\symbol.cpp">
<FileConfiguration
......@@ -747,6 +750,9 @@
<File
RelativePath=".\util\vector2d.hpp">
</File>
<File
RelativePath=".\util\version.hpp">
</File>
<File
RelativePath=".\util\window_id.hpp">
</File>
......
......@@ -7,15 +7,15 @@
#ifndef HEADER_UTIL_ERROR
#define HEADER_UTIL_ERROR
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
/** @file util/error.hpp
*
* @brief Classes and functions for handling errors/exceptions.
*/
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- : Error types
/// Our own exception class
......
......@@ -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 <typename T>
shared_ptr<T> read_new(Reader& reader) {
return new_shared<T>();
}
template <typename T>
void Reader::handle(vector<T>& vector) {
String vectorKey = key;
......@@ -111,7 +120,7 @@ void Reader::handle(vector<T>& vector) {
template <typename T>
void Reader::handle(shared_ptr<T>& pointer) {
if (!pointer) pointer.reset(new T);
if (!pointer) pointer = read_new<T>(*this);
handle(*pointer);
}
......
......@@ -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 <util/prec.hpp>
......
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