diff options
author | TheKodeToad <TheKodeToad@proton.me> | 2023-07-03 17:32:59 +0100 |
---|---|---|
committer | TheKodeToad <TheKodeToad@proton.me> | 2023-07-03 17:39:09 +0100 |
commit | 0e5c37768084cf0772ca2598b4554bf262cb581b (patch) | |
tree | 953d5bf9b2e2bc18fffb2e82902c46233efbf588 /launcher/ui | |
parent | 6cc3587da2a87c87d37f205fd39a31a5a136814a (diff) | |
download | PrismLauncher-0e5c37768084cf0772ca2598b4554bf262cb581b.tar.gz PrismLauncher-0e5c37768084cf0772ca2598b4554bf262cb581b.tar.bz2 PrismLauncher-0e5c37768084cf0772ca2598b4554bf262cb581b.zip |
Various tweaks
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/ui')
-rw-r--r-- | launcher/ui/dialogs/InstallLoaderDialog.cpp | 78 | ||||
-rw-r--r-- | launcher/ui/dialogs/InstallLoaderDialog.h | 7 | ||||
-rw-r--r-- | launcher/ui/widgets/PageContainer.cpp | 2 | ||||
-rw-r--r-- | launcher/ui/widgets/PageContainer.h | 2 |
4 files changed, 52 insertions, 37 deletions
diff --git a/launcher/ui/dialogs/InstallLoaderDialog.cpp b/launcher/ui/dialogs/InstallLoaderDialog.cpp index acef60c6..31d6f9ab 100644 --- a/launcher/ui/dialogs/InstallLoaderDialog.cpp +++ b/launcher/ui/dialogs/InstallLoaderDialog.cpp @@ -38,7 +38,7 @@ class InstallLoaderPage : public VersionSelectWidget, public BasePage { // "lightweight" loaders are independent to any game version const bool lightweight, const std::shared_ptr<PackProfile> profile) - : VersionSelectWidget(nullptr), m_id(id), m_icon(icon), m_name(name) + : VersionSelectWidget(nullptr), uid(id), iconName(icon), name(name) { const QString minecraftVersion = profile->getComponentVersion("net.minecraft"); setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion)); @@ -49,21 +49,21 @@ class InstallLoaderPage : public VersionSelectWidget, public BasePage { 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); } + QString id() const override { return uid; } + QString displayName() const override { return name; } + QIcon icon() const override { return APPLICATION->getThemedIcon(iconName); } void openedImpl() override { - if (m_loaded) + if (loaded) return; - const auto versions = APPLICATION->metadataIndex()->get(m_id); + const auto versions = APPLICATION->metadataIndex()->get(uid); if (!versions) return; initialize(versions.get()); - m_loaded = true; + loaded = true; } void setParentContainer(BasePageContainer* container) override @@ -73,13 +73,13 @@ class InstallLoaderPage : public VersionSelectWidget, public BasePage { } private: - const QString m_id; - const QString m_icon; - const QString m_name; - bool m_loaded = false; + const QString uid; + const QString iconName; + const QString name; + bool loaded = false; }; -InstallLoaderPage* pageCast(BasePage* page) +static InstallLoaderPage* pageCast(BasePage* page) { auto result = dynamic_cast<InstallLoaderPage*>(page); Q_ASSERT(result != nullptr); @@ -87,46 +87,55 @@ InstallLoaderPage* pageCast(BasePage* page) } InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, const QString& uid, QWidget* parent) - : QDialog(parent), m_profile(profile), m_container(new PageContainer(this, QString(), this)), m_buttons(new QDialogButtonBox(this)) + : QDialog(parent), profile(std::move(profile)), container(new PageContainer(this, QString(), this)), buttons(new QDialogButtonBox(this)) { auto layout = new QVBoxLayout(this); - m_container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - layout->addWidget(m_container); + container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + layout->addWidget(container); auto buttonLayout = new QHBoxLayout(this); auto refreshButton = new QPushButton(tr("&Refresh"), this); - connect(refreshButton, &QPushButton::pressed, this, [this] { pageCast(m_container->selectedPage())->loadList(); }); + connect(refreshButton, &QPushButton::pressed, this, [this] { pageCast(container->selectedPage())->loadList(); }); buttonLayout->addWidget(refreshButton); - m_buttons->setOrientation(Qt::Horizontal); - m_buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); - connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); - buttonLayout->addWidget(m_buttons); + 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); + setWindowModality(Qt::WindowModal); + resize(520, 347); - pageCast(m_container->selectedPage())->selectSearch(); - for (BasePage* page : m_container->getPages()) + for (BasePage* page : container->getPages()) { if (page->id() == uid) - m_container->selectPage(page->id()); + container->selectPage(page->id()); + + connect(pageCast(page), &VersionSelectWidget::selectedVersionChanged, this, [this, page] { + if (page->id() == container->selectedPage()->id()) + validate(container->selectedPage()); + }); + } + connect(container, &PageContainer::selectedPageChanged, this, [this](BasePage* previous, BasePage* current) { validate(current); }); + pageCast(container->selectedPage())->selectSearch(); + validate(container->selectedPage()); } QList<BasePage*> InstallLoaderDialog::getPages() { return { // Forge - new InstallLoaderPage("net.minecraftforge", "forge", tr("Forge"), false, m_profile), + new InstallLoaderPage("net.minecraftforge", "forge", tr("Forge"), false, profile), // Fabric - new InstallLoaderPage("net.fabricmc.fabric-loader", "fabricmc-small", tr("Fabric"), true, m_profile), + new InstallLoaderPage("net.fabricmc.fabric-loader", "fabricmc-small", tr("Fabric"), true, profile), // Quilt - new InstallLoaderPage("org.quiltmc.quilt-loader", "quiltmc", tr("Quilt"), true, m_profile), + new InstallLoaderPage("org.quiltmc.quilt-loader", "quiltmc", tr("Quilt"), true, profile), // LiteLoader - new InstallLoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), false, m_profile) + new InstallLoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), false, profile) }; } @@ -135,13 +144,18 @@ QString InstallLoaderDialog::dialogTitle() return tr("Install Loader"); } +void InstallLoaderDialog::validate(BasePage* page) +{ + buttons->button(QDialogButtonBox::Ok)->setEnabled(pageCast(page)->selectedVersion() != nullptr); +} + void InstallLoaderDialog::done(int result) { if (result == Accepted) { - auto* page = pageCast(m_container->selectedPage()); + auto* page = pageCast(container->selectedPage()); if (page->selectedVersion()) { - m_profile->setComponentVersion(page->id(), page->selectedVersion()->descriptor()); - m_profile->resolve(Net::Mode::Online); + profile->setComponentVersion(page->id(), page->selectedVersion()->descriptor()); + profile->resolve(Net::Mode::Online); } } diff --git a/launcher/ui/dialogs/InstallLoaderDialog.h b/launcher/ui/dialogs/InstallLoaderDialog.h index 09d84777..cdcba2b9 100644 --- a/launcher/ui/dialogs/InstallLoaderDialog.h +++ b/launcher/ui/dialogs/InstallLoaderDialog.h @@ -35,10 +35,11 @@ class InstallLoaderDialog final : public QDialog, public BasePageProvider { QList<BasePage*> getPages() override; QString dialogTitle() override; + void validate(BasePage* page); void done(int result) override; private: - std::shared_ptr<PackProfile> m_profile; - PageContainer* m_container; - QDialogButtonBox* m_buttons; + std::shared_ptr<PackProfile> profile; + PageContainer* container; + QDialogButtonBox* buttons; }; diff --git a/launcher/ui/widgets/PageContainer.cpp b/launcher/ui/widgets/PageContainer.cpp index 0a8a0544..dbbed36a 100644 --- a/launcher/ui/widgets/PageContainer.cpp +++ b/launcher/ui/widgets/PageContainer.cpp @@ -147,7 +147,7 @@ BasePage* PageContainer::selectedPage() const return m_currentPage; } -const QList<BasePage*> PageContainer::getPages() const +const QList<BasePage*>& PageContainer::getPages() const { return m_model->pages(); } diff --git a/launcher/ui/widgets/PageContainer.h b/launcher/ui/widgets/PageContainer.h index bb365c82..eac59723 100644 --- a/launcher/ui/widgets/PageContainer.h +++ b/launcher/ui/widgets/PageContainer.h @@ -82,7 +82,7 @@ public: bool selectPage(QString pageId) override; BasePage* selectedPage() const override; BasePage* getPage(QString pageId) override; - const QList<BasePage*> getPages() const; + const QList<BasePage*>& getPages() const; void refreshContainer() override; virtual void setParentContainer(BasePageContainer * container) |