Skip to content

Commit

Permalink
Adding export chunks dialog to select specific chunks to export
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed Apr 16, 2024
1 parent fced841 commit a9df7c2
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 12 deletions.
19 changes: 15 additions & 4 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "widgets/EncounterWidget.h"
#include "widgets/MiscWidget.h"
#include "widgets/ImportDialog.h"
#include "widgets/ExportChunksDialog.h"
#include "widgets/MassExportDialog.h"
#include "widgets/MassImportDialog.h"
#include "widgets/PsfDialog.h"
Expand Down Expand Up @@ -1407,8 +1408,18 @@ void Window::exportCurrentMapIntoChunks()
if (path.isNull()) {
return;
}

ExportChunksDialog dialog(this);
if (dialog.exec() != QDialog::Accepted) {
return;
}

Field::FieldSections parts = dialog.parts();
if (parts == 0) {
return;
}

if (!field->exportToChunks(path)) {
if (!field->exportToChunks(path, parts)) {
QMessageBox::warning(this, tr("Error"), field->errorString());
return;
}
Expand Down Expand Up @@ -1540,10 +1551,10 @@ void Window::importToCurrentMap()
}
} else {
bool isDat = selectedFilter == dat;

ImportDialog dialog((isDat && fieldArchive->io()->isPS())
|| (!isDat && fieldArchive->io()->isPC()),
isDat, path, this);
|| (!isDat && fieldArchive->io()->isPC()),
isDat, path, this);
if (dialog.exec() != QDialog::Accepted) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/field/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Field
bool importer(const QByteArray &data, bool isPSField, FieldSections part, QIODevice *bsxDevice = nullptr,
QIODevice *mimDevice = nullptr);
bool importChunk(const QString &path);
virtual bool exportToChunks(const QDir &dir) = 0;
virtual bool exportToChunks(const QDir &dir, FieldSections parts) = 0;

