1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-26 13:47:46 +00:00

Gear Editor: General code cleanup

Boring stuff... removing unnecessary lambdas, variables and more.
This commit is contained in:
Joshua Goins 2024-05-27 18:57:17 -04:00
parent 0cf37355cb
commit 0a488807f6
11 changed files with 34 additions and 75 deletions

View file

@ -13,7 +13,4 @@ class BoneEditor : public SklbPart
public: public:
explicit BoneEditor(GearView *gearView, QWidget *parent = nullptr); explicit BoneEditor(GearView *gearView, QWidget *parent = nullptr);
private:
GearView *gearView = nullptr;
}; };

View file

@ -3,14 +3,14 @@
#pragma once #pragma once
#include <QGroupBox>
#include <QMainWindow> #include <QMainWindow>
#include "boneeditor.h"
#include "gearview.h" #include "gearview.h"
struct GameData; struct GameData;
class FileCache; class FileCache;
class QGroupBox;
class BoneEditor;
class FullModelViewer : public QMainWindow class FullModelViewer : public QMainWindow
{ {

View file

@ -27,14 +27,14 @@ class GearListModel : public QAbstractItemModel
public: public:
explicit GearListModel(GameData *data, QObject *parent = nullptr); explicit GearListModel(GameData *data, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent) const override;
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override; QModelIndex parent(const QModelIndex &child) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
std::optional<GearInfo> getGearFromIndex(const QModelIndex &index); std::optional<GearInfo> getGearFromIndex(const QModelIndex &index);

View file

@ -17,7 +17,6 @@ class SingleGearView : public QWidget
public: public:
explicit SingleGearView(GameData *data, FileCache &cache, QWidget *parent = nullptr); explicit SingleGearView(GameData *data, FileCache &cache, QWidget *parent = nullptr);
QString getLoadedGearPath() const;
QList<physis_Material> getLoadedMaterials() const; QList<physis_Material> getLoadedMaterials() const;
Q_SIGNALS: Q_SIGNALS:
@ -62,7 +61,6 @@ private:
QComboBox *raceCombo, *subraceCombo, *genderCombo, *lodCombo; QComboBox *raceCombo, *subraceCombo, *genderCombo, *lodCombo;
QPushButton *addToFMVButton, *editButton, *importButton, *exportButton; QPushButton *addToFMVButton, *editButton, *importButton, *exportButton;
bool loadingComboData = false;
bool fmvAvailable = false; bool fmvAvailable = false;
GameData *data = nullptr; GameData *data = nullptr;

View file

@ -7,15 +7,12 @@
BoneEditor::BoneEditor(GearView *gearView, QWidget *parent) BoneEditor::BoneEditor(GearView *gearView, QWidget *parent)
: SklbPart(parent) : SklbPart(parent)
, gearView(gearView)
{ {
connect(&gearView->part(), &MDLPart::skeletonChanged, this, [this, gearView] { connect(&gearView->part(), &MDLPart::skeletonChanged, this, [this, gearView] {
load(*gearView->part().skeleton); load(*gearView->part().skeleton);
}); });
connect(this, &SklbPart::valueChanged, this, [gearView] { connect(this, &SklbPart::valueChanged, &gearView->part(), &MDLPart::reloadRenderer);
gearView->part().reloadRenderer();
});
if (gearView->part().skeleton) { if (gearView->part().skeleton) {
load(*gearView->part().skeleton); load(*gearView->part().skeleton);

View file

@ -3,8 +3,6 @@
#include "fullmodelviewer.h" #include "fullmodelviewer.h"
#include "boneeditor.h"
#include "magic_enum.hpp"
#include <KLocalizedString> #include <KLocalizedString>
#include <QCheckBox> #include <QCheckBox>
#include <QCloseEvent> #include <QCloseEvent>
@ -15,6 +13,9 @@
#include <QRadioButton> #include <QRadioButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "boneeditor.h"
#include "magic_enum.hpp"
FullModelViewer::FullModelViewer(GameData *data, FileCache &cache, QWidget *parent) FullModelViewer::FullModelViewer(GameData *data, FileCache &cache, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, data(data) , data(data)

View file

@ -35,7 +35,7 @@ GearListModel::GearListModel(GameData *data, QObject *parent)
connect(exdFuture, &QFutureWatcher<physis_EXD>::resultReadyAt, this, &GearListModel::exdFinished); connect(exdFuture, &QFutureWatcher<physis_EXD>::resultReadyAt, this, &GearListModel::exdFinished);
connect(exdFuture, &QFutureWatcher<physis_EXD>::finished, this, &GearListModel::finished); connect(exdFuture, &QFutureWatcher<physis_EXD>::finished, this, &GearListModel::finished);
QVector<int> pages; QVector<uint32_t> pages;
for (uint32_t i = 0; i < exh->page_count; i++) { for (uint32_t i = 0; i < exh->page_count; i++) {
pages.push_back(i); pages.push_back(i);
} }
@ -65,7 +65,7 @@ int GearListModel::rowCount(const QModelIndex &parent) const
else else
parentItem = static_cast<TreeInformation *>(parent.internalPointer()); parentItem = static_cast<TreeInformation *>(parent.internalPointer());
return parentItem->children.size(); return static_cast<int>(parentItem->children.size());
} }
int GearListModel::columnCount(const QModelIndex &parent) const int GearListModel::columnCount(const QModelIndex &parent) const
@ -134,7 +134,7 @@ QVariant GearListModel::data(const QModelIndex &index, int role) const
if (texFile.data != nullptr) { if (texFile.data != nullptr) {
auto tex = physis_texture_parse(texFile); auto tex = physis_texture_parse(texFile);
if (tex.rgba != nullptr) { if (tex.rgba != nullptr) {
QImage image(tex.rgba, tex.width, tex.height, QImage::Format_RGBA8888); QImage image(tex.rgba, static_cast<int>(tex.width), static_cast<int>(tex.height), QImage::Format_RGBA8888);
QPixmap pixmap; QPixmap pixmap;
pixmap.convertFromImage(image); pixmap.convertFromImage(image);

View file

@ -28,9 +28,7 @@ GearListWidget::GearListWidget(GameData *data, QWidget *parent)
searchEdit->setPlaceholderText(i18nc("@info:placeholder Search through items", "Search…")); searchEdit->setPlaceholderText(i18nc("@info:placeholder Search through items", "Search…"));
searchEdit->setClearButtonEnabled(true); searchEdit->setClearButtonEnabled(true);
searchEdit->setProperty("_breeze_borders_sides", QVariant::fromValue(QFlags{Qt::BottomEdge})); searchEdit->setProperty("_breeze_borders_sides", QVariant::fromValue(QFlags{Qt::BottomEdge}));
connect(searchEdit, &QLineEdit::textChanged, this, [=](const QString &text) { connect(searchEdit, &QLineEdit::textChanged, searchModel, qOverload<const QString &>(&QSortFilterProxyModel::setFilterRegularExpression));
searchModel->setFilterRegularExpression(text);
});
layout->addWidget(searchEdit); layout->addWidget(searchEdit);
auto originalModel = new GearListModel(data); auto originalModel = new GearListModel(data);

View file

@ -108,7 +108,7 @@ void GearView::addGear(GearInfo &gear)
queuedGearAdditions.emplace_back(gear); queuedGearAdditions.emplace_back(gear);
for (auto loadedGear : loadedGears) { for (const auto &loadedGear : loadedGears) {
if (loadedGear.info.slot == gear.slot) { if (loadedGear.info.slot == gear.slot) {
queuedGearRemovals.push_back(loadedGear); queuedGearRemovals.push_back(loadedGear);
} }
@ -265,7 +265,6 @@ void GearView::reloadRaceDeforms()
qDebug() << "Loading race deform matrices for " << magic_enum::enum_name(currentRace).data() << magic_enum::enum_name(currentSubrace).data() qDebug() << "Loading race deform matrices for " << magic_enum::enum_name(currentRace).data() << magic_enum::enum_name(currentSubrace).data()
<< magic_enum::enum_name(currentGender).data(); << magic_enum::enum_name(currentGender).data();
const int raceCode = physis_get_race_code(currentRace, currentSubrace, currentGender); const int raceCode = physis_get_race_code(currentRace, currentSubrace, currentGender);
qDebug() << "Race code: " << raceCode;
QString skelName = QStringLiteral("chara/human/c%1/skeleton/base/b0001/skl_c%1b0001.sklb").arg(raceCode, 4, 10, QLatin1Char{'0'}); QString skelName = QStringLiteral("chara/human/c%1/skeleton/base/b0001/skl_c%1b0001.sklb").arg(raceCode, 4, 10, QLatin1Char{'0'});
std::string skelNameStd = skelName.toStdString(); std::string skelNameStd = skelName.toStdString();
@ -297,7 +296,6 @@ void GearView::updatePart()
auto mdlPath = QLatin1String( auto mdlPath = QLatin1String(
physis_build_equipment_path(gearAddition.info.modelInfo.primaryID, currentRace, currentSubrace, currentGender, gearAddition.info.slot)); physis_build_equipment_path(gearAddition.info.modelInfo.primaryID, currentRace, currentSubrace, currentGender, gearAddition.info.slot));
qInfo() << "Looking up" << magic_enum::enum_name(currentRace) << magic_enum::enum_name(currentSubrace) << magic_enum::enum_name(currentGender);
auto mdl_data = cache.lookupFile(mdlPath); auto mdl_data = cache.lookupFile(mdlPath);
// attempt to load the next best race // attempt to load the next best race
@ -313,11 +311,11 @@ void GearView::updatePart()
} }
if (fallbackRace != currentRace) { if (fallbackRace != currentRace) {
qInfo() << "Fell back to hyur race for" << mdlPath; qDebug() << "Fell back to hyur race for" << mdlPath;
} }
if (fallbackSubrace != currentSubrace) { if (fallbackSubrace != currentSubrace) {
qInfo() << "Fell back to midlander subrace for" << mdlPath; qDebug() << "Fell back to midlander subrace for" << mdlPath;
} }
if (mdl_data.size > 0) { if (mdl_data.size > 0) {

View file

@ -38,16 +38,11 @@ MainWindow::MainWindow(GameData *in_data)
auto gearListWidget = new GearListWidget(&data); auto gearListWidget = new GearListWidget(&data);
gearListWidget->setMaximumWidth(350); gearListWidget->setMaximumWidth(350);
connect(gearListWidget, &GearListWidget::gearSelected, this, [this](const GearInfo &gear) {
gearView->setGear(gear);
});
dummyWidget->addWidget(gearListWidget); dummyWidget->addWidget(gearListWidget);
gearView = new SingleGearView(&data, cache); gearView = new SingleGearView(&data, cache);
connect(gearView, &SingleGearView::addToFullModelViewer, this, [this](GearInfo &info) {
fullModelViewer->addGear(info);
});
connect(gearView, &SingleGearView::importedModel, m_api, &PenumbraApi::redrawAll); connect(gearView, &SingleGearView::importedModel, m_api, &PenumbraApi::redrawAll);
connect(gearListWidget, &GearListWidget::gearSelected, gearView, &SingleGearView::setGear);
materialsView = new QTabWidget(); materialsView = new QTabWidget();
@ -65,6 +60,7 @@ MainWindow::MainWindow(GameData *in_data)
connect(fullModelViewer, &FullModelViewer::loadingChanged, this, [this](const bool loading) { connect(fullModelViewer, &FullModelViewer::loadingChanged, this, [this](const bool loading) {
gearView->setFMVAvailable(!loading); gearView->setFMVAvailable(!loading);
}); });
connect(gearView, &SingleGearView::addToFullModelViewer, fullModelViewer, &FullModelViewer::addGear);
connect(gearView, &SingleGearView::doneLoadingModel, this, [this, in_data] { connect(gearView, &SingleGearView::doneLoadingModel, this, [this, in_data] {
materialsView->clear(); materialsView->clear();
@ -125,15 +121,11 @@ void MainWindow::setupActions()
actionCollection()->addAction(QStringLiteral("cmp_editor"), cmpEditorAction); actionCollection()->addAction(QStringLiteral("cmp_editor"), cmpEditorAction);
auto redrawAction = new QAction(i18nc("@action:inmenu", "Redraw All")); auto redrawAction = new QAction(i18nc("@action:inmenu", "Redraw All"));
connect(redrawAction, &QAction::triggered, [this] { connect(redrawAction, &QAction::triggered, m_api, &PenumbraApi::redrawAll);
m_api->redrawAll();
});
actionCollection()->addAction(QStringLiteral("redraw_all"), redrawAction); actionCollection()->addAction(QStringLiteral("redraw_all"), redrawAction);
auto openWindowAction = new QAction(i18nc("@action:inmenu", "Open Window")); auto openWindowAction = new QAction(i18nc("@action:inmenu", "Open Window"));
connect(openWindowAction, &QAction::triggered, [this] { connect(openWindowAction, &QAction::triggered, m_api, &PenumbraApi::openWindow);
m_api->openWindow();
});
actionCollection()->addAction(QStringLiteral("open_window"), openWindowAction); actionCollection()->addAction(QStringLiteral("open_window"), openWindowAction);
} }

View file

@ -6,7 +6,6 @@
#include <KConfig> #include <KConfig>
#include <KConfigGroup> #include <KConfigGroup>
#include <KLocalizedString> #include <KLocalizedString>
#include <QDebug>
#include <QFileDialog> #include <QFileDialog>
#include <QLineEdit> #include <QLineEdit>
#include <QMenu> #include <QMenu>
@ -20,17 +19,15 @@
SingleGearView::SingleGearView(GameData *data, FileCache &cache, QWidget *parent) SingleGearView::SingleGearView(GameData *data, FileCache &cache, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, gearView(new GearView(data, cache))
, data(data) , data(data)
{ {
gearView = new GearView(data, cache);
// We don't want to see the face in this view // We don't want to see the face in this view
gearView->setHair(-1); gearView->setHair(-1);
gearView->setEar(-1); gearView->setEar(-1);
gearView->setFace(-1); gearView->setFace(-1);
auto layout = new QVBoxLayout(); auto layout = new QVBoxLayout();
// layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout); setLayout(layout);
auto mdlPathEdit = new QLineEdit(); auto mdlPathEdit = new QLineEdit();
@ -51,36 +48,24 @@ SingleGearView::SingleGearView(GameData *data, FileCache &cache, QWidget *parent
raceCombo = new QComboBox(); raceCombo = new QComboBox();
connect(raceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) { connect(raceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;
setRace(static_cast<Race>(raceCombo->itemData(index).toInt())); setRace(static_cast<Race>(raceCombo->itemData(index).toInt()));
}); });
controlLayout->addWidget(raceCombo); controlLayout->addWidget(raceCombo);
subraceCombo = new QComboBox(); subraceCombo = new QComboBox();
connect(subraceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) { connect(subraceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;
setSubrace(static_cast<Subrace>(subraceCombo->itemData(index).toInt())); setSubrace(static_cast<Subrace>(subraceCombo->itemData(index).toInt()));
}); });
controlLayout->addWidget(subraceCombo); controlLayout->addWidget(subraceCombo);
genderCombo = new QComboBox(); genderCombo = new QComboBox();
connect(genderCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) { connect(genderCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;
setGender(static_cast<Gender>(genderCombo->itemData(index).toInt())); setGender(static_cast<Gender>(genderCombo->itemData(index).toInt()));
}); });
controlLayout->addWidget(genderCombo); controlLayout->addWidget(genderCombo);
lodCombo = new QComboBox(); lodCombo = new QComboBox();
connect(lodCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) { connect(lodCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;
setLevelOfDetail(index); setLevelOfDetail(index);
}); });
controlLayout->addWidget(lodCombo); controlLayout->addWidget(lodCombo);
@ -282,8 +267,6 @@ void SingleGearView::setSubrace(Subrace subrace)
return; return;
} }
qInfo() << "Setting subrace to" << magic_enum::enum_name(subrace);
currentSubrace = subrace; currentSubrace = subrace;
Q_EMIT subraceChanged(); Q_EMIT subraceChanged();
} }
@ -321,7 +304,10 @@ void SingleGearView::reloadGear()
editButton->setEnabled(currentGear.has_value()); editButton->setEnabled(currentGear.has_value());
if (currentGear.has_value()) { if (currentGear.has_value()) {
loadingComboData = true; QSignalBlocker raceBlocker(raceCombo);
QSignalBlocker subraceBlocker(subraceCombo);
QSignalBlocker genderBlocker(genderCombo);
QSignalBlocker lodBlocker(lodCombo);
const auto oldRace = static_cast<Race>(raceCombo->itemData(raceCombo->currentIndex()).toInt()); const auto oldRace = static_cast<Race>(raceCombo->itemData(raceCombo->currentIndex()).toInt());
const auto oldSubrace = static_cast<Subrace>(subraceCombo->itemData(subraceCombo->currentIndex()).toInt()); const auto oldSubrace = static_cast<Subrace>(subraceCombo->itemData(subraceCombo->currentIndex()).toInt());
@ -392,8 +378,6 @@ void SingleGearView::reloadGear()
if (oldLod < gearView->lodCount()) { if (oldLod < gearView->lodCount()) {
lodCombo->setCurrentIndex(oldLod); lodCombo->setCurrentIndex(oldLod);
} }
loadingComboData = false;
} }
} }
@ -405,11 +389,6 @@ void SingleGearView::setFMVAvailable(const bool available)
} }
} }
QString SingleGearView::getLoadedGearPath() const
{
return gearView->getLoadedGearPath();
}
void SingleGearView::importModel(const QString &filename) void SingleGearView::importModel(const QString &filename)
{ {
auto &mdl = gearView->part().getModel(0); auto &mdl = gearView->part().getModel(0);
@ -418,14 +397,14 @@ void SingleGearView::importModel(const QString &filename)
gearView->part().reloadModel(0); gearView->part().reloadModel(0);
KConfig config(QStringLiteral("novusrc")); const KConfig config(QStringLiteral("novusrc"));
KConfigGroup game = config.group(QStringLiteral("Armoury")); const KConfigGroup game = config.group(QStringLiteral("Armoury"));
QString outputDirectory = game.readEntry(QStringLiteral("PenumbraOutputDirectory")); const QDir outputDirectory = game.readEntry(QStringLiteral("PenumbraOutputDirectory"));
QFileInfo info(QStringLiteral("%1/%2").arg(outputDirectory, gearView->getLoadedGearPath())); const QFileInfo info(outputDirectory.absoluteFilePath(gearView->getLoadedGearPath()));
auto buffer = physis_mdl_write(&mdl.model); auto buffer = physis_mdl_write(&mdl.model);
QFile file(QStringLiteral("%1/%2").arg(outputDirectory, gearView->getLoadedGearPath())); QFile file(info.absoluteFilePath());
if (!QDir().exists(info.absolutePath())) if (!QDir().exists(info.absolutePath()))
QDir().mkpath(info.absolutePath()); QDir().mkpath(info.absolutePath());
@ -434,7 +413,6 @@ void SingleGearView::importModel(const QString &filename)
file.write(reinterpret_cast<char *>(buffer.data), buffer.size); file.write(reinterpret_cast<char *>(buffer.data), buffer.size);
file.close(); file.close();
qInfo() << "Successfully imported model!";
Q_EMIT importedModel(); Q_EMIT importedModel();
} }
@ -443,8 +421,8 @@ QList<physis_Material> SingleGearView::getLoadedMaterials() const
QList<physis_Material> materialPaths; QList<physis_Material> materialPaths;
for (int i = 0; i < gearView->part().numModels(); i++) { for (int i = 0; i < gearView->part().numModels(); i++) {
auto model = gearView->part().getModel(i); const auto &model = gearView->part().getModel(i);
for (auto material : model.materials) { for (const auto &material : model.materials) {
materialPaths.push_back(material.mat); materialPaths.push_back(material.mat);
} }
} }