1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-21 03:57:44 +00:00
novus/mdlviewer/src/singlegearview.cpp
Joshua Goins 7407d26247 Overhaul mdlviewer to use the MDL part, and add the full model viewer
This is a major code overhaul for mdlviewer, which will make it easier
to extend and modify in the future (trust me, the old code was garbage).

The different views are now split up (SingleGearView, FullModelViewer,
and MDLPart) which makes the functionality easier to handle, and less
error-prone.

Right now bone debugging is disabled (not that it worked that well
anyway) but will be brought back in a future commit.
2023-04-09 15:31:19 -04:00

149 lines
No EOL
3.9 KiB
C++

#include "singlegearview.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include "magic_enum.hpp"
SingleGearView::SingleGearView(GameData* data) : data(data) {
gearView = new GearView(data);
auto layout = new QVBoxLayout();
layout->addWidget(gearView);
setLayout(layout);
auto controlLayout = new QHBoxLayout();
layout->addLayout(controlLayout);
raceCombo = new QComboBox();
connect(raceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if(loadingComboData)
return;
setRace((Race)index);
});
controlLayout->addWidget(raceCombo);
genderCombo = new QComboBox();
connect(genderCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if(loadingComboData)
return;
setGender((Gender)index);
});
controlLayout->addWidget(genderCombo);
lodCombo = new QComboBox();
connect(lodCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if(loadingComboData)
return;
setLevelOfDetail(index);
});
controlLayout->addWidget(lodCombo);
addToFMVButton = new QPushButton("Add to FMV");
connect(addToFMVButton, &QPushButton::clicked, this, [this](bool) {
if(currentGear.has_value()) {
Q_EMIT addToFullModelViewer(*currentGear);
}
});
controlLayout->addWidget(addToFMVButton);
exportButton = new QPushButton("Export...");
connect(exportButton, &QPushButton::clicked, this, [this](bool) {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Model"),
"model.fbx",
tr("FBX Files (*.fbx)"));
gearView->exportModel(fileName);
});
controlLayout->addWidget(exportButton);
connect(this, &SingleGearView::gearChanged, this, &SingleGearView::reloadGear);
connect(this, &SingleGearView::raceChanged, this, [=] {
gearView->setRace(currentRace);
});
connect(this, &SingleGearView::genderChanged, this, [=] {
gearView->setGender(currentGender);
});
connect(this, &SingleGearView::levelOfDetailChanged, this, [=] {
gearView->setLevelOfDetail(currentLod);
});
reloadGear();
}
void SingleGearView::clear() {
currentGear.reset();
Q_EMIT gearChanged();
}
void SingleGearView::setGear(GearInfo &info) {
currentGear = info;
Q_EMIT gearChanged();
}
void SingleGearView::setRace(Race race) {
if (currentRace == race) {
return;
}
currentRace = race;
Q_EMIT raceChanged();
}
void SingleGearView::setGender(Gender gender) {
if (currentGender == gender) {
return;
}
currentGender = gender;
Q_EMIT genderChanged();
}
void SingleGearView::setLevelOfDetail(int lod) {
if (currentLod == lod) {
return;
}
currentLod = lod;
Q_EMIT levelOfDetailChanged();
}
void SingleGearView::reloadGear() {
gearView->clear();
raceCombo->setEnabled(currentGear.has_value());
genderCombo->setEnabled(currentGear.has_value());
lodCombo->setEnabled(currentGear.has_value());
addToFMVButton->setEnabled(currentGear.has_value());
exportButton->setEnabled(currentGear.has_value());
if (currentGear.has_value()) {
gearView->addGear(*currentGear);
loadingComboData = true;
raceCombo->clear();
for(auto race : gearView->supportedRaces()) {
raceCombo->addItem(magic_enum::enum_name(race).data());
}
genderCombo->clear();
for(auto gender : gearView->supportedGenders()) {
genderCombo->addItem(magic_enum::enum_name(gender).data());
}
lodCombo->clear();
for(int i = 0; i < gearView->lodCount(); i++)
lodCombo->addItem(QString::number(i));
loadingComboData = false;
}
}
#include "moc_singlegearview.cpp"