mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Moved clean_filename to file_utils.cpp where it belongs;
Split up images exporting, and moved it to data/formats/image git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1085 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -57,50 +57,6 @@ ImagesExportWindow::ImagesExportWindow(Window* parent, const SetP& set)
|
||||
|
||||
// ----------------------------------------------------------------------------- : Exporting the images
|
||||
|
||||
void ExportCardImages::exportImages(const SetP& set, wxFileName& fn, const String& filename_template, FilenameConflicts conflicts) {
|
||||
// Script
|
||||
ScriptP filename_script = parse(filename_template, nullptr, true);
|
||||
// Export
|
||||
std::set<String> used; // for CONFLICT_NUMBER_OVERWRITE
|
||||
FOR_EACH(card, set->cards) {
|
||||
if (includeCard(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
|
||||
// sanitize filename
|
||||
fn.SetFullName(clean_filename(filename));
|
||||
// does the file exist?
|
||||
if (fn.FileExists()) {
|
||||
// file exists, what to do?
|
||||
switch (conflicts) {
|
||||
case CONFLICT_KEEP_OLD: goto next_card;
|
||||
case CONFLICT_OVERWRITE: break;
|
||||
case CONFLICT_NUMBER: {
|
||||
int i = 0;
|
||||
String ext = fn.GetExt();
|
||||
do {
|
||||
fn.SetExt(String() << ++i << _(".") << ext);
|
||||
} while(fn.FileExists());
|
||||
}
|
||||
case CONFLICT_NUMBER_OVERWRITE: {
|
||||
int i = 0;
|
||||
String ext = fn.GetExt();
|
||||
while(used.find(fn.GetFullPath()) != used.end()) {
|
||||
fn.SetExt(String() << ++i << _(".") << ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// write image
|
||||
filename = fn.GetFullPath();
|
||||
used.insert(filename);
|
||||
export_image(set, card, filename);
|
||||
}
|
||||
next_card:;
|
||||
}
|
||||
}
|
||||
|
||||
void ImagesExportWindow::onOk(wxCommandEvent&) {
|
||||
// Update settings
|
||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||
@@ -114,17 +70,17 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
|
||||
String name = wxFileSelector(_TITLE_("export images"),_(""), _LABEL_("filename is ignored"),_(""),
|
||||
_LABEL_("filename is ignored")+_("|*"), wxSAVE, this);
|
||||
if (name.empty()) return;
|
||||
wxFileName fn(name);
|
||||
// Cards to export
|
||||
vector<CardP> cards;
|
||||
FOR_EACH(card, set->cards) {
|
||||
if (isSelected(card)) cards.push_back(card);
|
||||
}
|
||||
// Export
|
||||
exportImages(set, fn, gs.images_export_filename, gs.images_export_conflicts);
|
||||
export_images(set, cards, name, gs.images_export_filename, gs.images_export_conflicts);
|
||||
// Done
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
|
||||
bool ImagesExportWindow::includeCard(const CardP& card) const {
|
||||
return isSelected(card);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_EVENT_TABLE(ImagesExportWindow,CardSelectWindow)
|
||||
EVT_BUTTON (wxID_OK, ImagesExportWindow::onOk)
|
||||
|
||||
@@ -12,24 +12,11 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/card_select_window.hpp>
|
||||
#include <data/settings.hpp>
|
||||
class wxFileName;
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImagesExportWindow
|
||||
|
||||
/// Export the cards in a set
|
||||
class ExportCardImages {
|
||||
public:
|
||||
void exportImages(const SetP& set, wxFileName& filename, const String& filename_template, FilenameConflicts conflicts);
|
||||
virtual ~ExportCardImages() {}
|
||||
protected:
|
||||
/// Should the given card be exported?
|
||||
virtual bool includeCard(const CardP& card) const { return true; }
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImagesExportWindow
|
||||
|
||||
/// A window for selecting a subset of the cards from a set to export to images
|
||||
class ImagesExportWindow : public CardSelectWindow, private ExportCardImages {
|
||||
class ImagesExportWindow : public CardSelectWindow {
|
||||
public:
|
||||
ImagesExportWindow(Window* parent, const SetP& set);
|
||||
|
||||
@@ -38,8 +25,6 @@ class ImagesExportWindow : public CardSelectWindow, private ExportCardImages {
|
||||
|
||||
void onOk(wxCommandEvent&);
|
||||
|
||||
virtual bool includeCard(const CardP& card) const;
|
||||
|
||||
wxTextCtrl* format;
|
||||
wxChoice* conflicts;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user