Skip to content

Commit

Permalink
Gear Editor: General code cleanup
Browse files Browse the repository at this point in the history
Boring stuff... removing unnecessary lambdas, variables and more.
  • Loading branch information
redstrate committed May 27, 2024
1 parent 0cf3735 commit 0a48880
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 75 deletions.
3 changes: 0 additions & 3 deletions apps/armoury/include/boneeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ class BoneEditor : public SklbPart

public:
explicit BoneEditor(GearView *gearView, QWidget *parent = nullptr);

private:
GearView *gearView = nullptr;
};
4 changes: 2 additions & 2 deletions apps/armoury/include/fullmodelviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

#pragma once

#include <QGroupBox>
#include <QMainWindow>

#include "boneeditor.h"
#include "gearview.h"

struct GameData;
class FileCache;
class QGroupBox;
class BoneEditor;

class FullModelViewer : public QMainWindow
{
Expand Down
10 changes: 5 additions & 5 deletions apps/armoury/include/gearlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class GearListModel : public QAbstractItemModel
public:
explicit GearListModel(GameData *data, QObject *parent = nullptr);

int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent) 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;

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

std::optional<GearInfo> getGearFromIndex(const QModelIndex &index);

Expand Down
2 changes: 0 additions & 2 deletions apps/armoury/include/singlegearview.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class SingleGearView : public QWidget
public:
explicit SingleGearView(GameData *data, FileCache &cache, QWidget *parent = nullptr);

QString getLoadedGearPath() const;
QList<physis_Material> getLoadedMaterials() const;

Q_SIGNALS:
Expand Down Expand Up @@ -62,7 +61,6 @@ private Q_SLOTS:
QComboBox *raceCombo, *subraceCombo, *genderCombo, *lodCombo;
QPushButton *addToFMVButton, *editButton, *importButton, *exportButton;

bool loadingComboData = false;
bool fmvAvailable = false;

GameData *data = nullptr;
Expand Down
5 changes: 1 addition & 4 deletions apps/armoury/src/boneeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@

