diff options
author | TheKodeToad <TheKodeToad@proton.me> | 2023-06-19 22:42:27 +0100 |
---|---|---|
committer | TheKodeToad <TheKodeToad@proton.me> | 2023-06-19 22:42:30 +0100 |
commit | 6ccc7e77f918503125c363eb8ac9455aa9fc095e (patch) | |
tree | eebf279b43d2976a061865818d2144e0a0d70b46 /launcher/ui/dialogs | |
parent | fd9a8d1551e5736aff6da10d8d00cc631c6d6ee0 (diff) | |
download | PrismLauncher-6ccc7e77f918503125c363eb8ac9455aa9fc095e.tar.gz PrismLauncher-6ccc7e77f918503125c363eb8ac9455aa9fc095e.tar.bz2 PrismLauncher-6ccc7e77f918503125c363eb8ac9455aa9fc095e.zip |
Basic, unfinished & broken impl
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/ui/dialogs')
-rw-r--r-- | launcher/ui/dialogs/InstallLoaderDialog.cpp | 121 | ||||
-rw-r--r-- | launcher/ui/dialogs/InstallLoaderDialog.h | 42 | ||||
-rw-r--r-- | launcher/ui/dialogs/ResourceDownloadDialog.cpp | 26 | ||||
-rw-r--r-- | launcher/ui/dialogs/ResourceDownloadDialog.h | 3 |
4 files changed, 170 insertions, 22 deletions
diff --git a/launcher/ui/dialogs/InstallLoaderDialog.cpp b/launcher/ui/dialogs/InstallLoaderDialog.cpp new file mode 100644 index 00000000..34c91c68 --- /dev/null +++ b/launcher/ui/dialogs/InstallLoaderDialog.cpp @@ -0,0 +1,121 @@ +#include "InstallLoaderDialog.h" + +#include <QDialogButtonBox> +#include <QPushButton> +#include <QVBoxLayout> +#include "Application.h" +#include "BuildConfig.h" +#include "DesktopServices.h" +#include "meta/Index.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" +#include "ui/widgets/PageContainer.h" +#include "ui/widgets/VersionSelectWidget.h" + +class LoaderPage : public VersionSelectWidget, public BasePage { + public: + LoaderPage(const QString&& id, + const QString&& icon, + const QString&& name, + // "lightweight" loaders are independent to any game version + const bool lightweight, + const std::shared_ptr<PackProfile> profile, + QWidget* parent = nullptr) + : VersionSelectWidget(parent), m_id(std::move(id)), m_icon(std::move(icon)), m_name(std::move(name)) + { + const QString minecraftVersion = profile->getComponentVersion("net.minecraft"); + setEmptyErrorString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion)); + if (!lightweight) + setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion); + + if (const QString currentVersion = profile->getComponentVersion(id); !currentVersion.isNull()) + setCurrentVersion(currentVersion); + } + + QString id() const override { return m_id; } + QString displayName() const override { return m_name; } + QIcon icon() const override { return APPLICATION->getThemedIcon(m_icon); } + + void openedImpl() override + { + if (m_loaded) + return; + + const auto versions = APPLICATION->metadataIndex()->get(m_id); + if (!versions) + return; + + initialize(versions.get()); + m_loaded = true; + } + + private: + const QString m_id; + const QString m_icon; + const QString m_name; + bool m_loaded = false; +}; + +InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, QWidget* parent) + : QDialog(parent), m_profile(profile), m_container(new PageContainer(this)) +{ + auto layout = new QVBoxLayout(this); + + m_container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + layout->addWidget(m_container); + + auto buttonLayout = new QHBoxLayout(this); + + auto refreshButton = new QPushButton(tr("&Refresh"), this); + connect(refreshButton, &QPushButton::pressed, this, [this] { + LoaderPage* page = dynamic_cast<LoaderPage*>(m_container->selectedPage()); + Q_ASSERT(page != nullptr); + page->loadList(); + }); + buttonLayout->addWidget(refreshButton); + + auto buttons = new QDialogButtonBox(this); + buttons->setOrientation(Qt::Horizontal); + buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); + connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); + buttonLayout->addWidget(buttons); + + layout->addLayout(buttonLayout); + + setWindowTitle(dialogTitle()); + resize(650, 400); +} + +QList<BasePage*> InstallLoaderDialog::getPages() +{ + return { // Fabric + new LoaderPage("net.fabricmc.fabric-loader", "fabric-loader", tr("Fabric"), true, m_profile, this), + // Quilt + new LoaderPage("org.quiltmc.quilt-loader", "quilt-loader", tr("Quilt"), true, m_profile, this), + // Forge + new LoaderPage("net.minecraftforge", "forge-loader", tr("Forge"), false, m_profile, this), + // LiteLoader + new LoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), false, m_profile, this) + }; +} + +QString InstallLoaderDialog::dialogTitle() +{ + return tr("Install Loader"); +} + +void InstallLoaderDialog::done(int result) +{ + if (result == Accepted) { + LoaderPage* page = dynamic_cast<LoaderPage*>(m_container->selectedPage()); + Q_ASSERT(page != nullptr); + + if (page->selectedVersion()) { + m_profile->setComponentVersion(page->id(), page->selectedVersion()->descriptor()); + m_profile->resolve(Net::Mode::Online); + } + } + + QDialog::done(result); +} diff --git a/launcher/ui/dialogs/InstallLoaderDialog.h b/launcher/ui/dialogs/InstallLoaderDialog.h new file mode 100644 index 00000000..26b39e4a --- /dev/null +++ b/launcher/ui/dialogs/InstallLoaderDialog.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <QDialog> +#include "ui/pages/BasePageProvider.h" + +class MinecraftInstance; +class PageContainer; +class PackProfile; + +class InstallLoaderDialog : public QDialog, public BasePageProvider { + Q_OBJECT + + public: + explicit InstallLoaderDialog(std::shared_ptr<PackProfile> instance, QWidget* parent = nullptr); + + QList<BasePage*> getPages() override; + QString dialogTitle() override; + + void done(int result) override; + + private: + std::shared_ptr<PackProfile> m_profile; + PageContainer* m_container; +}; diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.cpp b/launcher/ui/dialogs/ResourceDownloadDialog.cpp index 6d90480f..784662a0 100644 --- a/launcher/ui/dialogs/ResourceDownloadDialog.cpp +++ b/launcher/ui/dialogs/ResourceDownloadDialog.cpp @@ -148,15 +148,17 @@ bool ResourceDownloadDialog::selectPage(QString pageId) return m_container->selectPage(pageId); } -ResourcePage* ResourceDownloadDialog::getSelectedPage() +ResourcePage* ResourceDownloadDialog::selectedPage() { - return m_selectedPage; + ResourcePage* result = dynamic_cast<ResourcePage*>(m_container->selectedPage()); + Q_ASSERT(result != nullptr); + return result; } void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& ver) { removeResource(pack->name); - m_selectedPage->addResourceToPage(pack, ver, getBaseModel()); + selectedPage()->addResourceToPage(pack, ver, getBaseModel()); setButtonStatus(); } @@ -196,14 +198,8 @@ void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* s return; } - m_selectedPage = dynamic_cast<ResourcePage*>(selected); - if (!m_selectedPage) { - qCritical() << "Page '" << selected->displayName() << "' in ResourceDownloadDialog is not a ResourcePage!"; - return; - } - // Same effect as having a global search bar - m_selectedPage->setSearchTerm(prev_page->getSearchTerm()); + selectedPage()->setSearchTerm(prev_page->getSearchTerm()); } ModDownloadDialog::ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance) @@ -226,8 +222,6 @@ QList<BasePage*> ModDownloadDialog::getPages() if (APPLICATION->capabilities() & Application::SupportsFlame) pages.append(FlameModPage::create(this, *m_instance)); - m_selectedPage = dynamic_cast<ModPage*>(pages[0]); - return pages; } @@ -253,8 +247,6 @@ QList<BasePage*> ResourcePackDownloadDialog::getPages() if (APPLICATION->capabilities() & Application::SupportsFlame) pages.append(FlameResourcePackPage::create(this, *m_instance)); - m_selectedPage = dynamic_cast<ResourcePackResourcePage*>(pages[0]); - return pages; } @@ -280,8 +272,6 @@ QList<BasePage*> TexturePackDownloadDialog::getPages() if (APPLICATION->capabilities() & Application::SupportsFlame) pages.append(FlameTexturePackPage::create(this, *m_instance)); - m_selectedPage = dynamic_cast<TexturePackResourcePage*>(pages[0]); - return pages; } @@ -302,11 +292,7 @@ ShaderPackDownloadDialog::ShaderPackDownloadDialog(QWidget* parent, QList<BasePage*> ShaderPackDownloadDialog::getPages() { QList<BasePage*> pages; - pages.append(ModrinthShaderPackPage::create(this, *m_instance)); - - m_selectedPage = dynamic_cast<ShaderPackResourcePage*>(pages[0]); - return pages; } diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.h b/launcher/ui/dialogs/ResourceDownloadDialog.h index 5b5b48c6..5077b2ca 100644 --- a/launcher/ui/dialogs/ResourceDownloadDialog.h +++ b/launcher/ui/dialogs/ResourceDownloadDialog.h @@ -60,7 +60,7 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider { QString dialogTitle() override { return tr("Download %1").arg(resourcesString()); }; bool selectPage(QString pageId); - ResourcePage* getSelectedPage(); + ResourcePage* selectedPage(); void addResource(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&); void removeResource(const QString&); @@ -85,7 +85,6 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider { const std::shared_ptr<ResourceFolderModel> m_base_model; PageContainer* m_container = nullptr; - ResourcePage* m_selectedPage = nullptr; QDialogButtonBox m_buttons; QVBoxLayout m_vertical_layout; |