Commit 9ca309c6 authored by twanvl's avatar twanvl

settings get read&written

parent f3924ec8
......@@ -7,9 +7,21 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/game.hpp>
#include <util/io/package_manager.hpp>
// ----------------------------------------------------------------------------- : Game
GameP Game::byName(const String& name) {
return packages.open<Game>(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
......@@ -12,9 +12,8 @@
#include <util/prec.hpp>
#include <util/io/package.hpp>
#ifndef HEADER_DATA_CARD
DECLARE_POINTER_TYPE(Field);
#endif
DECLARE_POINTER_TYPE(Game);
// ----------------------------------------------------------------------------- : Game
......@@ -25,8 +24,16 @@ class Game : public Packaged {
vector<FieldP> setFields;
vector<FieldP> 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
......
......@@ -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() {}
......
......@@ -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();
};
......
......@@ -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() {}
......
......@@ -9,3 +9,7 @@
#include <gui/set/stats_panel.hpp>
// ----------------------------------------------------------------------------- : StatsPanel
StatsPanel::StatsPanel(Window* parent, int id)
: SetWindowPanel(parent, id)
{}
......@@ -14,6 +14,12 @@
// ----------------------------------------------------------------------------- : StatsPanel
class StatsPanel : public SetWindowPanel {
public:
StatsPanel(Window* parent, int id);
};
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -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();
}
......
......@@ -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
......
......@@ -6,7 +6,12 @@
// ----------------------------------------------------------------------------- : Includes
#include "util/prec.hpp"
#include <util/prec.hpp>
#include <data/game.hpp>
#include <data/set.hpp>
#include <data/settings.hpp>
#include <data/format/formats.hpp>
#include <gui/set/window.hpp>
#include <gui/symbol/window.hpp>
// ----------------------------------------------------------------------------- : 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<Set>(Game::byName(_("magic"))));
wnd->Show();
return true;
}
......@@ -39,7 +46,7 @@ bool MSE::OnInit() {
// ----------------------------------------------------------------------------- : Exit
int MSE::OnExit() {
// settings.write();
settings.write();
return 0;
}
......
......@@ -328,6 +328,9 @@
<File
RelativePath=".\gui\set\cards_panel.hpp">
</File>
<File
RelativePath=".\gui\set\panel.cpp">
</File>
<File
RelativePath=".\gui\set\panel.hpp">
</File>
......@@ -768,6 +771,12 @@
<File
RelativePath=".\util\io\package.hpp">
</File>
<File
RelativePath=".\util\io\package_manager.cpp">
</File>
<File
RelativePath=".\util\io\package_manager.hpp">
</File>
<File
RelativePath=".\util\io\reader.cpp">
<FileConfiguration
......
......@@ -111,6 +111,11 @@ template <> 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);
}
......
......@@ -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);
}
......
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