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"
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
2023-07-07 16:16:21 -04:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
2023-09-23 14:09:25 -04:00
|
|
|
#include <QDebug>
|
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
|
|
|
layout->addWidget(gearView);
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
auto controlLayout = new QHBoxLayout();
|
|
|
|
layout->addLayout(controlLayout);
|
|
|
|
|
|
|
|
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-23 14:09:25 -04:00
|
|
|
setSubrace(static_cast<Subrace>(raceCombo->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-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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
controlLayout->addWidget(addToFMVButton);
|
|
|
|
|
2023-09-26 00:37:55 -04:00
|
|
|
exportButton = new QPushButton(QStringLiteral("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 00:37:55 -04:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Model"), QStringLiteral("model.glb"), 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
|
|
|
});
|
|
|
|
controlLayout->addWidget(exportButton);
|
|
|
|
|
|
|
|
connect(this, &SingleGearView::gearChanged, this, &SingleGearView::reloadGear);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 00:37:55 -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);
|
|
|
|
}
|
2023-09-26 00:37:55 -04:00
|
|
|
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(), [oldRace](auto p) { return std::get<0>(p) == oldRace; }); it != supportedRaces.end()) {
|
|
|
|
raceCombo->setCurrentIndex(std::distance(supportedRaces.begin(), it));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 00:37:55 -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-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-04-09 15:31:19 -04:00
|
|
|
#include "moc_singlegearview.cpp"
|