Added 'export all card images' functionality

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@232 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-03-23 18:37:49 +00:00
parent 851799d1b6
commit 0f8f8a3334
13 changed files with 236 additions and 25 deletions
+19 -15
View File
@@ -12,27 +12,31 @@
// ----------------------------------------------------------------------------- : CardSelectWindow
CardSelectWindow::CardSelectWindow(Window* parent, const SetP& set, const String& label)
CardSelectWindow::CardSelectWindow(Window* parent, const SetP& set, const String& label, const String& title, bool sizer)
: wxDialog(parent, wxID_ANY, _TITLE_("select cards"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, set(set)
{
// init controls
list = new SelectCardList(this, wxID_ANY);
list->setSet(set);
wxButton* sel_all = new wxButton(this, ID_SELECT_ALL, _BUTTON_("select all"));
wxButton* sel_none = new wxButton(this, ID_SELECT_NONE, _BUTTON_("select none"));
sel_all = new wxButton(this, ID_SELECT_ALL, _BUTTON_("select all"));
sel_none = new wxButton(this, ID_SELECT_NONE, _BUTTON_("select none"));
// init sizers
wxSizer* s = new wxBoxSizer(wxVERTICAL);
s->Add(new wxStaticText(this, wxID_ANY, label), 0, wxALL & ~wxBOTTOM, 8);
s->Add(list, 1, wxEXPAND | wxALL, 8);
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
s2->Add(sel_all, 0, wxEXPAND | wxRIGHT, 8);
s2->Add(sel_none, 0, wxEXPAND | wxRIGHT, 8);
s2->Add(CreateButtonSizer(wxOK | wxCANCEL), 1, wxEXPAND, 8);
s->Add(s2, 0, wxEXPAND | wxALL & ~wxTOP, 8);
s->SetSizeHints(this);
SetSizer(s);
SetSize(500,500);
if (sizer) {
wxSizer* s = new wxBoxSizer(wxVERTICAL);
if (!label.empty()) {
s->Add(new wxStaticText(this, wxID_ANY, label), 0, wxALL & ~wxBOTTOM, 8);
}
s->Add(list, 1, wxEXPAND | wxALL, 8);
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
s2->Add(sel_all, 0, wxEXPAND | wxRIGHT, 8);
s2->Add(sel_none, 0, wxEXPAND | wxRIGHT, 8);
s2->Add(CreateButtonSizer(wxOK | wxCANCEL), 1, wxEXPAND, 8);
s->Add(s2, 0, wxEXPAND | wxALL & ~wxTOP, 8);
s->SetSizeHints(this);
SetSizer(s);
SetSize(500,500);
}
}
bool CardSelectWindow::isSelected(const CardP& card) const {
@@ -46,7 +50,7 @@ void CardSelectWindow::onSelectNone(wxCommandEvent&) {
list->selectNone();
}
BEGIN_EVENT_TABLE(CardSelectWindow,wxDialog)
BEGIN_EVENT_TABLE(CardSelectWindow, wxDialog)
EVT_BUTTON (ID_SELECT_ALL, CardSelectWindow::onSelectAll)
EVT_BUTTON (ID_SELECT_NONE, CardSelectWindow::onSelectNone)
END_EVENT_TABLE ()
+2 -1
View File
@@ -22,7 +22,7 @@ class SelectCardList;
*/
class CardSelectWindow : public wxDialog {
public:
CardSelectWindow(Window* parent, const SetP& set, const String& label);
CardSelectWindow(Window* parent, const SetP& set, const String& label, const String& title, bool sizer=true);
/// Is the given card selected?
bool isSelected(const CardP& card) const;
@@ -32,6 +32,7 @@ class CardSelectWindow : public wxDialog {
SelectCardList* list;
SetP set;
wxButton* sel_all, *sel_none;
void onSelectAll (wxCommandEvent&);
void onSelectNone(wxCommandEvent&);
+120
View File
@@ -0,0 +1,120 @@
//+----------------------------------------------------------------------------+
//| 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/images_export_window.hpp>
#include <gui/control/select_card_list.hpp>
#include <data/settings.hpp>
#include <data/set.hpp>
#include <data/format/formats.hpp>
#include <script/parser.hpp>
#include <script/context.hpp>
#include <util/tagged_string.hpp>
#include <wx/filename.h>
DECLARE_TYPEOF_COLLECTION(CardP);
// ----------------------------------------------------------------------------- : ImagesExportWindow
ImagesExportWindow::ImagesExportWindow(Window* parent, const SetP& set)
: CardSelectWindow(parent, set, wxEmptyString, _TITLE_("select cards export"), false)
{
// init controls
GameSettings& gs = settings.gameSettingsFor(*set->game);
format = new wxTextCtrl(this, wxID_ANY, gs.images_export_filename);
conflicts = new wxChoice (this, wxID_ANY);
conflicts->Append(_BUTTON_("keep old")); // 0
conflicts->Append(_BUTTON_("overwrite")); // 1
conflicts->Append(_BUTTON_("number")); // 2
conflicts->Append(_BUTTON_("number overwrite")); // 3
conflicts->SetSelection(gs.images_export_conflicts);
// init sizers
wxSizer* s = new wxBoxSizer(wxVERTICAL);
wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("export filenames"));
s2->Add(new wxStaticText(this, -1, _LABEL_("filename format")), 0, wxALL, 4);
s2->Add(format, 0, wxEXPAND | wxALL & ~wxTOP, 4);
s2->Add(new wxStaticText(this, -1, _HELP_("filename format")), 0, wxALL & ~wxTOP, 4);
s2->Add(new wxStaticText(this, -1, _LABEL_("filename conflicts")), 0, wxALL, 4);
s2->Add(conflicts, 0, wxEXPAND | wxALL & ~wxTOP, 4);
s->Add(s2, 0, wxEXPAND | wxALL, 8);
wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("cards to export"));
s3->Add(list, 1, wxEXPAND | wxALL, 4);
wxSizer* s4 = new wxBoxSizer(wxHORIZONTAL);
s4->Add(sel_all, 0, wxEXPAND | wxRIGHT, 4);
s4->Add(sel_none, 0, wxEXPAND, 4);
s3->Add(s4, 0, wxEXPAND | wxALL & ~wxTOP, 8);
s->Add(s3, 1, wxEXPAND | wxALL & ~wxTOP, 8);
s->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | wxALL & ~wxTOP, 8);
s->SetSizeHints(this);
SetSizer(s);
SetSize(500,500);
}
// ----------------------------------------------------------------------------- : Exporting the images
// filename.3.ext -> filename.4.ext
void inc_number_filename(String& filename) {
// TODO
throw "TODO";
}
void ImagesExportWindow::onOk(wxCommandEvent&) {
// Update settings
GameSettings& gs = settings.gameSettingsFor(*set->game);
gs.images_export_filename = format->GetValue();
int sel = conflicts->GetSelection();
if (sel == 0) gs.images_export_conflicts = CONFLICT_KEEP_OLD;
else if (sel == 1) gs.images_export_conflicts = CONFLICT_OVERWRITE;
else if (sel == 2) gs.images_export_conflicts = CONFLICT_NUMBER;
else gs.images_export_conflicts = CONFLICT_NUMBER_OVERWRITE;
// Script
ScriptP filename_script = parse(gs.images_export_filename, true);
// Select filename
String name = wxFileSelector(_TITLE_("export images"),_(""), _LABEL_("filename is ignored"),_(""),
_LABEL_("all files")+_("|*.*"), wxSAVE, this);
if (name.empty()) return;
wxFileName fn(name);
// Export
std::set<String> used; // for CONFLICT_NUMBER_OVERWRITE
FOR_EACH(card, set->cards) {
if (isSelected(card)) {
// filename for this card
Context& ctx = set->getContext(card);
String filename = untag(ctx.eval(*filename_script)->toString());
if (!filename) continue; // no filename -> no saving
fn.SetName(filename);
filename = fn.GetFullPath();
if (wxFileExists(filename)) {
// file exists, what to do?
switch (gs.images_export_conflicts) {
case CONFLICT_KEEP_OLD: goto next_card;
case CONFLICT_OVERWRITE: break;
case CONFLICT_NUMBER: {
do {
inc_number_filename(filename);
} while(wxFileExists(filename));
}
case CONFLICT_NUMBER_OVERWRITE: {
while(used.find(filename) != used.end()) {
inc_number_filename(filename);
}
}
}
}
used.insert(filename);
export_image(set, card, filename);
}
next_card:;
}
// Done
EndModal(wxID_OK);
}
BEGIN_EVENT_TABLE(ImagesExportWindow,CardSelectWindow)
EVT_BUTTON (wxID_OK, ImagesExportWindow::onOk)
END_EVENT_TABLE ()
+32
View File
@@ -0,0 +1,32 @@
//+----------------------------------------------------------------------------+
//| 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_IMAGES_EXPORT_WINDOW
#define HEADER_GUI_IMAGES_EXPORT_WINDOW
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/card_select_window.hpp>
// ----------------------------------------------------------------------------- : ImagesExportWindow
/// A window for selecting a subset of the cards from a set to export to images
class ImagesExportWindow : public CardSelectWindow {
public:
ImagesExportWindow(Window* parent, const SetP& set);
private:
DECLARE_EVENT_TABLE();
void onOk(wxCommandEvent&);
wxTextCtrl* format;
wxChoice* conflicts;
};
// ----------------------------------------------------------------------------- : EOF
#endif
+2 -2
View File
@@ -94,7 +94,7 @@ void TextBufferDC::drawToDevice(DC& dc, int x, int y) {
void print_preview(Window* parent, const SetP& set) {
// Let the user choose cards
CardSelectWindow wnd(parent, set, _LABEL_("select cards print"));
CardSelectWindow wnd(parent, set, _LABEL_("select cards print"), _TITLE_("select cards"));
if (wnd.ShowModal() != wxID_OK) {
return; // cancel
}
@@ -116,7 +116,7 @@ void print_preview(Window* parent, const SetP& set) {
void print_set(Window* parent, const SetP& set) {
// Let the user choose cards
CardSelectWindow wnd(parent, set, _LABEL_("select cards print"));
CardSelectWindow wnd(parent, set, _LABEL_("select cards print"), _TITLE_("select cards"));
if (wnd.ShowModal() != wxID_OK) {
return; // cancel
}
+2
View File
@@ -13,6 +13,7 @@
#include <gui/set/panel.hpp>
class KeywordList;
class TextCtrl;
// ----------------------------------------------------------------------------- : KeywordsPanel
@@ -25,6 +26,7 @@ class KeywordsPanel : public SetWindowPanel {
private:
KeywordList* list;
TextCtrl* keyword;
};
// ----------------------------------------------------------------------------- : EOF
+3 -1
View File
@@ -21,6 +21,7 @@
#include <gui/new_window.hpp>
#include <gui/preferences_window.hpp>
#include <gui/print_window.hpp>
#include <gui/images_export_window.hpp>
#include <gui/icon_menu.hpp>
#include <gui/util.hpp>
#include <util/window_id.hpp>
@@ -437,7 +438,8 @@ void SetWindow::onFileExportImage(wxCommandEvent&) {
}
void SetWindow::onFileExportImages(wxCommandEvent&) {
// exportImages(this, set);
ImagesExportWindow wnd(this, set);
wnd.ShowModal();
}
void SetWindow::onFileExportHTML(wxCommandEvent&) {