diff --git a/src/data/game.cpp b/src/data/game.cpp index dd5d169a..df810319 100644 --- a/src/data/game.cpp +++ b/src/data/game.cpp @@ -7,9 +7,21 @@ // ----------------------------------------------------------------------------- : Includes #include +#include // ----------------------------------------------------------------------------- : Game +GameP Game::byName(const String& name) { + return packages.open(name + _(".mse-game")); +} + bool Game::isMagic() const { return name() == _("magic"); +} + +String Game::typeName() const { return _("game"); } + +IMPLEMENT_REFLECTION(Game) { + REFLECT_N("full name", fullName); + REFLECT_N("icon", iconFilename); } \ No newline at end of file diff --git a/src/data/game.hpp b/src/data/game.hpp index e173f7ce..b094ad28 100644 --- a/src/data/game.hpp +++ b/src/data/game.hpp @@ -12,9 +12,8 @@ #include #include -#ifndef HEADER_DATA_CARD DECLARE_POINTER_TYPE(Field); -#endif +DECLARE_POINTER_TYPE(Game); // ----------------------------------------------------------------------------- : Game @@ -25,8 +24,16 @@ class Game : public Packaged { vector setFields; vector cardFields; - // Is this Magic the Gathering? + /// Loads the game with a particular name, for example "magic" + static GameP byName(const String& name); + + /// Is this Magic the Gathering? bool isMagic() const; + + protected: + String typeName() const; + + DECLARE_REFLECTION(); }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/data/set.cpp b/src/data/set.cpp index 643807f0..d7ab1ceb 100644 --- a/src/data/set.cpp +++ b/src/data/set.cpp @@ -11,12 +11,21 @@ // ----------------------------------------------------------------------------- : Set +Set::Set(const GameP& game) + : game(game) +{} + +Set::Set() {} + +String Set::typeName() const { return _("set"); } + IMPLEMENT_REFLECTION(Set) { WITH_DYNAMIC_ARG(game_for_new_cards, game.get()) { REFLECT_N("card", cards); } } + // ----------------------------------------------------------------------------- : SetView SetView::SetView() {} diff --git a/src/data/set.hpp b/src/data/set.hpp index c5c02ee5..ce361e37 100644 --- a/src/data/set.hpp +++ b/src/data/set.hpp @@ -23,6 +23,9 @@ DECLARE_POINTER_TYPE(Game); /// A set of cards class Set : public Packaged { public: + /// Create a set using the given game + Set(const GameP& game); + /// The game this set uses GameP game; /// The cards in the set @@ -30,6 +33,12 @@ class Set : public Packaged { /// Actions performed on this set and the cards in it ActionStack actions; + protected: + String typeName() const; + + // default constructor accessible to Reader + Set(); + DECLARE_REFLECTION(); }; diff --git a/src/gui/set/panel.hpp b/src/gui/set/panel.hpp index 5021f281..1c700f4a 100644 --- a/src/gui/set/panel.hpp +++ b/src/gui/set/panel.hpp @@ -24,7 +24,7 @@ class SetWindowPanel : public wxPanel, public SetView { SetWindowPanel(Window* parent, int id, bool autoTabbing = false); /// We will probably want to respond to set changes - virtual void onSetChange(); + virtual void onSetChange() {} // --------------------------------------------------- : Meta information @@ -50,6 +50,8 @@ class SetWindowPanel : public wxPanel, public SetView { /// Should return true if this panel wants to get focus to show an action virtual bool wantsToHandle(const Action&) { return false; } + /// Handle an action that changes the current set + virtual void onAction(const Action&) {} /// The settings for rendering cards have changed, refresh card viewers/editors virtual void onRenderSettingsChange() {} diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index 2271ac8e..23f60e01 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -9,3 +9,7 @@ #include // ----------------------------------------------------------------------------- : StatsPanel + +StatsPanel::StatsPanel(Window* parent, int id) + : SetWindowPanel(parent, id) +{} diff --git a/src/gui/set/stats_panel.hpp b/src/gui/set/stats_panel.hpp index dbf695c4..e9d66b64 100644 --- a/src/gui/set/stats_panel.hpp +++ b/src/gui/set/stats_panel.hpp @@ -14,6 +14,12 @@ // ----------------------------------------------------------------------------- : StatsPanel +class StatsPanel : public SetWindowPanel { + public: + StatsPanel(Window* parent, int id); + + +}; // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 1dea7a61..4b77e9c9 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -24,7 +24,7 @@ DECLARE_TYPEOF_COLLECTION(SetWindowPanel*); // ----------------------------------------------------------------------------- : Constructor -SetWindow::SetWindow(Window* parent) +SetWindow::SetWindow(Window* parent, const SetP& set) : wxFrame(parent, wxID_ANY, _("Magic Set Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) , currentPanel(nullptr) , findDialog(nullptr) @@ -120,13 +120,16 @@ SetWindow::SetWindow(Window* parent) // addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 3, _("F9")); //addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10")) // selectPanel(idWindowMin + 4); // select cards panel + + addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 0, _("F9")); + selectPanel(ID_WINDOW_MIN); // test // loose ends tabBar->Realize(); -// setSize(settings.SetWindowWidth, settings.SetWindowHeight); -// if (settings.SetWindowMaximized) { -// maximize(); -// } + SetSize(settings.setWindowWidth, settings.setWindowHeight); + if (settings.setWindowMaximized) { + Maximize(); + } // SetWindows.push_back(&this); // register this window // timer.owner = &this; // timer.start(10); @@ -134,20 +137,22 @@ SetWindow::SetWindow(Window* parent) // note: this still sends events for menu and toolbar items! wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); + + setSet(set); } SetWindow::~SetWindow() { // store window size in settings -// wxSize s = getSize(); -// settings.SetWindowMaximized = isMaximized(); -// if (!isMaximized()) { -// settings.SetWindowWidth = s.GetWidth(); -// settings.SetWindowHeight = s.GetHeight(); -// } -// // destroy ui of selected panel -// currentPanel->destroyUI(GetToolBar(), GetMenuBar()); + wxSize s = GetSize(); + settings.setWindowMaximized = IsMaximized(); + if (!IsMaximized()) { + settings.setWindowWidth = s.GetWidth(); + settings.setWindowHeight = s.GetHeight(); + } + // destroy ui of selected panel + currentPanel->destroyUI(GetToolBar(), GetMenuBar()); // cleanup (see find stuff) -// delete findDialog; + delete findDialog; // remove from list of main windows // SetWindows.erase(remove(SetWindows.begin(), SetWindows.end(), &this)); // stop updating @@ -511,8 +516,7 @@ void SetWindow::onEditPreferences(wxCommandEvent&) { // ----------------------------------------------------------------------------- : Window events - menu - window void SetWindow::onWindowNewWindow(wxCommandEvent&) { - SetWindow* newWindow = new SetWindow(nullptr); - newWindow->setSet(set); + SetWindow* newWindow = new SetWindow(nullptr, set); newWindow->Show(); } diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index 186aef69..070fe92d 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -25,7 +25,7 @@ class wxFindDialogEvent; class SetWindow : public wxFrame, public SetView { public: /// Construct a SetWindow - SetWindow(Window* parent); + SetWindow(Window* parent, const SetP& set); ~SetWindow(); // --------------------------------------------------- : Set actions diff --git a/src/main.cpp b/src/main.cpp index dd4fcd9d..980c7d5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,12 @@ // ----------------------------------------------------------------------------- : Includes -#include "util/prec.hpp" +#include +#include +#include +#include +#include +#include #include // ----------------------------------------------------------------------------- : Main function/class @@ -30,8 +35,10 @@ IMPLEMENT_APP(MSE) bool MSE::OnInit() { wxInitAllImageHandlers(); - //initFileFilters() - Window* wnd = new SymbolWindow(0); + initFileFormats(); + settings.read(); + //Window* wnd = new SymbolWindow(nullptr); + Window* wnd = new SetWindow(nullptr, new_shared1(Game::byName(_("magic")))); wnd->Show(); return true; } @@ -39,7 +46,7 @@ bool MSE::OnInit() { // ----------------------------------------------------------------------------- : Exit int MSE::OnExit() { -// settings.write(); + settings.write(); return 0; } diff --git a/src/mse.vcproj b/src/mse.vcproj index ecc3f428..16496345 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -328,6 +328,9 @@ + + @@ -768,6 +771,12 @@ + + + + void Reader::handle(int& i) { value.ToLong(&l); i = l; } +template <> void Reader::handle(unsigned int& i) { + long l = 0; + value.ToLong(&l); + i = abs(l); // abs, because it will seem strange if -1 comes out as MAX_INT +} template <> void Reader::handle(double& d) { value.ToDouble(&d); } diff --git a/src/util/io/writer.cpp b/src/util/io/writer.cpp index 13a5d7a7..0508c16d 100644 --- a/src/util/io/writer.cpp +++ b/src/util/io/writer.cpp @@ -92,6 +92,9 @@ void Writer::handle(const String& value) { template <> void Writer::handle(const int& value) { handle(String() << value); } +template <> void Writer::handle(const unsigned int& value) { + handle(String() << value); +} template <> void Writer::handle(const double& value) { handle(String() << value); }