mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
start with implementing fields
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@12 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
+32
-2
@@ -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
|
||||
|
||||
void initObject(const FieldP& field, ValueP& value) {
|
||||
value = new_shared<Value>();
|
||||
IMPLEMENT_REFLECTION(Value) {
|
||||
}
|
||||
|
||||
void initObject(const FieldP& field, ValueP& value) {
|
||||
value = field->newValue(field);
|
||||
}
|
||||
|
||||
|
||||
+60
-3
@@ -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&);
|
||||
|
||||
+16
-2
@@ -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();
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class Game : public Packaged {
|
||||
|
||||
protected:
|
||||
String typeName() const;
|
||||
void validate();
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
@@ -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 <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);
|
||||
}
|
||||
@@ -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 <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
|
||||
@@ -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 <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 <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
|
||||
Reference in New Issue
Block a user