Signed-off-by: Pagwin <dev@pagwin.xyz>
This commit is contained in:
Pagwin
2025-11-19 10:43:52 -05:00
parent 4c437a839c
commit 9ce7738912
2 changed files with 38 additions and 3 deletions

View File

@@ -38,6 +38,7 @@
#include "ModFolderPage.h"
#include "ui/dialogs/ExportToModListDialog.h"
#include "ui/dialogs/InstallLoaderDialog.h"
#include "ui_ExternalResourcesPage.h"
#include <QAbstractItemModel>
@@ -65,6 +66,7 @@
#include "tasks/Task.h"
#include "ui/dialogs/ProgressDialog.h"
inline void HandleNoModLoader(ModFolderPage* self);
ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> model, QWidget* parent)
: ExternalResourcesPage(inst, model, parent), m_model(model)
{
@@ -145,7 +147,7 @@ void ModFolderPage::downloadMods()
auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
if (!profile->getModLoaders().has_value()) {
QMessageBox::critical(this, tr("Error"), tr("Please install a mod loader first!"));
HandleNoModLoader(this);
return;
}
@@ -201,7 +203,7 @@ void ModFolderPage::updateMods(bool includeDeps)
auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
if (!profile->getModLoaders().has_value()) {
QMessageBox::critical(this, tr("Error"), tr("Please install a mod loader first!"));
HandleNoModLoader(this);
return;
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
@@ -305,7 +307,7 @@ void ModFolderPage::changeModVersion()
auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
if (!profile->getModLoaders().has_value()) {
QMessageBox::critical(this, tr("Error"), tr("Please install a mod loader first!"));
HandleNoModLoader(this);
return;
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
@@ -385,3 +387,34 @@ bool NilModFolderPage::shouldDisplay() const
{
return m_model->dir().exists();
}
// Helper function so this doesn't need to be duplicated 3 times
inline void HandleNoModLoader(ModFolderPage* self)
{
// QMessageBox::critical(self, tr("Error"), tr("Please install a mod loader first!"));
int resp = QMessageBox::question(self, self->tr("Missing ModLoader"),
self->tr("You need to install a mod loader before installing mods, would you like to do so?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
switch (resp) {
case QMessageBox::Yes: {
// now how do I get the values this all needs
if (self->m_instance->typeName() != "Minecraft") {
// not what we need
return;
}
auto profile = static_cast<MinecraftInstance*>(self->m_instance)->getPackProfile();
InstallLoaderDialog dialog(profile, QString(), self);
dialog.exec();
self->m_container->refreshContainer();
break;
}
case QMessageBox::No: {
// Nothing happens the dialog is already closing
break;
}
default: {
// Unreachable
break;
}
}
}

View File

@@ -45,6 +45,8 @@
class ModFolderPage : public ExternalResourcesPage {
Q_OBJECT
friend void HandleNoModLoader(ModFolderPage* self);
public:
explicit ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> model, QWidget* parent = nullptr);
virtual ~ModFolderPage() = default;