Section1File *scriptsAndTexts(bool open=true);
EncounterFile *encounter(bool open=true);
Expand Down
27 changes: 25 additions & 2 deletions src/core/field/FieldArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,12 +1878,35 @@ bool FieldArchive::exportation(const QList<int> &selectedFields, const QString &
}
}
if (toExport.contains(Chunks)) {
path = QDir::cleanPath(QString("%1/%2").arg(directory, f->name()));
path = QDir::cleanPath(directory);
extension = toExport.value(Chunks);
Field::FieldSection section;
if (extension == "chunk.1") {
section = Field::Scripts;
} else if (extension == "chunk.2") {
section = Field::Camera;
} else if (extension == "chunk.3") {
section = Field::ModelLoader;
} else if (extension == "chunk.4") {
section = Field::PalettePC;
} else if (extension == "chunk.5") {
section = Field::Walkmesh;
} else if (extension == "chunk.6") {
section = Field::Tiles;
} else if (extension == "chunk.7") {
section = Field::Encounter;
} else if (extension == "chunk.8") {
section = Field::Inf;
} else if (extension == "chunk.9") {
section = Field::Background;
} else {
return false;
}
QDir dir(path);
if (!dir.exists()) {
dir.mkpath("./");
}
if (!f->exportToChunks(dir)) {
if (!f->exportToChunks(dir, section)) {
return false;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/field/FieldPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,15 @@ bool FieldPC::importModelLoader(const QByteArray &sectionData, bool isPSField, Q
return true;
}

bool FieldPC::exportToChunks(const QDir &dir)
bool FieldPC::exportToChunks(const QDir &dir, FieldSections parts)
{
quint8 sectionNum = 1;
QList<FieldSection> sections = orderOfSections();
for (FieldSection section : sections) {
if (!parts.testFlag(section)) {
++sectionNum;
continue;
}
QFile f(dir.filePath(QString("%1.chunk.%2").arg(name()).arg(sectionNum)));
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
setErrorString(QString("%1: %2").arg(f.fileName(), f.errorString()));
Expand Down
2 changes: 1 addition & 1 deletion src/core/field/FieldPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FieldPC : public Field
FieldModelLoaderPC *fieldModelLoader(bool open = true) override;
FieldModelFilePC *fieldModel(int modelID, int animationID = 0, bool animate = true, bool open = true) override;
FieldModelFilePC *fieldModel(const QString &hrc, const QString &a, bool animate = true);
bool exportToChunks(const QDir &dir) override;
bool exportToChunks(const QDir &dir, FieldSections parts) override;
protected:
inline int headerSize() const override { return 42; }
void openHeader(const QByteArray &fileData) override;
Expand Down
5 changes: 4 additions & 1 deletion src/core/field/FieldPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,13 @@ qint8 FieldPS::saveBackground(const QString &path, bool compress)
return 1;
}

bool FieldPS::exportToChunks(const QDir &dir)
bool FieldPS::exportToChunks(const QDir &dir, FieldSections parts)
{
QList<FieldSection> sections = orderOfSections();
for (FieldSection section : sections) {
if (!parts.testFlag(section)) {
continue;
}
QString extension;
switch (section) {
case Scripts:
Expand Down
2 changes: 1 addition & 1 deletion src/core/field/FieldPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FieldPS : public Field
FieldModelLoaderPS *fieldModelLoader(bool open = true) override;
FieldModelFilePS *fieldModel(int modelID, int animationID = 0, bool animate = true, bool open = true) override;
FieldArchiveIOPS *io() const override;
bool exportToChunks(const QDir &dir) override;
bool exportToChunks(const QDir &dir, FieldSections parts) override;
bool saveModels(QByteArray &newData, bool compress);
qint8 saveModels(const QString &path, bool compress);
bool saveBackground(QByteArray &newData, bool compress);
Expand Down
84 changes: 84 additions & 0 deletions src/widgets/ExportChunksDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/****************************************************************************
** Makou Reactor Final Fantasy VII Field Script Editor
** Copyright (C) 2009-2024 Arzel Jérôme <[email protected]>
**
** 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 <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "ExportChunksDialog.h"

ExportChunksDialog::ExportChunksDialog(QWidget *parent) :
QDialog(parent, Qt::Dialog | Qt::WindowCloseButtonHint)
{
setWindowTitle(tr("Export to chunks"));

QGroupBox *group = new QGroupBox(tr("Export"));
scripts = new QCheckBox(tr("Chunk 1: Scripts/Texts"));
ca = new QCheckBox(tr("Chunk 2: Camera"));
id = new QCheckBox(tr("Chunk 5: Walkmesh"));
tiles = new QCheckBox(tr("Chunk 6: Tiles (unused)"));
encounter = new QCheckBox(tr("Chunk 7: Encounters"));
inf = new QCheckBox(tr("Chunk 8: Triggers/gateways"));
model = new QCheckBox(tr("Chunk 3: Model loader (PC only)"));
mim = new QCheckBox(tr("Chunk 9: Background (PC only)"));
palette = new QCheckBox(tr("Chunk 4: Palette (PC only)"));

scripts->setChecked(scripts->isEnabled());
ca->setChecked(ca->isEnabled());
id->setChecked(id->isEnabled());
tiles->setChecked(tiles->isEnabled());
encounter->setChecked(encounter->isEnabled());
inf->setChecked(inf->isEnabled());
model->setChecked(model->isEnabled());
mim->setChecked(mim->isEnabled());
palette->setChecked(palette->isEnabled());

QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);

QVBoxLayout *layout = new QVBoxLayout(group);
layout->addWidget(scripts);
layout->addWidget(ca);
layout->addWidget(model);
layout->addWidget(palette);
layout->addWidget(id);
layout->addWidget(tiles);
layout->addWidget(encounter);
layout->addWidget(inf);
layout->addWidget(mim);
layout->addStretch();

layout = new QVBoxLayout(this);
layout->addWidget(group);
layout->addWidget(buttonBox);
layout->addStretch();

connect(buttonBox, &QDialogButtonBox::accepted, this, &ExportChunksDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ExportChunksDialog::reject);
}

Field::FieldSections ExportChunksDialog::parts() const
{
Field::FieldSections parts;

if (scripts->isChecked()) parts |= Field::Scripts;
if (ca->isChecked()) parts |= Field::Camera;
if (model->isChecked()) parts |= Field::ModelLoader;
if (palette->isChecked()) parts |= Field::PalettePC;
if (id->isChecked()) parts |= Field::Walkmesh;
if (tiles->isChecked()) parts |= Field::Tiles;
if (encounter->isChecked()) parts |= Field::Encounter;
if (inf->isChecked()) parts |= Field::Inf;
if (mim->isChecked()) parts |= Field::Background;

return parts;
}
39 changes: 39 additions & 0 deletions src/widgets/ExportChunksDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/****************************************************************************
** Makou Reactor Final Fantasy VII Field Script Editor
** Copyright (C) 2009-2024 Arzel Jérôme <[email protected]>
**
** 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 <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once

#include <QtWidgets>
#include "core/field/Field.h"

class ExportChunksDialog : public QDialog
{
Q_OBJECT
public:
ExportChunksDialog(QWidget *parent = nullptr);
Field::FieldSections parts() const;
private:
QCheckBox *scripts;
QCheckBox *ca;
QCheckBox *id;
QCheckBox *tiles;
QCheckBox *encounter;
QCheckBox *inf;
QCheckBox *model;
QCheckBox *mim;
QCheckBox *palette;
};
11 changes: 10 additions & 1 deletion src/widgets/MassExportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ MassExportDialog::MassExportDialog(QWidget *parent) :
exports.insert(FieldArchive::Chunks,
new FormatSelectionWidget(tr("Export chunks"),
QStringList() <<
tr("Field Chunks") + ";;chunk", this));
tr("Field Chunks") + ";;chunk" <<
tr("Chunk 1 (Scripts, texts and akaos)") + ";;chunk.1" <<
tr("Chunk 2 (Camera)") + ";;chunk.2" <<
tr("Chunk 3 (Model loader PC)") + ";;chunk.3" <<
tr("Chunk 4 (Palettes PC)") + ";;chunk.4" <<
tr("Chunk 5 (Walkmesh)") + ";;chunk.5" <<
tr("Chunk 6 (Tiles)") + ";;chunk.6" <<
tr("Chunk 7 (Encounters)") + ";;chunk.7" <<
tr("Chunk 8 (Misc and doors)") + ";;chunk.8" <<
tr("Chunk 9 (Background PC)") + ";;chunk.9", this));

exports.value(FieldArchive::Backgrounds)->setCurrentFormat(Config::value("exportBackgroundFormat").toString());

Expand Down
Loading

0 comments on commit a9df7c2

Please sign in to comment.