2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
#include "singlegearview.h"
|
|
|
|
|
2023-09-26 20:21:06 -04:00
|
|
|
#include <QDebug>
|
2023-04-09 15:31:19 -04:00
|
|
|
#include <QFileDialog>
|
2023-09-26 20:21:06 -04:00
|
|
|
#include <QLineEdit>
|
2023-07-07 16:16:21 -04:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
#include "filecache.h"
|
2023-04-09 15:31:19 -04:00
|
|
|
#include "magic_enum.hpp"
|
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
SingleGearView::SingleGearView(GameData* data, FileCache& cache) : data(data) {
|
|
|
|
gearView = new GearView(data, cache);
|
2023-09-23 14:09:25 -04:00
|
|
|
|
|
|
|
// We don't want to see the face in this view
|
2023-07-09 11:56:20 -04:00
|
|
|
gearView->setHair(-1);
|
|
|
|
gearView->setEar(-1);
|
|
|
|
gearView->setFace(-1);
|
2023-04-09 15:31:19 -04:00
|
|
|
|
|
|
|
auto layout = new QVBoxLayout();
|
2023-07-09 11:04:30 -04:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2023-04-09 15:31:19 -04:00
|
|
|
setLayout(layout);
|
|
|
|
|
2023-09-26 20:21:06 -04:00
|
|
|
auto mdlPathEdit = new QLineEdit();
|
|
|
|
mdlPathEdit->setReadOnly(true);
|
|
|
|
|
|
|
|
connect(this, &SingleGearView::gotMDLPath, this, [this, mdlPathEdit] {
|
|
|
|
mdlPathEdit->setText(gearView->getLoadedGearPath());
|
|
|
|
});
|
|
|
|
|
|
|
|
auto topControlLayout = new QHBoxLayout();
|
2023-04-09 15:31:19 -04:00
|
|
|
auto controlLayout = new QHBoxLayout();
|
2023-09-26 20:21:06 -04:00
|
|
|
|
|
|
|
layout->addWidget(mdlPathEdit);
|
2023-04-09 15:31:19 -04:00
|
|
|
layout->addLayout(controlLayout);
|
2023-09-26 20:21:06 -04:00
|
|
|
layout->addWidget(gearView);
|
|
|
|
layout->addLayout(topControlLayout);
|
2023-04-09 15:31:19 -04:00
|
|
|
|
|
|
|
raceCombo = new QComboBox();
|
2023-07-07 16:16:21 -04:00
|
|
|
connect(raceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (loadingComboData)
|
|
|
|
return;
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-09-23 14:09:25 -04:00
|
|
|
setRace(static_cast<Race>(raceCombo->itemData(index).toInt()));
|
2023-07-07 16:16:21 -04:00
|
|
|
});
|
2023-04-09 15:31:19 -04:00
|
|
|
controlLayout->addWidget(raceCombo);
|
|
|
|
|
2023-07-07 16:02:28 -04:00
|
|
|
subraceCombo = new QComboBox();
|
2023-07-07 16:16:21 -04:00
|
|
|
connect(subraceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (loadingComboData)
|
|
|
|
return;
|
2023-07-07 16:02:28 -04:00
|
|
|
|
2023-09-26 19:48:59 -04:00
|
|
|
setSubrace(static_cast<Subrace>(subraceCombo->itemData(index).toInt()));
|
2023-07-07 16:16:21 -04:00
|
|
|
});
|
2023-07-07 16:02:28 -04:00
|
|
|
controlLayout->addWidget(subraceCombo);
|
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
genderCombo = new QComboBox();
|
2023-07-07 16:16:21 -04:00
|
|
|
connect(genderCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (loadingComboData)
|
|
|
|
return;
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-09-23 14:09:25 -04:00
|
|
|
setGender(static_cast<Gender>(genderCombo->itemData(index).toInt()));
|
2023-07-07 16:16:21 -04:00
|
|
|
});
|
2023-04-09 15:31:19 -04:00
|
|
|
controlLayout->addWidget(genderCombo);
|
|
|
|
|
|
|
|
lodCombo = new QComboBox();
|
|
|
|
connect(lodCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
|
2023-07-07 16:16:21 -04:00
|
|
|
if (loadingComboData)
|
2023-04-09 15:31:19 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
setLevelOfDetail(index);
|
|
|
|
});
|
|
|
|
controlLayout->addWidget(lodCombo);
|
|
|
|
|
2023-09-26 00:37:55 -04:00
|
|
|
addToFMVButton = new QPushButton(QStringLiteral("Add to FMV"));
|
2023-09-26 20:21:06 -04:00
|
|
|
addToFMVButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add-user")));
|
2023-04-09 15:31:19 -04:00
|
|
|
connect(addToFMVButton, &QPushButton::clicked, this, [this](bool) {
|
2023-07-07 16:16:21 -04:00
|
|
|
if (currentGear.has_value()) {
|
2023-04-09 15:31:19 -04:00
|
|
|
Q_EMIT addToFullModelViewer(*currentGear);
|
|
|
|
}
|
|
|
|
});
|
2023-09-26 20:21:06 -04:00
|
|
|
|
|
|
|
importButton = new QPushButton(QStringLiteral("Import..."));
|
|
|
|
importButton->setIcon(QIcon::fromTheme(QStringLiteral("document-import")));
|
|
|
|
topControlLayout->addWidget(importButton);
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-09-26 00:37:55 -04:00
|
|
|
exportButton = new QPushButton(QStringLiteral("Export..."));
|
2023-09-26 20:21:06 -04:00
|
|
|
exportButton->setIcon(QIcon::fromTheme(QStringLiteral("document-export")));
|
2023-04-09 15:31:19 -04:00
|
|
|
connect(exportButton, &QPushButton::clicked, this, [this](bool) {
|
2023-09-23 14:09:25 -04:00
|
|
|
if (currentGear.has_value()) {
|
2023-09-26 21:26:19 -04:00
|
|
|
// TODO: deduplicate
|
|
|
|
const auto sanitizeMdlPath = [](const QString &mdlPath) -> QString {
|
|
|
|
return QString(mdlPath).section(QLatin1Char('/'), -1).remove(QStringLiteral(".mdl"));
|
|
|
|
};
|
|
|
|
|
|
|
|
const QString fileName = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Save Model"),
|
|
|
|
QStringLiteral("%1.glb").arg(sanitizeMdlPath(gearView->getLoadedGearPath())),
|
|
|
|
tr("glTF Binary File (*.glb)"));
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-09-23 14:09:25 -04:00
|
|
|
gearView->exportModel(fileName);
|
|
|
|
}
|
2023-04-09 15:31:19 -04:00
|
|
|
});
|
2023-09-26 20:21:06 -04:00
|
|
|
topControlLayout->addWidget(exportButton);
|
|
|
|
topControlLayout->addWidget(addToFMVButton);
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-09-26 19:48:59 -04:00
|
|
|
connect(gearView, &GearView::loadingChanged, this, [this](const bool loading) {
|
|
|
|
if (!loading) {
|
|
|
|
reloadGear();
|
2023-09-26 20:21:06 -04:00
|
|
|
Q_EMIT gotMDLPath();
|
2023-09-26 19:48:59 -04:00
|
|
|
}
|
|
|
|
});
|
2023-04-09 15:31:19 -04:00
|
|
|
connect(this, &SingleGearView::raceChanged, this, [=] {
|
|
|
|
gearView->setRace(currentRace);
|
|
|
|
});
|
2023-07-07 16:29:43 -04:00
|
|
|
connect(this, &SingleGearView::subraceChanged, this, [=] {
|
|
|
|
gearView->setSubrace(currentSubrace);
|
|
|
|
});
|
2023-04-09 15:31:19 -04:00
|
|
|
connect(this, &SingleGearView::genderChanged, this, [=] {
|
|
|
|
gearView->setGender(currentGender);
|
|
|
|
});
|
|
|
|
connect(this, &SingleGearView::levelOfDetailChanged, this, [=] {
|
|
|
|
gearView->setLevelOfDetail(currentLod);
|
|
|
|
});
|
|
|
|
|
|
|
|
reloadGear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SingleGearView::clear() {
|
2023-09-25 23:48:03 -04:00
|
|
|
if (currentGear) {
|
|
|
|
gearView->removeGear(*currentGear);
|
|
|
|
}
|
2023-04-09 15:31:19 -04:00
|
|
|
currentGear.reset();
|
|
|
|
|
|
|
|
Q_EMIT gearChanged();
|
|
|
|
}
|
|
|
|
|
2023-07-08 09:13:02 -04:00
|
|
|
void SingleGearView::setGear(const GearInfo& info) {
|
2023-09-25 23:48:03 -04:00
|
|
|
if (info != currentGear) {
|
|
|
|
if (currentGear) {
|
|
|
|
gearView->removeGear(*currentGear);
|
|
|
|
}
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2023-09-25 23:48:03 -04:00
|
|
|
currentGear = info;
|
|
|
|
gearView->addGear(*currentGear);
|
|
|
|
|
|
|
|
Q_EMIT gearChanged();
|
|
|
|
}
|
2023-04-09 15:31:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SingleGearView::setRace(Race race) {
|
|
|
|
if (currentRace == race) {
|
2023-07-07 16:16:21 -04:00
|
|
|
return;
|
2023-04-09 15:31:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
currentRace = race;
|
|
|
|
Q_EMIT raceChanged();
|
|
|
|
}
|
|
|
|
|
2023-07-07 16:02:28 -04:00
|
|
|
void SingleGearView::setSubrace(Subrace subrace) {
|
|
|
|
if (currentSubrace == subrace) {
|
2023-07-07 16:16:21 -04:00
|
|
|
return;
|
2023-07-07 16:02:28 -04:00
|
|
|
}
|
|
|
|
|
2023-09-26 19:48:59 -04:00
|
|
|
qInfo() << "Setting subrace to" << magic_enum::enum_name(subrace);
|
|
|
|
|
2023-07-07 16:02:28 -04:00
|
|
|
currentSubrace = subrace;
|
|
|
|
Q_EMIT subraceChanged();
|
|
|
|
}
|
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
void SingleGearView::setGender(Gender gender) {
|
|
|
|
if (currentGender == gender) {
|
2023-07-07 16:16:21 -04:00
|
|
|
return;
|
2023-04-09 15:31:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
currentGender = gender;
|
|
|
|
Q_EMIT genderChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SingleGearView::setLevelOfDetail(int lod) {
|
|
|
|
if (currentLod == lod) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentLod = lod;
|
|
|
|
Q_EMIT levelOfDetailChanged();
|
|
|
|
}
|
|
|
|
|
2023-09-25 23:48:03 -04:00
|
|
|
void SingleGearView::reloadGear()
|
|
|
|
{
|
2023-04-09 15:31:19 -04:00
|
|
|
raceCombo->setEnabled(currentGear.has_value());
|
2023-07-07 16:29:43 -04:00
|
|
|
subraceCombo->setEnabled(currentGear.has_value());
|
2023-04-09 15:31:19 -04:00
|
|
|
genderCombo->setEnabled(currentGear.has_value());
|
|
|
|
lodCombo->setEnabled(currentGear.has_value());
|
2023-09-25 23:48:03 -04:00
|
|
|
addToFMVButton->setEnabled(currentGear.has_value() && fmvAvailable);
|
2023-04-09 15:31:19 -04:00
|
|
|
exportButton->setEnabled(currentGear.has_value());
|
|
|
|
|
|
|
|
if (currentGear.has_value()) {
|
|
|
|
loadingComboData = true;
|
|
|
|
|
2023-09-23 14:09:25 -04:00
|
|
|
const auto oldRace = static_cast<Race>(raceCombo->itemData(raceCombo->currentIndex()).toInt());
|
|
|
|
const auto oldSubrace = static_cast<Subrace>(subraceCombo->itemData(subraceCombo->currentIndex()).toInt());
|
|
|
|
const auto oldGender = static_cast<Gender>(genderCombo->itemData(genderCombo->currentIndex()).toInt());
|
|
|
|
const auto oldLod = lodCombo->itemData(lodCombo->currentIndex()).toInt();
|
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
raceCombo->clear();
|
2023-07-07 16:02:28 -04:00
|
|
|
subraceCombo->clear();
|
2023-09-23 14:09:25 -04:00
|
|
|
raceCombo->setCurrentIndex(0);
|
|
|
|
subraceCombo->setCurrentIndex(0);
|
|
|
|
|
|
|
|
const auto supportedRaces = gearView->supportedRaces();
|
|
|
|
QList<Race> addedRaces;
|
|
|
|
for (auto [race, subrace] : supportedRaces) {
|
|
|
|
// TODO: supportedRaces should be designed better
|
|
|
|
if (!addedRaces.contains(race)) {
|
2023-09-26 19:48:59 -04:00
|
|
|
raceCombo->addItem(QLatin1String(magic_enum::enum_name(race).data()), static_cast<int>(race));
|
2023-09-23 14:09:25 -04:00
|
|
|
addedRaces.push_back(race);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto it = std::find_if(supportedRaces.begin(), supportedRaces.end(), [oldRace](auto p) { return std::get<0>(p) == oldRace; }); it != supportedRaces.end()) {
|
|
|
|
raceCombo->setCurrentIndex(std::distance(supportedRaces.begin(), it));
|
|
|
|
}
|
|
|
|
|
2023-09-26 19:48:59 -04:00
|
|
|
const Race selectedRace = static_cast<Race>(raceCombo->currentData().toInt());
|
|
|
|
for (auto [race, subrace] : supportedRaces) {
|
|
|
|
if (race == selectedRace) {
|
|
|
|
subraceCombo->addItem(QLatin1String(magic_enum::enum_name(subrace).data()), static_cast<int>(subrace));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-23 14:09:25 -04:00
|
|
|
if (auto it = std::find_if(supportedRaces.begin(), supportedRaces.end(), [oldSubrace](auto p) { return std::get<1>(p) == oldSubrace; }); it != supportedRaces.end()) {
|
|
|
|
subraceCombo->setCurrentIndex(std::distance(supportedRaces.begin(), it));
|
2023-04-09 15:31:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
genderCombo->clear();
|
2023-09-23 14:09:25 -04:00
|
|
|
genderCombo->setCurrentIndex(0);
|
|
|
|
|
|
|
|
const auto supportedGenders = gearView->supportedGenders();
|
|
|
|
for (auto gender : supportedGenders) {
|
2023-09-26 19:48:59 -04:00
|
|
|
genderCombo->addItem(QLatin1String(magic_enum::enum_name(gender).data()), static_cast<int>(gender));
|
2023-09-23 14:09:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (auto it = std::find_if(supportedGenders.begin(), supportedGenders.end(), [oldGender](auto p) { return p == oldGender; }); it != supportedGenders.end()) {
|
|
|
|
genderCombo->setCurrentIndex(std::distance(supportedGenders.begin(), it));
|
2023-04-09 15:31:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
lodCombo->clear();
|
2023-09-23 14:09:25 -04:00
|
|
|
for (int i = 0; i < gearView->lodCount(); i++) {
|
|
|
|
lodCombo->addItem(QStringLiteral("LOD %1").arg(i), i);
|
|
|
|
}
|
2023-09-26 19:48:59 -04:00
|
|
|
if (oldLod < gearView->lodCount()) {
|
|
|
|
lodCombo->setCurrentIndex(oldLod);
|
|
|
|
}
|
2023-04-09 15:31:19 -04:00
|
|
|
|
|
|
|
loadingComboData = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-25 23:48:03 -04:00
|
|
|
void SingleGearView::setFMVAvailable(const bool available)
|
|
|
|
{
|
|
|
|
if (fmvAvailable != available) {
|
|
|
|
fmvAvailable = available;
|
|
|
|
addToFMVButton->setEnabled(currentGear.has_value() && available);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 20:21:06 -04:00
|
|
|
QString SingleGearView::getLoadedGearPath() const
|
|
|
|
{
|
|
|
|
return gearView->getLoadedGearPath();
|
|
|
|
}
|
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
#include "moc_singlegearview.cpp"
|