Commit c3008dd9 authored by twanvl's avatar twanvl

Added 'export all card images' functionality

parent 0935fcf8
...@@ -102,8 +102,11 @@ help: ...@@ -102,8 +102,11 @@ help:
undo: Undoes the last action undo: Undoes the last action
redo: Redoes the last action redo: Redoes the last action
cut: Move the selected text to the clipboard cut: Move the selected text to the clipboard
cut card: Move the selected card to the clipboard
copy: Place the selected text on the clipboard copy: Place the selected text on the clipboard
copy card: Place the selected card on the clipboard
paste: Inserts the text from the clipboard paste: Inserts the text from the clipboard
paste card: Inserts the card from the clipboard
preferences: Change the configuration of Not Quite Magic Set Editor preferences: Change the configuration of Not Quite Magic Set Editor
cards: cards:
...@@ -198,6 +201,9 @@ help: ...@@ -198,6 +201,9 @@ help:
drag to move line: Alt + drag to move curve; double click to add a point on this line drag to move line: Alt + drag to move curve; double click to add a point on this line
drag to move point: Click and drag to move control point; double click to remove the point drag to move point: Click and drag to move control point; double click to remove the point
# Card select
filename format: (Use {card.name} for the name of the card ; The filetype is determined based on the extension)
############################################################## Toolbar ############################################################## Toolbar
tool: tool:
undo: Undo undo: Undo
...@@ -304,6 +310,9 @@ tooltip: ...@@ -304,6 +310,9 @@ tooltip:
label: label:
card notes: Card notes: card notes: Card notes:
# Open dialogs
all files All files
# Preferences # Preferences
language: Language language: Language
app language: Language of the user interface: app language: Language of the user interface:
...@@ -324,8 +333,13 @@ label: ...@@ -324,8 +333,13 @@ label:
select columns: Select the columns you want to display select columns: Select the columns you want to display
columns: Columns: columns: Columns:
# Card select # Card select / images export
select cards print: Select the cards you want to print select cards print: Select the cards you want to print
filename format: &Format:
filename conflicts: &Handle duplicating filenames:
export filenames: Filenames
cards to export: Cards to export
filename is ignored: (filename is ignored)
# Image slicer # Image slicer
original: Original: original: Original:
...@@ -368,6 +382,10 @@ button: ...@@ -368,6 +382,10 @@ button:
# Card select # Card select
select all: Select &All select all: Select &All
select none: Select &None select none: Select &None
overwrite: Overwrite old files
keep old: Keep old files
number: Add a number to the filename
number overwrite: Add a number to the filename, overwrite previous exports
# Update checker # Update checker
close: &Close close: &Close
...@@ -393,10 +411,13 @@ title: ...@@ -393,10 +411,13 @@ title:
# select # select
select columns: Select Columns select columns: Select Columns
select cards: Select Cards select cards: Select Cards
select cards export:Select Cards to Export
# slice # slice
slice image: Slice Image slice image: Slice Image
# print # print
print preview: Print Preview print preview: Print Preview
# export
export images: Export Images
############################################################## Action (undo/redo) names ############################################################## Action (undo/redo) names
action: action:
......
...@@ -26,6 +26,13 @@ IMPLEMENT_REFLECTION_ENUM(CheckUpdates) { ...@@ -26,6 +26,13 @@ IMPLEMENT_REFLECTION_ENUM(CheckUpdates) {
VALUE_N("never", CHECK_NEVER); 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; const int COLUMN_NOT_INITIALIZED = -100000;
ColumnSettings::ColumnSettings() ColumnSettings::ColumnSettings()
...@@ -43,6 +50,8 @@ IMPLEMENT_REFLECTION(ColumnSettings) { ...@@ -43,6 +50,8 @@ IMPLEMENT_REFLECTION(ColumnSettings) {
GameSettings::GameSettings() GameSettings::GameSettings()
: sort_cards_ascending(true) : sort_cards_ascending(true)
, images_export_filename(_("{card.name}.jpg"))
, images_export_conflicts(CONFLICT_NUMBER_OVERWRITE)
{} {}
IMPLEMENT_REFLECTION(GameSettings) { IMPLEMENT_REFLECTION(GameSettings) {
...@@ -51,6 +60,8 @@ IMPLEMENT_REFLECTION(GameSettings) { ...@@ -51,6 +60,8 @@ IMPLEMENT_REFLECTION(GameSettings) {
REFLECT_N("cardlist columns", columns); REFLECT_N("cardlist columns", columns);
REFLECT(sort_cards_by); REFLECT(sort_cards_by);
REFLECT(sort_cards_ascending); REFLECT(sort_cards_ascending);
REFLECT(images_export_filename);
REFLECT(images_export_conflicts);
} }
......
...@@ -29,6 +29,14 @@ enum CheckUpdates ...@@ -29,6 +29,14 @@ enum CheckUpdates
, CHECK_NEVER , 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 /// Settings of a single column in the card list
class ColumnSettings { class ColumnSettings {
public: public:
...@@ -50,6 +58,8 @@ class GameSettings { ...@@ -50,6 +58,8 @@ class GameSettings {
map<String, ColumnSettings> columns; map<String, ColumnSettings> columns;
String sort_cards_by; String sort_cards_by;
bool sort_cards_ascending; bool sort_cards_ascending;
String images_export_filename;
FilenameConflicts images_export_conflicts;
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
......
...@@ -59,6 +59,7 @@ StatsCategory::StatsCategory(const StatsDimensionP& dim) ...@@ -59,6 +59,7 @@ StatsCategory::StatsCategory(const StatsDimensionP& dim)
IMPLEMENT_REFLECTION_ENUM(GraphType) { IMPLEMENT_REFLECTION_ENUM(GraphType) {
VALUE_N("bar", GRAPH_TYPE_BAR); VALUE_N("bar", GRAPH_TYPE_BAR);
VALUE_N("pie", GRAPH_TYPE_PIE); VALUE_N("pie", GRAPH_TYPE_PIE);
VALUE_N("scatter", GRAPH_TYPE_SCATTER);
} }
IMPLEMENT_REFLECTION(StatsCategory) { IMPLEMENT_REFLECTION(StatsCategory) {
......
...@@ -42,6 +42,7 @@ class StatsDimension { ...@@ -42,6 +42,7 @@ class StatsDimension {
enum GraphType enum GraphType
{ GRAPH_TYPE_BAR { GRAPH_TYPE_BAR
, GRAPH_TYPE_PIE , GRAPH_TYPE_PIE
, GRAPH_TYPE_SCATTER
}; };
/// A category for statistics /// A category for statistics
......
...@@ -12,18 +12,21 @@ ...@@ -12,18 +12,21 @@
// ----------------------------------------------------------------------------- : CardSelectWindow // ----------------------------------------------------------------------------- : 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) : wxDialog(parent, wxID_ANY, _TITLE_("select cards"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, set(set) , set(set)
{ {
// init controls // init controls
list = new SelectCardList(this, wxID_ANY); list = new SelectCardList(this, wxID_ANY);
list->setSet(set); list->setSet(set);
wxButton* sel_all = new wxButton(this, ID_SELECT_ALL, _BUTTON_("select all")); sel_all = new wxButton(this, ID_SELECT_ALL, _BUTTON_("select all"));
wxButton* sel_none = new wxButton(this, ID_SELECT_NONE, _BUTTON_("select none")); sel_none = new wxButton(this, ID_SELECT_NONE, _BUTTON_("select none"));
// init sizers // init sizers
if (sizer) {
wxSizer* s = new wxBoxSizer(wxVERTICAL); wxSizer* s = new wxBoxSizer(wxVERTICAL);
if (!label.empty()) {
s->Add(new wxStaticText(this, wxID_ANY, label), 0, wxALL & ~wxBOTTOM, 8); s->Add(new wxStaticText(this, wxID_ANY, label), 0, wxALL & ~wxBOTTOM, 8);
}
s->Add(list, 1, wxEXPAND | wxALL, 8); s->Add(list, 1, wxEXPAND | wxALL, 8);
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL); wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
s2->Add(sel_all, 0, wxEXPAND | wxRIGHT, 8); s2->Add(sel_all, 0, wxEXPAND | wxRIGHT, 8);
...@@ -33,6 +36,7 @@ CardSelectWindow::CardSelectWindow(Window* parent, const SetP& set, const String ...@@ -33,6 +36,7 @@ CardSelectWindow::CardSelectWindow(Window* parent, const SetP& set, const String
s->SetSizeHints(this); s->SetSizeHints(this);
SetSizer(s); SetSizer(s);
SetSize(500,500); SetSize(500,500);
}
} }
bool CardSelectWindow::isSelected(const CardP& card) const { bool CardSelectWindow::isSelected(const CardP& card) const {
...@@ -46,7 +50,7 @@ void CardSelectWindow::onSelectNone(wxCommandEvent&) { ...@@ -46,7 +50,7 @@ void CardSelectWindow::onSelectNone(wxCommandEvent&) {
list->selectNone(); list->selectNone();
} }
BEGIN_EVENT_TABLE(CardSelectWindow,wxDialog) BEGIN_EVENT_TABLE(CardSelectWindow, wxDialog)
EVT_BUTTON (ID_SELECT_ALL, CardSelectWindow::onSelectAll) EVT_BUTTON (ID_SELECT_ALL, CardSelectWindow::onSelectAll)
EVT_BUTTON (ID_SELECT_NONE, CardSelectWindow::onSelectNone) EVT_BUTTON (ID_SELECT_NONE, CardSelectWindow::onSelectNone)
END_EVENT_TABLE () END_EVENT_TABLE ()
...@@ -22,7 +22,7 @@ class SelectCardList; ...@@ -22,7 +22,7 @@ class SelectCardList;
*/ */
class CardSelectWindow : public wxDialog { class CardSelectWindow : public wxDialog {
public: 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? /// Is the given card selected?
bool isSelected(const CardP& card) const; bool isSelected(const CardP& card) const;
...@@ -32,6 +32,7 @@ class CardSelectWindow : public wxDialog { ...@@ -32,6 +32,7 @@ class CardSelectWindow : public wxDialog {
SelectCardList* list; SelectCardList* list;
SetP set; SetP set;
wxButton* sel_all, *sel_none;
void onSelectAll (wxCommandEvent&); void onSelectAll (wxCommandEvent&);
void onSelectNone(wxCommandEvent&); void onSelectNone(wxCommandEvent&);
......
//+----------------------------------------------------------------------------+
//| 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 ()
//+----------------------------------------------------------------------------+
//| 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) { ...@@ -94,7 +94,7 @@ void TextBufferDC::drawToDevice(DC& dc, int x, int y) {
void print_preview(Window* parent, const SetP& set) { void print_preview(Window* parent, const SetP& set) {
// Let the user choose cards // 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) { if (wnd.ShowModal() != wxID_OK) {
return; // cancel return; // cancel
} }
...@@ -116,7 +116,7 @@ void print_preview(Window* parent, const SetP& set) { ...@@ -116,7 +116,7 @@ void print_preview(Window* parent, const SetP& set) {
void print_set(Window* parent, const SetP& set) { void print_set(Window* parent, const SetP& set) {
// Let the user choose cards // 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) { if (wnd.ShowModal() != wxID_OK) {
return; // cancel return; // cancel
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <gui/set/panel.hpp> #include <gui/set/panel.hpp>
class KeywordList; class KeywordList;
class TextCtrl;
// ----------------------------------------------------------------------------- : KeywordsPanel // ----------------------------------------------------------------------------- : KeywordsPanel
...@@ -25,6 +26,7 @@ class KeywordsPanel : public SetWindowPanel { ...@@ -25,6 +26,7 @@ class KeywordsPanel : public SetWindowPanel {
private: private:
KeywordList* list; KeywordList* list;
TextCtrl* keyword;
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <gui/new_window.hpp> #include <gui/new_window.hpp>
#include <gui/preferences_window.hpp> #include <gui/preferences_window.hpp>
#include <gui/print_window.hpp> #include <gui/print_window.hpp>
#include <gui/images_export_window.hpp>
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
...@@ -437,7 +438,8 @@ void SetWindow::onFileExportImage(wxCommandEvent&) { ...@@ -437,7 +438,8 @@ void SetWindow::onFileExportImage(wxCommandEvent&) {
} }
void SetWindow::onFileExportImages(wxCommandEvent&) { void SetWindow::onFileExportImages(wxCommandEvent&) {
// exportImages(this, set); ImagesExportWindow wnd(this, set);
wnd.ShowModal();
} }
void SetWindow::onFileExportHTML(wxCommandEvent&) { void SetWindow::onFileExportHTML(wxCommandEvent&) {
......
...@@ -881,6 +881,12 @@ ...@@ -881,6 +881,12 @@
<File <File
RelativePath=".\gui\image_slice_window.hpp"> RelativePath=".\gui\image_slice_window.hpp">
</File> </File>
<File
RelativePath=".\gui\images_export_window.cpp">
</File>
<File
RelativePath=".\gui\images_export_window.hpp">
</File>
<File <File
RelativePath=".\gui\new_window.cpp"> RelativePath=".\gui\new_window.cpp">
</File> </File>
...@@ -2876,10 +2882,10 @@ ...@@ -2876,10 +2882,10 @@
RelativePath="..\conversion-todo.txt"> RelativePath="..\conversion-todo.txt">
</File> </File>
<File <File
RelativePath="..\data\en.mse-locale\locale"> RelativePath="..\data\nl.mse-locale\locale">
</File> </File>
<File <File
RelativePath="..\data\nl.mse-locale\locale"> RelativePath="..\data\en.mse-locale\locale">
</File> </File>
<File <File
RelativePath=".\main.cpp"> RelativePath=".\main.cpp">
......
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