mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implemented NewSetWindow, added events to GalleryList
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@48 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+7
-1
@@ -8,17 +8,23 @@
|
||||
|
||||
#include <data/set.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <script/value.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Set
|
||||
|
||||
Set::Set() {}
|
||||
|
||||
Set::Set(const GameP& game)
|
||||
: game(game)
|
||||
{}
|
||||
|
||||
Set::Set() {}
|
||||
Set::Set(const StyleSheetP& stylesheet)
|
||||
: stylesheet(stylesheet)
|
||||
, game(stylesheet->game)
|
||||
{}
|
||||
|
||||
String Set::typeName() const { return _("set"); }
|
||||
|
||||
|
||||
+4
-2
@@ -17,7 +17,7 @@
|
||||
DECLARE_POINTER_TYPE(Card);
|
||||
DECLARE_POINTER_TYPE(Set);
|
||||
DECLARE_POINTER_TYPE(Game);
|
||||
DECLARE_POINTER_TYPE(Stylesheet);
|
||||
DECLARE_POINTER_TYPE(StyleSheet);
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
DECLARE_POINTER_TYPE(Value);
|
||||
|
||||
@@ -30,11 +30,13 @@ class Set : public Packaged {
|
||||
Set();
|
||||
/// Create a set using the given game
|
||||
Set(const GameP& game);
|
||||
/// Create a set using the given stylesheet, and its game
|
||||
Set(const StyleSheetP& stylesheet);
|
||||
|
||||
/// The game this set uses
|
||||
GameP game;
|
||||
/// The default stylesheet
|
||||
StylesheetP stylesheet;
|
||||
StyleSheetP stylesheet;
|
||||
/// The values on the fields of the set
|
||||
/** The indices should correspond to the set_fields in the Game */
|
||||
IndexMap<FieldP, ValueP> data;
|
||||
|
||||
@@ -37,7 +37,7 @@ IMPLEMENT_REFLECTION(ColumnSettings) {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(GameSettings) {
|
||||
REFLECT(default_style);
|
||||
REFLECT(default_stylesheet);
|
||||
REFLECT(default_export);
|
||||
// REFLECT_N("cardlist columns", columns);
|
||||
REFLECT(sort_cards_by);
|
||||
|
||||
@@ -43,7 +43,7 @@ class ColumnSettings {
|
||||
/// Settings for a Game
|
||||
class GameSettings {
|
||||
public:
|
||||
String default_style;
|
||||
String default_stylesheet;
|
||||
String default_export;
|
||||
map<String, ColumnSettings> columns;
|
||||
String sort_cards_by;
|
||||
|
||||
@@ -8,4 +8,7 @@
|
||||
|
||||
#include <data/stylesheet.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
// ----------------------------------------------------------------------------- : StyleSheet
|
||||
|
||||
String StyleSheet::typeNameStatic() { return _("style"); }
|
||||
String StyleSheet::typeName() const { return _("style"); }
|
||||
|
||||
@@ -17,10 +17,17 @@ DECLARE_POINTER_TYPE(Game);
|
||||
// ----------------------------------------------------------------------------- : StyleSheet
|
||||
|
||||
/// A collection of style information for card and set fields
|
||||
class StyleSheet : Packaged {
|
||||
class StyleSheet : public Packaged {
|
||||
public:
|
||||
GameP game;
|
||||
|
||||
static String typeNameStatic();
|
||||
virtual String typeName() const;
|
||||
virtual String fullName() const;
|
||||
virtual InputStreamP openIconFile();
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -18,9 +18,9 @@ DECLARE_POINTER_TYPE(Field);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>);
|
||||
DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>)
|
||||
/// Handle CardSelectEvents
|
||||
#define EVT_CARD_SELECT(id, handler) EVT_COMMAND(id, EVENT_CARD_SELECT, handler);
|
||||
#define EVT_CARD_SELECT(id, handler) EVT_COMMAND(id, EVENT_CARD_SELECT, handler)
|
||||
|
||||
/// The event of selecting a card
|
||||
struct CardSelectEvent : public wxCommandEvent {
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
DEFINE_EVENT_TYPE(EVENT_GALLERY_SELECT);
|
||||
DEFINE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE);
|
||||
|
||||
// ----------------------------------------------------------------------------- : GalleryList
|
||||
|
||||
const int MARGIN = 2; // margin around items
|
||||
@@ -77,12 +82,12 @@ void GalleryList::onLeftDown(wxMouseEvent& ev) {
|
||||
if (item != selection && item < itemCount()) {
|
||||
selection = item;
|
||||
update();
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
}
|
||||
}
|
||||
|
||||
void GalleryList::onLeftDClick(wxMouseEvent& ev) {
|
||||
// activate an item
|
||||
// TODO
|
||||
sendEvent(EVENT_GALLERY_ACTIVATE);
|
||||
}
|
||||
|
||||
void GalleryList::onKeyDown(wxKeyEvent& ev) {
|
||||
@@ -160,6 +165,11 @@ void GalleryList::OnDraw(DC& dc) {
|
||||
}
|
||||
}
|
||||
|
||||
void GalleryList::sendEvent(WXTYPE type) {
|
||||
wxCommandEvent ev(type, GetId());
|
||||
ProcessEvent(ev);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
BEGIN_EVENT_TABLE(GalleryList, wxScrolledWindow)
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
DECLARE_EVENT_TYPE(EVENT_GALLERY_SELECT, <not used>)
|
||||
DECLARE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE, <not used>)
|
||||
|
||||
/// Handle EVENT_GALLERY_SELECT events
|
||||
#define EVT_GALLERY_SELECT( id, handler) EVT_COMMAND(id, EVENT_GALLERY_SELECT, handler)
|
||||
/// Handle EVENT_GALLERY_ACTIVATE events
|
||||
#define EVT_GALLERY_ACTIVATE(id, handler) EVT_COMMAND(id, EVENT_GALLERY_ACTIVATE, handler)
|
||||
|
||||
// ----------------------------------------------------------------------------- : GalleryList
|
||||
|
||||
/// A list of items with custom drawing
|
||||
@@ -47,6 +57,8 @@ class GalleryList : public wxScrolledWindow {
|
||||
|
||||
/// Find the item corresponding to the given location
|
||||
size_t findItem(const wxMouseEvent&);
|
||||
/// Send an event
|
||||
void sendEvent(WXTYPE type);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -76,3 +76,21 @@ void PackageList::showData(const String& pattern) {
|
||||
// update list
|
||||
update();
|
||||
}
|
||||
|
||||
void PackageList::clear() {
|
||||
packages.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void PackageList::select(const String& name) {
|
||||
for (vector<PackageData>::const_iterator it = packages.begin() ; it != packages.end() ; ++it) {
|
||||
if (it->package->name() == name) {
|
||||
selection = it - packages.begin();
|
||||
update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
selection = NO_SELECTION;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,10 @@ class PackageList : public GalleryList {
|
||||
/// Shows packages that match a specific patern
|
||||
void showData(const String& pattern = _("*.*"));
|
||||
|
||||
// Is there a package selected?
|
||||
/// Clears this list
|
||||
void clear();
|
||||
|
||||
/// Is there a package selected?
|
||||
inline bool hasSelection() const { return selection < itemCount(); }
|
||||
|
||||
/// Get the selected package, T should be the same type used for showData
|
||||
@@ -43,6 +46,9 @@ class PackageList : public GalleryList {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Select the package with the given name, if it is not found, selects nothing
|
||||
void select(const String& name);
|
||||
|
||||
protected:
|
||||
/// Return how many items there are in the list
|
||||
virtual size_t itemCount() const;
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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/new_window.hpp>
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <gui/control/package_list.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : NewSetWindow
|
||||
|
||||
SetP new_set_window(Window* parent) {
|
||||
NewSetWindow wnd(parent);
|
||||
wnd.ShowModal();
|
||||
return wnd.set;
|
||||
}
|
||||
|
||||
NewSetWindow::NewSetWindow(Window* parent)
|
||||
: wxDialog(parent, wxID_ANY, _("New set"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
{
|
||||
// init controls
|
||||
game_list = new PackageList (this, ID_GAME_LIST);
|
||||
stylesheet_list = new PackageList (this, ID_STYLESHEET_LIST);
|
||||
game_text = new wxStaticText(this, wxID_ANY, _("&Game type:"));
|
||||
stylesheet_text = new wxStaticText(this, wxID_ANY, _("&Card style:"));
|
||||
// init sizer
|
||||
wxSizer* s = new wxBoxSizer(wxVERTICAL);
|
||||
s->Add(game_text, 0, wxALL, 4);
|
||||
s->Add(game_list, 1, wxEXPAND | wxALL & ~wxTOP, 4);
|
||||
s->Add(stylesheet_text, 0, wxALL, 4);
|
||||
s->Add(stylesheet_list, 1, wxEXPAND | wxALL & ~wxTOP, 4);
|
||||
s->Add(CreateButtonSizer(wxOK | wxCANCEL) , 0, wxEXPAND | wxALL, 8);
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
// disable stuff
|
||||
ok_button = FindWindow(wxID_OK);
|
||||
assert(ok_button);
|
||||
enableStyle(false);
|
||||
// force refresh of gameList, otherwise a grey background shows (win XP)
|
||||
SetSize(wxSize(530,320));
|
||||
// init lists
|
||||
game_list->showData<Game>();
|
||||
game_list->select(settings.default_game);
|
||||
}
|
||||
|
||||
void NewSetWindow::enableStyle(bool e) {
|
||||
stylesheet_list->Enable(e);
|
||||
stylesheet_text->Enable(e);
|
||||
if (!e) enableOk(e);
|
||||
}
|
||||
void NewSetWindow::enableOk(bool e) {
|
||||
ok_button->Enable(e);
|
||||
}
|
||||
|
||||
void NewSetWindow::onGameSelect(wxCommandEvent&) {
|
||||
GameP game = game_list->getSelection<Game>();
|
||||
settings.default_game = game->name();
|
||||
GameSettings& gs = settings.gameSettingsFor(*game);
|
||||
stylesheet_list->showData<StyleSheet>(game->name() + _("-*"));
|
||||
stylesheet_list->select(gs.default_stylesheet);
|
||||
enableStyle(true);
|
||||
}
|
||||
/*void NewSetWindow::onGameDeselect(wxCommandEvent&) {
|
||||
stylesheet_list->clear();
|
||||
enableStyle(false);
|
||||
}
|
||||
*/
|
||||
void NewSetWindow::onStyleSheetSelect(wxCommandEvent&) {
|
||||
enableOk(true);
|
||||
// store this as default selection
|
||||
GameP game = game_list ->getSelection<Game>();
|
||||
StyleSheetP stylesheet = stylesheet_list->getSelection<StyleSheet>();
|
||||
GameSettings& gs = settings.gameSettingsFor(*game);
|
||||
gs.default_stylesheet = stylesheet->name();
|
||||
}
|
||||
/*void NewSetWindow::onStyleSheetDeselect(wxCommandEvent&) {
|
||||
enableOk(false);
|
||||
}
|
||||
*/
|
||||
void NewSetWindow::onStyleSheetActivate(wxCommandEvent&) {
|
||||
done();
|
||||
}
|
||||
|
||||
void NewSetWindow::OnOK(wxCommandEvent&) {
|
||||
done();
|
||||
}
|
||||
|
||||
void NewSetWindow::done() {
|
||||
StyleSheetP stylesheet = stylesheet_list->getSelection<StyleSheet>();
|
||||
set = new_shared1<Set>(stylesheet);
|
||||
set->cards.push_back(new_shared1<Card>(*set->game));
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(NewSetWindow, wxDialog)
|
||||
EVT_GALLERY_SELECT (ID_GAME_LIST, NewSetWindow::onGameSelect)
|
||||
// EVT_LIST_ITEM_DESELECTED (ID_GAME_LIST, NewSetWindow::onGameDeselect)
|
||||
EVT_GALLERY_SELECT (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect)
|
||||
// EVT_LIST_ITEM_DESELECTED (ID_STYLESHEET_LIST, NewSetWindow::onStyleDeselect)
|
||||
EVT_GALLERY_ACTIVATE (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate)
|
||||
END_EVENT_TABLE ()
|
||||
@@ -0,0 +1,60 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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_GUI_NEW_WINDOW
|
||||
#define HEADER_GUI_NEW_WINDOW
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
|
||||
class PackageList;
|
||||
DECLARE_POINTER_TYPE(Set);
|
||||
|
||||
// ----------------------------------------------------------------------------- : NewSetWindow
|
||||
|
||||
/// Show the new set window, return the new set, if any
|
||||
SetP new_set_window(Window* parent);
|
||||
|
||||
/// "Create a new set" dialog. First select game, then matching style.
|
||||
class NewSetWindow : public wxDialog {
|
||||
public:
|
||||
/// The newly created set, if any
|
||||
SetP set;
|
||||
|
||||
NewSetWindow(Window* parent);
|
||||
|
||||
// --------------------------------------------------- : data
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
// gui items
|
||||
PackageList* game_list, *stylesheet_list;
|
||||
wxStaticText* game_text, *stylesheet_text;
|
||||
Window* ok_button;
|
||||
|
||||
// --------------------------------------------------- : enabling stuff
|
||||
|
||||
void enableStyle(bool e);
|
||||
void enableOk (bool e);
|
||||
|
||||
// --------------------------------------------------- : events
|
||||
|
||||
void onGameSelect (wxCommandEvent&);
|
||||
// void onGameDeselect(wxCommandEvent&);
|
||||
|
||||
void onStyleSheetSelect (wxCommandEvent&);
|
||||
// void onStyleSheetDeselect(wxCommandEvent&);
|
||||
void onStyleSheetActivate(wxCommandEvent&);
|
||||
|
||||
virtual void OnOK(wxCommandEvent&);
|
||||
|
||||
// we are done, close the window
|
||||
void done();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -366,10 +366,9 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
|
||||
void SetWindow::onFileNew(wxCommandEvent&) {
|
||||
if (!askSaveAndContinue()) return;
|
||||
// NewWindow wnd(this);
|
||||
// wnd.showModal();
|
||||
// associate new set
|
||||
// if (wnd.set) set = wnd.set;
|
||||
// new set?
|
||||
SetP new_set = new_set_window(this);
|
||||
if (new_set) set = new_set;
|
||||
}
|
||||
|
||||
void SetWindow::onFileOpen(wxCommandEvent&) {
|
||||
@@ -451,7 +450,7 @@ void SetWindow::onFilePrintPreview(wxCommandEvent&) {
|
||||
}
|
||||
|
||||
void SetWindow::onFileRecent(wxCommandEvent& ev) {
|
||||
// setSet(importSet(settings.recentSets.at(ev.GetId() - ID_FILE_RECENT)));
|
||||
// setSet(import_set(settings.recentSets.at(ev.GetId() - ID_FILE_RECENT)));
|
||||
}
|
||||
|
||||
void SetWindow::onFileExit(wxCommandEvent&) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <gui/welcome_window.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <gui/new_window.hpp>
|
||||
#include <gui/set/window.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <data/settings.hpp>
|
||||
@@ -70,11 +71,7 @@ void WelcomeWindow::onOpenSet(wxCommandEvent&) {
|
||||
}
|
||||
|
||||
void WelcomeWindow::onNewSet(wxCommandEvent&) {
|
||||
// NewWindow wnd(0);
|
||||
// wnd.ShowModal();
|
||||
// if (wnd.set) {
|
||||
// close(wnd.getSet());
|
||||
// }
|
||||
close(new_set_window(this));
|
||||
}
|
||||
|
||||
// MOVEME
|
||||
|
||||
+5
-3
@@ -12,6 +12,7 @@
|
||||
#include <data/set.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <data/format/formats.hpp>
|
||||
#include <gui/welcome_window.hpp>
|
||||
#include <gui/set/window.hpp>
|
||||
#include <gui/symbol/window.hpp>
|
||||
|
||||
@@ -41,9 +42,10 @@ bool MSE::OnInit() {
|
||||
settings.read();
|
||||
//Window* wnd = new SymbolWindow(nullptr);
|
||||
//GameP g = Game::byName(_("magic"))
|
||||
SetP s = new_shared<Set>();
|
||||
s->open(_("test.mse-set"));
|
||||
Window* wnd = new SetWindow(nullptr, s);
|
||||
//SetP s = new_shared<Set>();
|
||||
//s->open(_("test.mse-set"));
|
||||
//Window* wnd = new SetWindow(nullptr, s);
|
||||
Window* wnd = new WelcomeWindow();
|
||||
wnd->Show();
|
||||
return true;
|
||||
|
||||
|
||||
@@ -155,6 +155,8 @@ enum ControlID {
|
||||
, ID_TAB_BAR
|
||||
, ID_CARD_LIST
|
||||
, ID_PART_LIST
|
||||
, ID_GAME_LIST
|
||||
, ID_STYLESHEET_LIST
|
||||
, ID_NOTES
|
||||
, ID_KEYWORD
|
||||
, ID_PARAMETER
|
||||
|
||||
Reference in New Issue
Block a user