BoneEditor::BoneEditor(GearView *gearView, QWidget *parent)
: SklbPart(parent)
, gearView(gearView)
{
connect(&gearView->part(), &MDLPart::skeletonChanged, this, [this, gearView] {
load(*gearView->part().skeleton);
});

connect(this, &SklbPart::valueChanged, this, [gearView] {
gearView->part().reloadRenderer();
});
connect(this, &SklbPart::valueChanged, &gearView->part(), &MDLPart::reloadRenderer);

if (gearView->part().skeleton) {
load(*gearView->part().skeleton);
Expand Down
5 changes: 3 additions & 2 deletions apps/armoury/src/fullmodelviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "fullmodelviewer.h"

#include "boneeditor.h"
#include "magic_enum.hpp"
#include <KLocalizedString>
#include <QCheckBox>
#include <QCloseEvent>
Expand All @@ -15,6 +13,9 @@
#include <QRadioButton>
#include <QVBoxLayout>

#include "boneeditor.h"
#include "magic_enum.hpp"

FullModelViewer::FullModelViewer(GameData *data, FileCache &cache, QWidget *parent)
: QMainWindow(parent)
, data(data)
Expand Down
6 changes: 3 additions & 3 deletions apps/armoury/src/gearlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GearListModel::GearListModel(GameData *data, QObject *parent)
connect(exdFuture, &QFutureWatcher<physis_EXD>::resultReadyAt, this, &GearListModel::exdFinished);
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++) {
pages.push_back(i);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ int GearListModel::rowCount(const QModelIndex &parent) const
else
parentItem = static_cast<TreeInformation *>(parent.internalPointer());

return parentItem->children.size();
return static_cast<int>(parentItem->children.size());
}

int GearListModel::columnCount(const QModelIndex &parent) const
Expand Down Expand Up @@ -134,7 +134,7 @@ QVariant GearListModel::data(const QModelIndex &index, int role) const
if (texFile.data != nullptr) {
auto tex = physis_texture_parse(texFile);
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;
pixmap.convertFromImage(image);
Expand Down
4 changes: 1 addition & 3 deletions apps/armoury/src/gearlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ GearListWidget::GearListWidget(GameData *data, QWidget *parent)
searchEdit->setPlaceholderText(i18nc("@info:placeholder Search through items", "Search…"));
searchEdit->setClearButtonEnabled(true);
searchEdit->setProperty("_breeze_borders_sides", QVariant::fromValue(QFlags{Qt::BottomEdge}));
connect(searchEdit, &QLineEdit::textChanged, this, [=](const QString &text) {
searchModel->setFilterRegularExpression(text);
});
connect(searchEdit, &QLineEdit::textChanged, searchModel, qOverload<const QString &>(&QSortFilterProxyModel::setFilterRegularExpression));
layout->addWidget(searchEdit);

auto originalModel = new GearListModel(data);
Expand Down
8 changes: 3 additions & 5 deletions apps/armoury/src/gearview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void GearView::addGear(GearInfo &gear)

queuedGearAdditions.emplace_back(gear);

for (auto loadedGear : loadedGears) {
for (const auto &loadedGear : loadedGears) {
if (loadedGear.info.slot == gear.slot) {
queuedGearRemovals.push_back(loadedGear);
}
Expand Down Expand Up @@ -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()
<< magic_enum::enum_name(currentGender).data();
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'});
std::string skelNameStd = skelName.toStdString();
Expand Down Expand Up @@ -297,7 +296,6 @@ void GearView::updatePart()
auto mdlPath = QLatin1String(
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);

// attempt to load the next best race
Expand All @@ -313,11 +311,11 @@ void GearView::updatePart()
}

if (fallbackRace != currentRace) {
qInfo() << "Fell back to hyur race for" << mdlPath;
qDebug() << "Fell back to hyur race for" << mdlPath;
}

if (fallbackSubrace != currentSubrace) {
qInfo() << "Fell back to midlander subrace for" << mdlPath;
qDebug() << "Fell back to midlander subrace for" << mdlPath;
}

if (mdl_data.size > 0) {
Expand Down
16 changes: 4 additions & 12 deletions apps/armoury/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ MainWindow::MainWindow(GameData *in_data)

auto gearListWidget = new GearListWidget(&data);
gearListWidget->setMaximumWidth(350);
connect(gearListWidget, &GearListWidget::gearSelected, this, [this](const GearInfo &gear) {
gearView->setGear(gear);
});
dummyWidget->addWidget(gearListWidget);

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(gearListWidget, &GearListWidget::gearSelected, gearView, &SingleGearView::setGear);

materialsView = new QTabWidget();

Expand All @@ -65,6 +60,7 @@ MainWindow::MainWindow(GameData *in_data)
connect(fullModelViewer, &FullModelViewer::loadingChanged, this, [this](const bool loading) {
gearView->setFMVAvailable(!loading);
});
connect(gearView, &SingleGearView::addToFullModelViewer, fullModelViewer, &FullModelViewer::addGear);

connect(gearView, &SingleGearView::doneLoadingModel, this, [this, in_data] {
materialsView->clear();
Expand Down Expand Up @@ -125,15 +121,11 @@ void MainWindow::setupActions()
actionCollection()->addAction(QStringLiteral("cmp_editor"), cmpEditorAction);

auto redrawAction = new QAction(i18nc("@action:inmenu", "Redraw All"));
connect(redrawAction, &QAction::triggered, [this] {
m_api->redrawAll();
});
connect(redrawAction, &QAction::triggered, m_api, &PenumbraApi::redrawAll);
actionCollection()->addAction(QStringLiteral("redraw_all"), redrawAction);

auto openWindowAction = new QAction(i18nc("@action:inmenu", "Open Window"));
connect(openWindowAction, &QAction::triggered, [this] {
m_api->openWindow();
});
connect(openWindowAction, &QAction::triggered, m_api, &PenumbraApi::openWindow);
actionCollection()->addAction(QStringLiteral("open_window"), openWindowAction);
}

Expand Down
46 changes: 12 additions & 34 deletions apps/armoury/src/singlegearview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <QDebug>
#include <QFileDialog>
#include <QLineEdit>
#include <QMenu>
Expand All @@ -20,17 +19,15 @@

SingleGearView::SingleGearView(GameData *data, FileCache &cache, QWidget *parent)
: QWidget(parent)
, gearView(new GearView(data, cache))
, data(data)
{
gearView = new GearView(data, cache);

// We don't want to see the face in this view
gearView->setHair(-1);
gearView->setEar(-1);
gearView->setFace(-1);

auto layout = new QVBoxLayout();
// layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);

auto mdlPathEdit = new QLineEdit();
Expand All @@ -51,36 +48,24 @@ SingleGearView::SingleGearView(GameData *data, FileCache &cache, QWidget *parent

raceCombo = new QComboBox();
connect(raceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;

setRace(static_cast<Race>(raceCombo->itemData(index).toInt()));
});
controlLayout->addWidget(raceCombo);

subraceCombo = new QComboBox();
connect(subraceCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;

setSubrace(static_cast<Subrace>(subraceCombo->itemData(index).toInt()));
});
controlLayout->addWidget(subraceCombo);

genderCombo = new QComboBox();
connect(genderCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;

setGender(static_cast<Gender>(genderCombo->itemData(index).toInt()));
});
controlLayout->addWidget(genderCombo);

lodCombo = new QComboBox();
connect(lodCombo, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
if (loadingComboData)
return;

setLevelOfDetail(index);
});
controlLayout->addWidget(lodCombo);
Expand Down Expand Up @@ -282,8 +267,6 @@ void SingleGearView::setSubrace(Subrace subrace)
return;
}

qInfo() << "Setting subrace to" << magic_enum::enum_name(subrace);

currentSubrace = subrace;
Q_EMIT subraceChanged();
}
Expand Down Expand Up @@ -321,7 +304,10 @@ void SingleGearView::reloadGear()
editButton->setEnabled(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 oldSubrace = static_cast<Subrace>(subraceCombo->itemData(subraceCombo->currentIndex()).toInt());
Expand Down Expand Up @@ -392,8 +378,6 @@ void SingleGearView::reloadGear()
if (oldLod < gearView->lodCount()) {
lodCombo->setCurrentIndex(oldLod);
}

loadingComboData = false;
}
}

