From e0ab8207ed3614bf078cc2d79f154afeb9d45737 Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 2 Apr 2022 18:29:35 -0300 Subject: [PATCH] feat: Add dialog to filter mod options in mod download --- launcher/CMakeLists.txt | 3 + launcher/ui/dialogs/FilterModsDialog.cpp | 75 ++++++++++ launcher/ui/dialogs/FilterModsDialog.h | 54 +++++++ launcher/ui/dialogs/FilterModsDialog.ui | 181 +++++++++++++++++++++++ 4 files changed, 313 insertions(+) create mode 100644 launcher/ui/dialogs/FilterModsDialog.cpp create mode 100644 launcher/ui/dialogs/FilterModsDialog.h create mode 100644 launcher/ui/dialogs/FilterModsDialog.ui diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 42348792..8579071a 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -824,6 +824,8 @@ SET(LAUNCHER_SOURCES ui/dialogs/SkinUploadDialog.h ui/dialogs/ModDownloadDialog.cpp ui/dialogs/ModDownloadDialog.h + ui/dialogs/FilterModsDialog.cpp + ui/dialogs/FilterModsDialog.h # GUI - widgets @@ -923,6 +925,7 @@ qt5_wrap_ui(LAUNCHER_UI ui/dialogs/LoginDialog.ui ui/dialogs/EditAccountDialog.ui ui/dialogs/ReviewMessageBox.ui + ui/dialogs/FilterModsDialog.ui ) qt5_add_resources(LAUNCHER_RESOURCES diff --git a/launcher/ui/dialogs/FilterModsDialog.cpp b/launcher/ui/dialogs/FilterModsDialog.cpp new file mode 100644 index 00000000..a36f4ba4 --- /dev/null +++ b/launcher/ui/dialogs/FilterModsDialog.cpp @@ -0,0 +1,75 @@ +#include "FilterModsDialog.h" +#include "ui_FilterModsDialog.h" + +FilterModsDialog::FilterModsDialog(Version def, QWidget* parent) + : QDialog(parent), m_filter(new Filter()), ui(new Ui::FilterModsDialog) +{ + ui->setupUi(this); + + m_mcVersion_buttons.addButton(ui->strictVersionButton, VersionButtonID::Strict); + m_mcVersion_buttons.addButton(ui->majorVersionButton, VersionButtonID::Major); + m_mcVersion_buttons.addButton(ui->allVersionsButton, VersionButtonID::All); + m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between); + + connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int))); + + m_filter->versions.push_front(def); +} + +int FilterModsDialog::execWithInstance(MinecraftInstance* instance) +{ + m_instance = instance; + + // Fix first openening behaviour + onVersionFilterChanged(0); + + auto mcVersionSplit = mcVersionStr().split("."); + + ui->strictVersionButton->setText( + tr("Strict match (= %1)").arg(mcVersionStr())); + ui->majorVersionButton->setText( + tr("Major varsion match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); + ui->allVersionsButton->setText( + tr("Any version match")); + ui->betweenVersionsButton->setText( + tr("Between two versions")); + + int ret = QDialog::exec(); + m_instance = nullptr; + return ret; +} + +void FilterModsDialog::onVersionFilterChanged(int id) +{ + ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); + ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); + + auto versionSplit = mcVersionStr().split("."); + int index = 0; + + m_filter->versions.clear(); + + switch(id){ + case(VersionButtonID::Strict): + m_filter->versions.push_front(mcVersion()); + break; + case(VersionButtonID::Major): + for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){ + m_filter->versions.push_front(i); + i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index))); + } + break; + case(VersionButtonID::All): + break; + case(VersionButtonID::Between): + // TODO + break; + default: + break; + } +} + +FilterModsDialog::~FilterModsDialog() +{ + delete ui; +} diff --git a/launcher/ui/dialogs/FilterModsDialog.h b/launcher/ui/dialogs/FilterModsDialog.h new file mode 100644 index 00000000..b119e8e5 --- /dev/null +++ b/launcher/ui/dialogs/FilterModsDialog.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include + +#include "Version.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" + +class MinecraftInstance; + +namespace Ui { +class FilterModsDialog; +} + +class FilterModsDialog : public QDialog +{ + Q_OBJECT +public: + struct Filter { + std::list versions; + }; + + std::shared_ptr m_filter; + +public: + explicit FilterModsDialog(Version def, QWidget* parent = nullptr); + ~FilterModsDialog(); + + int execWithInstance(MinecraftInstance* instance); + + auto getFilter() -> std::shared_ptr { return m_filter; } + +private: + enum VersionButtonID { + Strict = 0, + Major = 1, + All = 2, + Between = 3 + }; + + inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; } + inline auto mcVersion() const -> Version { return { mcVersionStr() }; } + +private slots: + void onVersionFilterChanged(int id); + +private: + Ui::FilterModsDialog* ui; + + MinecraftInstance* m_instance = nullptr; + + QButtonGroup m_mcVersion_buttons; +}; diff --git a/launcher/ui/dialogs/FilterModsDialog.ui b/launcher/ui/dialogs/FilterModsDialog.ui new file mode 100644 index 00000000..da368aac --- /dev/null +++ b/launcher/ui/dialogs/FilterModsDialog.ui @@ -0,0 +1,181 @@ + + + FilterModsDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 345 + 323 + + + + Copy Instance + + + + :/icons/toolbar/copy:/icons/toolbar/copy + + + true + + + true + + + + + + + 0 + 0 + + + + Minecraft versions + + + false + + + false + + + + + + QLayout::SetDefaultConstraint + + + + + + + StrictVersion + + + true + + + + + + + MajorVersion + + + + + + + AllVersions + + + + + + + + + + + + + BetweenVersions + + + + + + + From + + + + + + + + + + To + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + FilterModsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + FilterModsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +