From 9ce773891229babff6008d19e2e1a5ee0c08f6ea Mon Sep 17 00:00:00 2001 From: Pagwin Date: Wed, 19 Nov 2025 10:43:52 -0500 Subject: [PATCH] Implemented #4369 Signed-off-by: Pagwin --- launcher/ui/pages/instance/ModFolderPage.cpp | 39 ++++++++++++++++++-- launcher/ui/pages/instance/ModFolderPage.h | 2 + 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 198f336f9..54932c2ee 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -38,6 +38,7 @@ #include "ModFolderPage.h" #include "ui/dialogs/ExportToModListDialog.h" +#include "ui/dialogs/InstallLoaderDialog.h" #include "ui_ExternalResourcesPage.h" #include @@ -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 model, QWidget* parent) : ExternalResourcesPage(inst, model, parent), m_model(model) { @@ -145,7 +147,7 @@ void ModFolderPage::downloadMods() auto profile = static_cast(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(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(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(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; + } + } +} diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index b33992470..6360c9739 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -45,6 +45,8 @@ class ModFolderPage : public ExternalResourcesPage { Q_OBJECT + friend void HandleNoModLoader(ModFolderPage* self); + public: explicit ModFolderPage(BaseInstance* inst, std::shared_ptr model, QWidget* parent = nullptr); virtual ~ModFolderPage() = default;