From 8406c7f431009d7e81b0b0e9e1daddcaf82d8324 Mon Sep 17 00:00:00 2001 From: Kenneth Chew Date: Mon, 4 Apr 2022 19:30:27 -0400 Subject: [PATCH] Add option to install mod loader during instance creation --- launcher/InstanceCreationTask.cpp | 11 + launcher/InstanceCreationTask.h | 4 + launcher/ui/pages/modplatform/VanillaPage.cpp | 71 +++- launcher/ui/pages/modplatform/VanillaPage.h | 7 + launcher/ui/pages/modplatform/VanillaPage.ui | 311 ++++++++++++------ 5 files changed, 303 insertions(+), 101 deletions(-) diff --git a/launcher/InstanceCreationTask.cpp b/launcher/InstanceCreationTask.cpp index 4c37bd7f..24bc5f46 100644 --- a/launcher/InstanceCreationTask.cpp +++ b/launcher/InstanceCreationTask.cpp @@ -9,6 +9,15 @@ InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version) { m_version = version; + m_usingLoader = false; +} + +InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version, QString loader, BaseVersionPtr loaderVersion) +{ + m_version = version; + m_usingLoader = true; + m_loader = loader; + m_loaderVersion = loaderVersion; } void InstanceCreationTask::executeTask() @@ -21,6 +30,8 @@ void InstanceCreationTask::executeTask() auto components = inst.getPackProfile(); components->buildingFromScratch(); components->setComponentVersion("net.minecraft", m_version->descriptor(), true); + if(m_usingLoader) + components->setComponentVersion(m_loader, m_loaderVersion->descriptor(), true); inst.setName(m_instName); inst.setIconKey(m_instIcon); instanceSettings->resumeSave(); diff --git a/launcher/InstanceCreationTask.h b/launcher/InstanceCreationTask.h index 54997116..23367c3f 100644 --- a/launcher/InstanceCreationTask.h +++ b/launcher/InstanceCreationTask.h @@ -12,6 +12,7 @@ class InstanceCreationTask : public InstanceTask Q_OBJECT public: explicit InstanceCreationTask(BaseVersionPtr version); + explicit InstanceCreationTask(BaseVersionPtr version, QString loader, BaseVersionPtr loaderVersion); protected: //! Entry point for tasks. @@ -19,4 +20,7 @@ protected: private: /* data */ BaseVersionPtr m_version; + bool m_usingLoader; + QString m_loader; + BaseVersionPtr m_loaderVersion; }; diff --git a/launcher/ui/pages/modplatform/VanillaPage.cpp b/launcher/ui/pages/modplatform/VanillaPage.cpp index c691128f..959e695c 100644 --- a/launcher/ui/pages/modplatform/VanillaPage.cpp +++ b/launcher/ui/pages/modplatform/VanillaPage.cpp @@ -59,6 +59,11 @@ VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent) connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); connect(ui->experimentsFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh); + + connect(ui->loaderVersionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedLoaderVersion); + connect(ui->loaderBtnGroup, &QButtonGroup::idToggled, this, &VanillaPage::loaderFilterChanged); + connect(ui->loaderRefreshBtn, &QPushButton::clicked, this, &VanillaPage::loaderRefresh); + } void VanillaPage::openedImpl() @@ -80,6 +85,13 @@ void VanillaPage::refresh() ui->versionList->loadList(); } +void VanillaPage::loaderRefresh() +{ + if(ui->noneFilter->isChecked()) + return; + ui->loaderVersionList->loadList(); +} + void VanillaPage::filterChanged() { QStringList out; @@ -99,6 +111,38 @@ void VanillaPage::filterChanged() ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false)); } +void VanillaPage::loaderFilterChanged() +{ + if(ui->noneFilter->isChecked()) + { + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // empty list + // TODO: The below message does not show when the add instance window is first opened. This should be fixed. + ui->loaderVersionList->setEmptyString(tr("No mod loader is selected.")); + return; + } + else if(ui->forgeFilter->isChecked()) + { + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, m_selectedVersion->descriptor()); + m_selectedLoader = "net.minecraftforge"; + } + else if(ui->fabricFilter->isChecked()) + { + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, ""); + m_selectedLoader = "net.fabricmc.fabric-loader"; + } + else if(ui->liteLoaderFilter->isChecked()) + { + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, m_selectedVersion->descriptor()); + m_selectedLoader = "com.mumfrey.liteloader"; + } + + auto vlist = APPLICATION->metadataIndex()->get(m_selectedLoader); + ui->loaderVersionList->initialize(vlist.get()); + ui->loaderVersionList->selectRecommended(); + suggestCurrent(); + ui->loaderVersionList->setEmptyString(tr("No versions are currently available for Minecraft %1").arg(m_selectedVersion->descriptor())); +} + VanillaPage::~VanillaPage() { delete ui; @@ -119,6 +163,16 @@ BaseVersionPtr VanillaPage::selectedVersion() const return m_selectedVersion; } +BaseVersionPtr VanillaPage::selectedLoaderVersion() const +{ + return m_selectedLoaderVersion; +} + +QString VanillaPage::selectedLoader() const +{ + return m_selectedLoader; +} + void VanillaPage::suggestCurrent() { if (!isOpened) @@ -132,7 +186,15 @@ void VanillaPage::suggestCurrent() return; } - dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion)); + // List is empty if either no mod loader is selected, or no versions are available + if(!ui->loaderVersionList->hasVersions()) + dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion)); + else + { + dialog->setSuggestedPack(m_selectedVersion->descriptor(), + new InstanceCreationTask(m_selectedVersion, m_selectedLoader, + m_selectedLoaderVersion)); + } dialog->setSuggestedIcon("default"); } @@ -140,4 +202,11 @@ void VanillaPage::setSelectedVersion(BaseVersionPtr version) { m_selectedVersion = version; suggestCurrent(); + loaderFilterChanged(); +} + +void VanillaPage::setSelectedLoaderVersion(BaseVersionPtr version) +{ + m_selectedLoaderVersion = version; + suggestCurrent(); } diff --git a/launcher/ui/pages/modplatform/VanillaPage.h b/launcher/ui/pages/modplatform/VanillaPage.h index 4e7479df..7193597d 100644 --- a/launcher/ui/pages/modplatform/VanillaPage.h +++ b/launcher/ui/pages/modplatform/VanillaPage.h @@ -77,15 +77,20 @@ public: void openedImpl() override; BaseVersionPtr selectedVersion() const; + BaseVersionPtr selectedLoaderVersion() const; + QString selectedLoader() const; public slots: void setSelectedVersion(BaseVersionPtr version); + void setSelectedLoaderVersion(BaseVersionPtr version); private slots: void filterChanged(); + void loaderFilterChanged(); private: void refresh(); + void loaderRefresh(); void suggestCurrent(); private: @@ -94,4 +99,6 @@ private: Ui::VanillaPage *ui = nullptr; bool m_versionSetByUser = false; BaseVersionPtr m_selectedVersion; + BaseVersionPtr m_selectedLoaderVersion; + QString m_selectedLoader; }; diff --git a/launcher/ui/pages/modplatform/VanillaPage.ui b/launcher/ui/pages/modplatform/VanillaPage.ui index 870ff161..97724ea8 100644 --- a/launcher/ui/pages/modplatform/VanillaPage.ui +++ b/launcher/ui/pages/modplatform/VanillaPage.ui @@ -33,113 +33,221 @@ - - - - - - Filter - - - Qt::AlignCenter - - - - - - - Releases - - - true - - - true - - - - - - - Snapshots - - - true - - - - - - - Old Snapshots - - - true - - - - - - - Betas - - - true - - - - - - - Alphas - - - true - - - - - - - Experiments - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Refresh - - - - - - - + + - + 0 0 + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + + + + + + Filter + + + Qt::AlignCenter + + + + + + + Releases + + + true + + + true + + + + + + + Snapshots + + + true + + + + + + + Old Snapshots + + + true + + + + + + + Betas + + + true + + + + + + + Alphas + + + true + + + + + + + Experiments + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Refresh + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + Mod Loader + + + Qt::AlignCenter + + + + + + + None + + + true + + + loaderBtnGroup + + + + + + + Forge + + + loaderBtnGroup + + + + + + + Fabric + + + loaderBtnGroup + + + + + + + LiteLoader + + + loaderBtnGroup + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Refresh + + + + + + + @@ -166,4 +274,7 @@ + + +