diff --git a/CMakeLists.txt b/CMakeLists.txt index faea23d..7509b69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,6 +264,8 @@ set(PROJECT_SOURCES "src/SpecialCharactersDialog.h" "src/TdwManagerDialog.cpp" "src/TdwManagerDialog.h" + "src/TdwExporter.cpp" + "src/TdwExporter.h" "src/TextExporter.cpp" "src/TextExporter.h" "src/TextExporterWidget.cpp" diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 9cc960d..e64b6eb 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -24,6 +24,7 @@ #include "ScriptExporter.h" #include "EncounterExporter.h" #include "BackgroundExporter.h" +#include "TdwExporter.h" #include "widgets/PageWidget.h" #include "widgets/MsdWidget.h" #include "widgets/JsmWidget.h" @@ -84,6 +85,7 @@ MainWindow::MainWindow() menuExportAll->addAction(tr("Scripts..."), this, SLOT(exportAllScripts())); menuExportAll->addAction(tr("Random Encounters..."), this, SLOT(exportAllEncounters())); menuExportAll->addAction(tr("Backgrounds..."), this, SLOT(exportAllBackground())); + menuExportAll->addAction(tr("Additional Characters..."), this, SLOT(exportAllAdditionalFont())); actionImport = menu->addAction(tr("Import..."), this, SLOT(importCurrent())); menuImportAll = menu->addMenu(tr("Import all")); menuImportAll->addAction(tr("Texts..."), this, SLOT(importAllTexts())); @@ -1052,6 +1054,31 @@ void MainWindow::exportAllBackground() } } +void MainWindow::exportAllAdditionalFont() +{ + if (!fieldArchive) + return; + + QString oldPath = Config::value("export_path").toString(); + + QString dirPath = + QFileDialog::getExistingDirectory(this, tr("Export"), oldPath); + if (dirPath.isNull()) { + return; + } + + Config::setValue("export_path", dirPath); + + ProgressWidget progress(tr("Export..."), ProgressWidget::Cancel, this); + + TdwExporter exporter(fieldArchive); + + if (!exporter.toDir(dirPath, &progress) + && !progress.observerWasCanceled()) { + QMessageBox::warning(this, tr("Error"), exporter.errorString()); + } +} + void MainWindow::importCurrent() { if (!currentField) return; diff --git a/src/MainWindow.h b/src/MainWindow.h index f8fb865..39b7cd0 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -73,6 +73,7 @@ private slots: void exportAllScripts(); void exportAllEncounters(); void exportAllBackground(); + void exportAllAdditionalFont(); void importCurrent(); void optimizeArchive(); void manageArchive(); diff --git a/src/TdwExporter.cpp b/src/TdwExporter.cpp new file mode 100644 index 0000000..11a67be --- /dev/null +++ b/src/TdwExporter.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** + ** Deling Final Fantasy VIII Field Editor + ** Copyright (C) 2009-2024 Arzel Jérôme + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ****************************************************************************/ +#include "TdwExporter.h" +#include "FieldPC.h" +#include "FieldArchivePC.h" +#include "ArchiveObserver.h" + +TdwExporter::TdwExporter(FieldArchive *archive) : _archive(archive) +{ +} + +bool TdwExporter::toDir(const QDir &dir, ArchiveObserver *observer) +{ + if (!_archive) { + return false; + } + + FieldArchiveIterator it = _archive->iterator(); + + if (observer) { + observer->setObserverMaximum(quint32(_archive->nbFields())); + } + + int i = 0; + + while (it.hasNext()) { + Field *f = it.next(); + + if (observer) { + if (observer->observerWasCanceled()) { + return false; + } + observer->setObserverValue(i++); + } + + if (f && f->isOpen() && f->hasTdwFile()) { + TdwFile *tdw = f->getTdwFile(); + char *format = (char *)"PNG"; + if (tdw->isOpen()) { + QString fieldName = f->name(); + + if (fieldName.isEmpty()) { + fieldName = QObject::tr("Unamed"); + } + QByteArray data; + if (tdw) { + QString path = dir.filePath(fieldName + ".png"); + QFile f(path); + tdw->image(TdwFile::Color::White).save(path, format); + } else { + _lastErrorString = + QObject::tr("Unable to export '%1' to image") + .arg(fieldName); + } + } + } + } + + return true; +} diff --git a/src/TdwExporter.h b/src/TdwExporter.h new file mode 100644 index 0000000..d5553fe --- /dev/null +++ b/src/TdwExporter.h @@ -0,0 +1,37 @@ +/**************************************************************************** + ** Deling Final Fantasy VIII Field Editor + ** Copyright (C) 2009-2024 Arzel Jérôme + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ****************************************************************************/ +#pragma once + +#include + +#include "FieldArchive.h" + +class TdwExporter +{ +public: + explicit TdwExporter(FieldArchive *archive); + bool toDir(const QDir &dir, ArchiveObserver *observer = nullptr); + inline const QString &errorString() const + { + return _lastErrorString; + } + +private: + FieldArchive *_archive; + QString _lastErrorString; +};