mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
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:
@@ -26,6 +26,13 @@ IMPLEMENT_REFLECTION_ENUM(CheckUpdates) {
|
||||
VALUE_N("never", CHECK_NEVER);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(FilenameConflicts) {
|
||||
VALUE_N("keep old", CONFLICT_KEEP_OLD);
|
||||
VALUE_N("overwrite", CONFLICT_OVERWRITE);
|
||||
VALUE_N("number", CONFLICT_NUMBER);
|
||||
VALUE_N("number overwrite", CONFLICT_NUMBER_OVERWRITE);
|
||||
}
|
||||
|
||||
const int COLUMN_NOT_INITIALIZED = -100000;
|
||||
|
||||
ColumnSettings::ColumnSettings()
|
||||
@@ -43,6 +50,8 @@ IMPLEMENT_REFLECTION(ColumnSettings) {
|
||||
|
||||
GameSettings::GameSettings()
|
||||
: sort_cards_ascending(true)
|
||||
, images_export_filename(_("{card.name}.jpg"))
|
||||
, images_export_conflicts(CONFLICT_NUMBER_OVERWRITE)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION(GameSettings) {
|
||||
@@ -51,6 +60,8 @@ IMPLEMENT_REFLECTION(GameSettings) {
|
||||
REFLECT_N("cardlist columns", columns);
|
||||
REFLECT(sort_cards_by);
|
||||
REFLECT(sort_cards_ascending);
|
||||
REFLECT(images_export_filename);
|
||||
REFLECT(images_export_conflicts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,14 @@ enum CheckUpdates
|
||||
, CHECK_NEVER
|
||||
};
|
||||
|
||||
/// How to handle filename conflicts
|
||||
enum FilenameConflicts
|
||||
{ CONFLICT_KEEP_OLD // always keep old file
|
||||
, CONFLICT_OVERWRITE // always overwrite
|
||||
, CONFLICT_NUMBER // always add numbers ("file.1.something")
|
||||
, CONFLICT_NUMBER_OVERWRITE // only add numbers for conflicts inside a set, overwrite old stuff
|
||||
};
|
||||
|
||||
/// Settings of a single column in the card list
|
||||
class ColumnSettings {
|
||||
public:
|
||||
@@ -50,6 +58,8 @@ class GameSettings {
|
||||
map<String, ColumnSettings> columns;
|
||||
String sort_cards_by;
|
||||
bool sort_cards_ascending;
|
||||
String images_export_filename;
|
||||
FilenameConflicts images_export_conflicts;
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
@@ -57,8 +57,9 @@ StatsCategory::StatsCategory(const StatsDimensionP& dim)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(GraphType) {
|
||||
VALUE_N("bar", GRAPH_TYPE_BAR);
|
||||
VALUE_N("pie", GRAPH_TYPE_PIE);
|
||||
VALUE_N("bar", GRAPH_TYPE_BAR);
|
||||
VALUE_N("pie", GRAPH_TYPE_PIE);
|
||||
VALUE_N("scatter", GRAPH_TYPE_SCATTER);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(StatsCategory) {
|
||||
|
||||
@@ -42,6 +42,7 @@ class StatsDimension {
|
||||
enum GraphType
|
||||
{ GRAPH_TYPE_BAR
|
||||
, GRAPH_TYPE_PIE
|
||||
, GRAPH_TYPE_SCATTER
|
||||
};
|
||||
|
||||
/// A category for statistics
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
@@ -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&);
|
||||
|
||||
@@ -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 ()
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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&) {
|
||||
|
||||
+8
-2
@@ -881,6 +881,12 @@
|
||||
<File
|
||||
RelativePath=".\gui\image_slice_window.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gui\images_export_window.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gui\images_export_window.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gui\new_window.cpp">
|
||||
</File>
|
||||
@@ -2876,10 +2882,10 @@
|
||||
RelativePath="..\conversion-todo.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\data\en.mse-locale\locale">
|
||||
RelativePath="..\data\nl.mse-locale\locale">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\data\nl.mse-locale\locale">
|
||||
RelativePath="..\data\en.mse-locale\locale">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\main.cpp">
|
||||
|
||||
Reference in New Issue
Block a user