diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 54932c2ee..a619743b3 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -66,7 +66,6 @@ #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) { @@ -147,8 +146,9 @@ void ModFolderPage::downloadMods() auto profile = static_cast(m_instance)->getPackProfile(); if (!profile->getModLoaders().has_value()) { - HandleNoModLoader(this); - return; + if (HandleNoModLoader()) { + return; + } } m_downloadDialog = new ResourceDownload::ModDownloadDialog(this, m_model, m_instance); @@ -203,8 +203,9 @@ void ModFolderPage::updateMods(bool includeDeps) auto profile = static_cast(m_instance)->getPackProfile(); if (!profile->getModLoaders().has_value()) { - HandleNoModLoader(this); - return; + if (HandleNoModLoader()) { + return; + } } if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) { QMessageBox::critical(this, tr("Error"), tr("Mod updates are unavailable when metadata is disabled!")); @@ -307,8 +308,9 @@ void ModFolderPage::changeModVersion() auto profile = static_cast(m_instance)->getPackProfile(); if (!profile->getModLoaders().has_value()) { - HandleNoModLoader(this); - return; + if (HandleNoModLoader()) { + return; + } } if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) { QMessageBox::critical(this, tr("Error"), tr("Mod updates are unavailable when metadata is disabled!")); @@ -389,28 +391,25 @@ bool NilModFolderPage::shouldDisplay() const } // Helper function so this doesn't need to be duplicated 3 times -inline void HandleNoModLoader(ModFolderPage* self) +inline bool ModFolderPage::HandleNoModLoader() { - // 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?"), + int resp = QMessageBox::question(this, this->tr("Missing ModLoader"), + this->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); + // Should be safe + auto profile = static_cast(this->m_instance)->getPackProfile(); + InstallLoaderDialog dialog(profile, QString(), this); dialog.exec(); - self->m_container->refreshContainer(); - break; + this->m_container->refreshContainer(); + // returning false so the caller can go and open up the dialog it was originally going to + return false; } case QMessageBox::No: { // Nothing happens the dialog is already closing - break; + // returning true so the caller doesn't go and continue with opening it's dialog without a mod loader + return true; } default: { // Unreachable diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index 6360c9739..296f1dd4e 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -45,7 +45,7 @@ class ModFolderPage : public ExternalResourcesPage { Q_OBJECT - friend void HandleNoModLoader(ModFolderPage* self); + bool HandleNoModLoader(); public: explicit ModFolderPage(BaseInstance* inst, std::shared_ptr model, QWidget* parent = nullptr);