From 17bf05971b95384bfb5adf4956f35c314d057e3a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 26 Sep 2023 21:26:19 -0400 Subject: [PATCH] armoury: Suggest a better model name, take off the .mdl extension --- armoury/src/gearview.cpp | 14 +++++++++----- armoury/src/singlegearview.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/armoury/src/gearview.cpp b/armoury/src/gearview.cpp index a6e578c..d5d2cdb 100644 --- a/armoury/src/gearview.cpp +++ b/armoury/src/gearview.cpp @@ -276,6 +276,10 @@ void GearView::updatePart() gearDirty = true; } + const auto sanitizeMdlPath = [](const QLatin1String mdlPath) -> QString { + return QString(mdlPath).section(QLatin1Char('/'), -1).remove(QStringLiteral(".mdl")); + }; + if (gearDirty) { for (auto &gearAddition : queuedGearAdditions) { auto mdlPath = QLatin1String( @@ -320,7 +324,7 @@ void GearView::updatePart() maxLod = std::max(mdl.num_lod, maxLod); - mdlPart->addModel(mdl, QString(mdlPath).section(QLatin1Char('/'), -1), materials, currentLod); + mdlPart->addModel(mdl, sanitizeMdlPath(mdlPath), materials, currentLod); gearAddition.mdl = mdl; gearAddition.path = mdlPath; loadedGears.push_back(gearAddition); @@ -356,7 +360,7 @@ void GearView::updatePart() } } - mdlPart->addModel(mdl, QString(mdlPath).section(QLatin1Char('/'), -1), materials, currentLod); + mdlPart->addModel(mdl, sanitizeMdlPath(mdlPath), materials, currentLod); } } @@ -378,7 +382,7 @@ void GearView::updatePart() } } - mdlPart->addModel(mdl, QString(mdlPath).section(QLatin1Char('/'), -1), materials, currentLod); + mdlPart->addModel(mdl, sanitizeMdlPath(mdlPath), materials, currentLod); } } @@ -400,7 +404,7 @@ void GearView::updatePart() } } - mdlPart->addModel(mdl, QString(mdlPath).section(QLatin1Char('/'), -1), materials, currentLod); + mdlPart->addModel(mdl, sanitizeMdlPath(mdlPath), materials, currentLod); } } @@ -416,7 +420,7 @@ void GearView::updatePart() if (cache.fileExists(QLatin1String(skinmtrl_path.c_str()))) { auto mat = physis_material_parse(cache.lookupFile(QLatin1String(skinmtrl_path.c_str()))); - mdlPart->addModel(mdl, QString(mdlPath).section(QLatin1Char('/'), -1), {mat}, currentLod); + mdlPart->addModel(mdl, sanitizeMdlPath(mdlPath), {mat}, currentLod); } } } diff --git a/armoury/src/singlegearview.cpp b/armoury/src/singlegearview.cpp index ecce76a..c3e6356 100644 --- a/armoury/src/singlegearview.cpp +++ b/armoury/src/singlegearview.cpp @@ -91,7 +91,15 @@ SingleGearView::SingleGearView(GameData* data, FileCache& cache) : data(data) { exportButton->setIcon(QIcon::fromTheme(QStringLiteral("document-export"))); connect(exportButton, &QPushButton::clicked, this, [this](bool) { if (currentGear.has_value()) { - QString fileName = QFileDialog::getSaveFileName(this, tr("Save Model"), QStringLiteral("model.glb"), tr("glTF Binary File (*.glb)")); + // 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)")); gearView->exportModel(fileName); }