Expand All @@ -405,11 +389,6 @@ void SingleGearView::setFMVAvailable(const bool available)
}
}

QString SingleGearView::getLoadedGearPath() const
{
return gearView->getLoadedGearPath();
}

void SingleGearView::importModel(const QString &filename)
{
auto &mdl = gearView->part().getModel(0);
Expand All @@ -418,14 +397,14 @@ void SingleGearView::importModel(const QString &filename)

gearView->part().reloadModel(0);

KConfig config(QStringLiteral("novusrc"));
KConfigGroup game = config.group(QStringLiteral("Armoury"));
QString outputDirectory = game.readEntry(QStringLiteral("PenumbraOutputDirectory"));
const KConfig config(QStringLiteral("novusrc"));
const KConfigGroup game = config.group(QStringLiteral("Armoury"));
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);
QFile file(QStringLiteral("%1/%2").arg(outputDirectory, gearView->getLoadedGearPath()));
QFile file(info.absoluteFilePath());

if (!QDir().exists(info.absolutePath()))
QDir().mkpath(info.absolutePath());
Expand All @@ -434,7 +413,6 @@ void SingleGearView::importModel(const QString &filename)
file.write(reinterpret_cast<char *>(buffer.data), buffer.size);
file.close();

qInfo() << "Successfully imported model!";
Q_EMIT importedModel();
}

Expand All @@ -443,8 +421,8 @@ QList<physis_Material> SingleGearView::getLoadedMaterials() const
QList<physis_Material> materialPaths;

for (int i = 0; i < gearView->part().numModels(); i++) {
auto model = gearView->part().getModel(i);
for (auto material : model.materials) {
const auto &model = gearView->part().getModel(i);
for (const auto &material : model.materials) {
materialPaths.push_back(material.mat);
}
}
Expand Down

0 comments on commit 0a48880

Please sign in to comment.