2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-04-14 08:24:06 -04:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2023-07-08 10:33:12 -04:00
|
|
|
#include <QApplication>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QDesktopServices>
|
2023-10-12 19:04:19 -04:00
|
|
|
#include <QFileDialog>
|
2022-04-14 08:24:06 -04:00
|
|
|
#include <QHBoxLayout>
|
2023-10-12 21:33:32 -04:00
|
|
|
#include <QLabel>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QMenuBar>
|
2024-02-03 10:04:25 -05:00
|
|
|
#include <QMessageBox>
|
2022-04-14 08:24:06 -04:00
|
|
|
|
2023-10-13 15:20:01 -04:00
|
|
|
#include "cmppart.h"
|
2023-10-12 21:33:32 -04:00
|
|
|
#include "exdpart.h"
|
|
|
|
#include "exlpart.h"
|
2023-07-08 10:33:12 -04:00
|
|
|
#include "filepropertieswindow.h"
|
2023-09-23 15:45:38 -04:00
|
|
|
#include "filetreewindow.h"
|
2023-10-12 20:18:22 -04:00
|
|
|
#include "hexpart.h"
|
2023-10-12 21:33:32 -04:00
|
|
|
#include "mdlpart.h"
|
2023-10-13 15:01:08 -04:00
|
|
|
#include "shpkpart.h"
|
2023-10-13 15:36:36 -04:00
|
|
|
#include "sklbpart.h"
|
2023-10-12 21:40:46 -04:00
|
|
|
#include "texpart.h"
|
2023-07-08 10:33:12 -04:00
|
|
|
|
2023-12-09 15:24:54 -05:00
|
|
|
MainWindow::MainWindow(const QString &gamePath, GameData *data)
|
2023-10-10 18:22:38 -04:00
|
|
|
: NovusMainWindow()
|
|
|
|
, data(data)
|
2023-10-12 21:33:32 -04:00
|
|
|
, fileCache(*data)
|
2023-10-10 18:02:13 -04:00
|
|
|
{
|
2023-10-10 18:22:38 -04:00
|
|
|
setupMenubar();
|
2023-07-08 10:33:12 -04:00
|
|
|
|
2023-10-12 19:46:58 -04:00
|
|
|
auto dummyWidget = new QWidget();
|
|
|
|
setCentralWidget(dummyWidget);
|
|
|
|
|
|
|
|
auto layout = new QHBoxLayout();
|
|
|
|
dummyWidget->setLayout(layout);
|
2022-04-14 08:24:06 -04:00
|
|
|
|
2024-02-02 14:25:32 -05:00
|
|
|
auto tree = new FileTreeWindow(m_database, gamePath, data);
|
2023-12-09 15:24:54 -05:00
|
|
|
connect(tree, &FileTreeWindow::extractFile, this, [this, data](const QString &path) {
|
2023-10-12 19:04:19 -04:00
|
|
|
const QFileInfo info(path);
|
|
|
|
|
|
|
|
const QString savePath = QFileDialog::getSaveFileName(this, tr("Save File"), info.fileName(), QStringLiteral("*.%1").arg(info.completeSuffix()));
|
|
|
|
if (!savePath.isEmpty()) {
|
|
|
|
qInfo() << "Saving to" << savePath;
|
|
|
|
|
|
|
|
std::string savePathStd = path.toStdString();
|
|
|
|
|
|
|
|
auto fileData = physis_gamedata_extract_file(data, savePathStd.c_str());
|
|
|
|
QFile file(savePath);
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reinterpret_cast<const char *>(fileData.data), fileData.size);
|
|
|
|
}
|
|
|
|
});
|
2023-12-09 22:35:59 -05:00
|
|
|
connect(tree, &FileTreeWindow::pathSelected, this, [this](const QString &path) {
|
2023-10-12 19:46:58 -04:00
|
|
|
refreshParts(path);
|
|
|
|
});
|
|
|
|
tree->setMaximumWidth(200);
|
|
|
|
layout->addWidget(tree);
|
|
|
|
|
|
|
|
partHolder = new QTabWidget();
|
|
|
|
partHolder->setMinimumWidth(800);
|
|
|
|
partHolder->setMinimumHeight(720);
|
|
|
|
layout->addWidget(partHolder);
|
|
|
|
|
|
|
|
refreshParts({});
|
|
|
|
}
|
|
|
|
|
2023-12-09 15:24:54 -05:00
|
|
|
void MainWindow::refreshParts(const QString &path)
|
2023-10-12 19:46:58 -04:00
|
|
|
{
|
|
|
|
partHolder->clear();
|
|
|
|
|
|
|
|
std::string pathStd = path.toStdString();
|
|
|
|
if (path.isEmpty() || !physis_gamedata_exists(data, pathStd.c_str())) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-14 08:24:06 -04:00
|
|
|
|
2023-10-12 20:18:22 -04:00
|
|
|
auto file = physis_gamedata_extract_file(data, path.toStdString().c_str());
|
|
|
|
|
2023-10-12 21:33:32 -04:00
|
|
|
QFileInfo info(path);
|
|
|
|
if (info.completeSuffix() == QStringLiteral("exl")) {
|
|
|
|
auto exlWidget = new EXLPart(data);
|
|
|
|
exlWidget->load(file);
|
|
|
|
partHolder->addTab(exlWidget, QStringLiteral("Excel List"));
|
|
|
|
} else if (info.completeSuffix() == QStringLiteral("exh")) {
|
|
|
|
auto exdWidget = new EXDPart(data);
|
|
|
|
exdWidget->loadSheet(info.baseName(), file);
|
|
|
|
partHolder->addTab(exdWidget, QStringLiteral("Excel Sheet"));
|
|
|
|
} else if (info.completeSuffix() == QStringLiteral("exd")) {
|
|
|
|
auto exdWidget = new QLabel(QStringLiteral("Note: Excel data files cannot be previewed standalone, select the EXH file instead."));
|
|
|
|
partHolder->addTab(exdWidget, QStringLiteral("Note"));
|
|
|
|
} else if (info.completeSuffix() == QStringLiteral("mdl")) {
|
|
|
|
auto mdlWidget = new MDLPart(data, fileCache);
|
2024-02-02 14:37:58 -05:00
|
|
|
mdlWidget->addModel(physis_mdl_parse(file), false, glm::vec3(), QStringLiteral("mdl"), {}, 0);
|
2023-10-12 21:33:32 -04:00
|
|
|
partHolder->addTab(mdlWidget, QStringLiteral("Model"));
|
2023-10-14 20:23:36 -04:00
|
|
|
} else if (info.completeSuffix() == QStringLiteral("tex") || info.completeSuffix() == QStringLiteral("atex")) {
|
2023-10-12 21:40:46 -04:00
|
|
|
auto texWidget = new TexPart(data);
|
|
|
|
texWidget->load(file);
|
|
|
|
partHolder->addTab(texWidget, QStringLiteral("Texture"));
|
2023-10-13 15:01:08 -04:00
|
|
|
} else if (info.completeSuffix() == QStringLiteral("shpk")) {
|
|
|
|
auto shpkWidget = new SHPKPart(data);
|
|
|
|
shpkWidget->load(file);
|
|
|
|
partHolder->addTab(shpkWidget, QStringLiteral("Shader Package"));
|
2023-10-13 15:20:01 -04:00
|
|
|
} else if (info.completeSuffix() == QStringLiteral("cmp")) {
|
|
|
|
auto cmpWidget = new CmpPart(data);
|
|
|
|
cmpWidget->load(file);
|
|
|
|
partHolder->addTab(cmpWidget, QStringLiteral("Chara Make Params"));
|
2023-10-13 15:36:36 -04:00
|
|
|
} else if (info.completeSuffix() == QStringLiteral("sklb")) {
|
|
|
|
auto sklbWidget = new SklbPart();
|
|
|
|
sklbWidget->load(physis_parse_skeleton(file));
|
|
|
|
partHolder->addTab(sklbWidget, QStringLiteral("Skeleton"));
|
2023-10-12 21:33:32 -04:00
|
|
|
}
|
2023-10-12 20:18:22 -04:00
|
|
|
|
|
|
|
auto hexWidget = new HexPart();
|
|
|
|
hexWidget->loadFile(file);
|
|
|
|
partHolder->addTab(hexWidget, QStringLiteral("Raw Hex"));
|
2023-10-12 21:33:32 -04:00
|
|
|
|
|
|
|
auto propertiesWidget = new FilePropertiesWindow(path, file);
|
|
|
|
partHolder->addTab(propertiesWidget, QStringLiteral("Properties"));
|
2022-04-14 08:24:06 -04:00
|
|
|
}
|
2024-02-02 14:25:32 -05:00
|
|
|
|
|
|
|
void MainWindow::setupFileMenu(QMenu *menu)
|
|
|
|
{
|
2024-02-03 10:04:25 -05:00
|
|
|
auto openList = menu->addAction(QStringLiteral("Import Path List..."));
|
2024-02-02 14:25:32 -05:00
|
|
|
openList->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
|
|
|
|
connect(openList, &QAction::triggered, [this] {
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(nullptr, QStringLiteral("Open Path List"), QStringLiteral("~"));
|
|
|
|
|
2024-02-03 10:04:25 -05:00
|
|
|
QMessageBox::warning(this,
|
|
|
|
QStringLiteral("Import Warning"),
|
|
|
|
QStringLiteral("Depending on the size of the import, this process usually takes a few minutes. The program may freeze. Please "
|
|
|
|
"keep it open until the operation is finished."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Ok);
|
|
|
|
|
|
|
|
m_database.importFileList(fileName);
|
|
|
|
|
|
|
|
QMessageBox::information(this, QStringLiteral("Import Complete"), QStringLiteral("Successfully imported path list!"), QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto downloadList = menu->addAction(QStringLiteral("Download Path List..."));
|
|
|
|
downloadList->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
|
|
|
|
connect(downloadList, &QAction::triggered, [this] {
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(nullptr, QStringLiteral("Open Path List"), QStringLiteral("~"));
|
|
|
|
|
2024-02-02 14:25:32 -05:00
|
|
|
m_database.importFileList(fileName);
|
|
|
|
});
|
|
|
|
}
|