diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index fa8234ff..a87e2a7c 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -735,12 +735,14 @@ SET(LAUNCHER_SOURCES ui/pages/modplatform/atlauncher/AtlPage.cpp ui/pages/modplatform/atlauncher/AtlPage.h - ui/pages/modplatform/ftb/FtbFilterModel.cpp - ui/pages/modplatform/ftb/FtbFilterModel.h - ui/pages/modplatform/ftb/FtbListModel.cpp - ui/pages/modplatform/ftb/FtbListModel.h - ui/pages/modplatform/ftb/FtbPage.cpp - ui/pages/modplatform/ftb/FtbPage.h + ui/pages/modplatform/modpacksch/MCHFilterModel.cpp + ui/pages/modplatform/modpacksch/MCHFilterModel.h + ui/pages/modplatform/modpacksch/MCHListModel.cpp + ui/pages/modplatform/modpacksch/MCHListModel.h + ui/pages/modplatform/modpacksch/FtbPage.cpp + ui/pages/modplatform/modpacksch/FtbPage.h + ui/pages/modplatform/modpacksch/CursePage.cpp + ui/pages/modplatform/modpacksch/CursePage.h ui/pages/modplatform/legacy_ftb/Page.cpp ui/pages/modplatform/legacy_ftb/Page.h @@ -881,7 +883,8 @@ qt5_wrap_ui(LAUNCHER_UI ui/pages/modplatform/flame/FlamePage.ui ui/pages/modplatform/legacy_ftb/Page.ui ui/pages/modplatform/ImportPage.ui - ui/pages/modplatform/ftb/FtbPage.ui + ui/pages/modplatform/modpacksch/FtbPage.ui + ui/pages/modplatform/modpacksch/CursePage.ui ui/pages/modplatform/modrinth/ModrinthPage.ui ui/pages/modplatform/technic/TechnicPage.ui ui/widgets/InstanceCardWidget.ui diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index 5bce16fb..b82631f5 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -30,7 +30,7 @@ class PackInstallTask : public InstanceTask Q_OBJECT public: - explicit PackInstallTask(Modpack pack, QString version, PackType type = PackType::ModpacksCH); + explicit PackInstallTask(Modpack pack, QString version, PackType type = PackType::FTB); virtual ~PackInstallTask(){} bool canAbort() const override { return true; } diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.h b/launcher/modplatform/modpacksch/FTBPackManifest.h index da45d8ac..cf10a561 100644 --- a/launcher/modplatform/modpacksch/FTBPackManifest.h +++ b/launcher/modplatform/modpacksch/FTBPackManifest.h @@ -22,6 +22,7 @@ #include #include #include +#include "MCHPackType.h" namespace ModpacksCH { @@ -72,16 +73,17 @@ struct VersionInfo struct Modpack { - int id; + PackType packType = PackType::FTB; + int id = 0; QString name; QString synopsis; QString description; QString type; - bool featured; - int installs; - int plays; - int64_t updated; - int64_t refreshed; + bool featured = false; + int installs = 0; + int plays = 0; + int64_t updated = 0; + int64_t refreshed = 0; QVector art; QVector authors; QVector versions; diff --git a/launcher/modplatform/modpacksch/MCHPackType.cpp b/launcher/modplatform/modpacksch/MCHPackType.cpp index a03f4bf3..76344218 100644 --- a/launcher/modplatform/modpacksch/MCHPackType.cpp +++ b/launcher/modplatform/modpacksch/MCHPackType.cpp @@ -23,7 +23,7 @@ namespace ModpacksCH { QString getRealmForPackType(PackType type) { switch (type) { - case PackType::ModpacksCH: + case PackType::FTB: return "modpack"; case PackType::CurseForge: return "curseforge"; diff --git a/launcher/modplatform/modpacksch/MCHPackType.h b/launcher/modplatform/modpacksch/MCHPackType.h index cb7b2554..15742a0e 100644 --- a/launcher/modplatform/modpacksch/MCHPackType.h +++ b/launcher/modplatform/modpacksch/MCHPackType.h @@ -21,7 +21,7 @@ namespace ModpacksCH { enum class PackType { - ModpacksCH, + FTB, CurseForge, }; diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 05ea091d..e8966cd8 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -35,7 +35,8 @@ #include "ui/widgets/PageContainer.h" #include "ui/pages/modplatform/VanillaPage.h" #include "ui/pages/modplatform/atlauncher/AtlPage.h" -#include "ui/pages/modplatform/ftb/FtbPage.h" +#include "ui/pages/modplatform/modpacksch/FtbPage.h" +#include "ui/pages/modplatform/modpacksch/CursePage.h" #include "ui/pages/modplatform/legacy_ftb/Page.h" #include "ui/pages/modplatform/flame/FlamePage.h" #include "ui/pages/modplatform/ImportPage.h" @@ -125,14 +126,13 @@ void NewInstanceDialog::accept() QList NewInstanceDialog::getPages() { importPage = new ImportPage(this); - flamePage = new FlamePage(this); auto technicPage = new TechnicPage(this); return { new VanillaPage(this), importPage, new AtlPage(this), - flamePage, + new CursePage(this), new FtbPage(this), new LegacyFTB::Page(this), new ModrinthPage(this), diff --git a/launcher/ui/dialogs/NewInstanceDialog.h b/launcher/ui/dialogs/NewInstanceDialog.h index ef74634e..3a100b77 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.h +++ b/launcher/ui/dialogs/NewInstanceDialog.h @@ -29,7 +29,6 @@ class NewInstanceDialog; class PageContainer; class QDialogButtonBox; class ImportPage; -class FlamePage; class NewInstanceDialog : public QDialog, public BasePageProvider { @@ -69,7 +68,6 @@ private: QString InstIconKey; ImportPage *importPage = nullptr; - FlamePage *flamePage = nullptr; std::unique_ptr creationTask; bool importIcon = false; diff --git a/launcher/ui/pages/modplatform/modpacksch/CursePage.cpp b/launcher/ui/pages/modplatform/modpacksch/CursePage.cpp new file mode 100644 index 00000000..8b2a3d29 --- /dev/null +++ b/launcher/ui/pages/modplatform/modpacksch/CursePage.cpp @@ -0,0 +1,168 @@ +/* + * Copyright 2020-2021 Jamie Mansfield + * Copyright 2021 Philip T + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CursePage.h" +#include "ui_CursePage.h" + +#include + +#include "ui/dialogs/NewInstanceDialog.h" +#include "modplatform/modpacksch/FTBPackInstallTask.h" + +#include "HoeDown.h" + +CursePage::CursePage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), ui(new Ui::CursePage), dialog(dialog) +{ + ui->setupUi(this); + connect(ui->searchButton, &QPushButton::clicked, this, &CursePage::triggerSearch); + + filterModel = new ModpacksCH::FilterModel(this); + listModel = new ModpacksCH::ListModel(this); + filterModel->setSourceModel(listModel); + ui->packView->setModel(filterModel); + ui->packView->setSortingEnabled(true); + ui->packView->header()->hide(); + ui->packView->setIndentation(0); + + ui->searchEdit->installEventFilter(this); + + ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300); + + for(int i = 0; i < filterModel->getAvailableSortings().size(); i++) + { + ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); + } + ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); + + connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &CursePage::onSortingSelectionChanged); + connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &CursePage::onSelectionChanged); + connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &CursePage::onVersionSelectionChanged); +} + +CursePage::~CursePage() +{ + delete ui; +} + +bool CursePage::eventFilter(QObject* watched, QEvent* event) +{ + if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Return) { + triggerSearch(); + keyEvent->accept(); + return true; + } + } + return QWidget::eventFilter(watched, event); +} + +bool CursePage::shouldDisplay() const +{ + return true; +} + +void CursePage::openedImpl() +{ + if(!initialised) + { + initialised = true; + } + + suggestCurrent(); +} + +void CursePage::suggestCurrent() +{ + if(!isOpened) + { + return; + } + + if (selectedVersion.isEmpty()) + { + dialog->setSuggestedPack(); + return; + } + + auto & selectedPack = selected; + dialog->setSuggestedPack(selectedVersion, new ModpacksCH::PackInstallTask(selectedPack, selectedVersion, selected.packType)); + for(auto art : selectedPack.art) { + if(art.type == "square") { + QString editedLogoName; + editedLogoName = selectedPack.name; + + listModel->getLogo(selectedPack.name, art.url, [this, editedLogoName](QString logo) + { + dialog->setSuggestedIconFromFile(logo + ".small", editedLogoName); + }); + } + } +} + +void CursePage::triggerSearch() +{ + listModel->requestCurse(ui->searchEdit->text()); +} + +void CursePage::onSortingSelectionChanged(QString data) +{ + auto toSet = filterModel->getAvailableSortings().value(data); + filterModel->setSorting(toSet); +} + +void CursePage::onSelectionChanged(QModelIndex first, QModelIndex second) +{ + ui->versionSelectionBox->clear(); + + if(!first.isValid()) + { + if(isOpened) + { + dialog->setSuggestedPack(); + } + return; + } + + selected = filterModel->data(first, Qt::UserRole).value(); + auto & selectedPack = selected; + + HoeDown hoedown; + QString output = hoedown.process(selectedPack.description.toUtf8()); + ui->packDescription->setHtml(output); + + // reverse foreach, so that the newest versions are first + for (auto i = selectedPack.versions.size(); i--;) { + ui->versionSelectionBox->addItem(selectedPack.versions.at(i).name); + } + + suggestCurrent(); +} + +void CursePage::onVersionSelectionChanged(QString data) +{ + if(data.isNull() || data.isEmpty()) + { + selectedVersion = ""; + return; + } + + selectedVersion = data; + suggestCurrent(); +} diff --git a/launcher/ui/pages/modplatform/modpacksch/CursePage.h b/launcher/ui/pages/modplatform/modpacksch/CursePage.h new file mode 100644 index 00000000..e1f27b0d --- /dev/null +++ b/launcher/ui/pages/modplatform/modpacksch/CursePage.h @@ -0,0 +1,83 @@ +/* Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "MCHFilterModel.h" +#include "MCHListModel.h" + +#include + +#include "Application.h" +#include "ui/pages/BasePage.h" +#include "tasks/Task.h" + +namespace Ui +{ + class CursePage; +} + +class NewInstanceDialog; + +class CursePage : public QWidget, public BasePage +{ +Q_OBJECT + +public: + explicit CursePage(NewInstanceDialog* dialog, QWidget *parent = 0); + virtual ~CursePage(); + virtual QString displayName() const override + { + return tr("CurseForge"); + } + virtual QIcon icon() const override + { + return APPLICATION->getThemedIcon("flame"); + } + virtual QString id() const override + { + return "flame"; + } + virtual QString helpPage() const override + { + return "Flame-platform"; + } + virtual bool shouldDisplay() const override; + + void openedImpl() override; + + bool eventFilter(QObject * watched, QEvent * event) override; + +private: + void suggestCurrent(); + +private slots: + void triggerSearch(); + + void onSortingSelectionChanged(QString data); + void onSelectionChanged(QModelIndex first, QModelIndex second); + void onVersionSelectionChanged(QString data); + +private: + Ui::CursePage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; + ModpacksCH::ListModel* listModel = nullptr; + ModpacksCH::FilterModel* filterModel = nullptr; + + ModpacksCH::Modpack selected; + QString selectedVersion; + + bool initialised { false }; +}; diff --git a/launcher/ui/pages/modplatform/modpacksch/CursePage.ui b/launcher/ui/pages/modplatform/modpacksch/CursePage.ui new file mode 100644 index 00000000..671bd9dc --- /dev/null +++ b/launcher/ui/pages/modplatform/modpacksch/CursePage.ui @@ -0,0 +1,86 @@ + + + CursePage + + + + 0 + 0 + 875 + 745 + + + + + + + Search... + + + true + + + + + + + Search + + + + + + + + + true + + + + 48 + 48 + + + + + + + + true + + + true + + + + + + + + + + + + + + Version selected: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + searchEdit + versionSelectionBox + + + + diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp b/launcher/ui/pages/modplatform/modpacksch/FtbPage.cpp similarity index 86% rename from launcher/ui/pages/modplatform/ftb/FtbPage.cpp rename to launcher/ui/pages/modplatform/modpacksch/FtbPage.cpp index b6b5dcd4..689958e2 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp +++ b/launcher/ui/pages/modplatform/modpacksch/FtbPage.cpp @@ -30,8 +30,8 @@ FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent) { ui->setupUi(this); - filterModel = new Ftb::FilterModel(this); - listModel = new Ftb::ListModel(this); + filterModel = new ModpacksCH::FilterModel(this); + listModel = new ModpacksCH::ListModel(this); filterModel->setSourceModel(listModel); ui->packView->setModel(filterModel); ui->packView->setSortingEnabled(true); @@ -102,13 +102,14 @@ void FtbPage::suggestCurrent() return; } - dialog->setSuggestedPack(selected.name + " " + selectedVersion, new ModpacksCH::PackInstallTask(selected, selectedVersion)); - for(auto art : selected.art) { + auto & selectedPack = selected; + dialog->setSuggestedPack(selected.name + " " + selectedVersion, new ModpacksCH::PackInstallTask(selectedPack, selectedVersion, selected.packType)); + for(auto art : selectedPack.art) { if(art.type == "square") { QString editedLogoName; - editedLogoName = selected.name; + editedLogoName = selectedPack.name; - listModel->getLogo(selected.name, art.url, [this, editedLogoName](QString logo) + listModel->getLogo(selectedPack.name, art.url, [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo + ".small", editedLogoName); }); @@ -141,14 +142,15 @@ void FtbPage::onSelectionChanged(QModelIndex first, QModelIndex second) } selected = filterModel->data(first, Qt::UserRole).value(); + auto & selectedPack = selected; HoeDown hoedown; - QString output = hoedown.process(selected.description.toUtf8()); + QString output = hoedown.process(selectedPack.description.toUtf8()); ui->packDescription->setHtml(output); // reverse foreach, so that the newest versions are first - for (auto i = selected.versions.size(); i--;) { - ui->versionSelectionBox->addItem(selected.versions.at(i).name); + for (auto i = selectedPack.versions.size(); i--;) { + ui->versionSelectionBox->addItem(selectedPack.versions.at(i).name); } suggestCurrent(); diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.h b/launcher/ui/pages/modplatform/modpacksch/FtbPage.h similarity index 92% rename from launcher/ui/pages/modplatform/ftb/FtbPage.h rename to launcher/ui/pages/modplatform/modpacksch/FtbPage.h index 28a189f0..d0ac10fb 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbPage.h +++ b/launcher/ui/pages/modplatform/modpacksch/FtbPage.h @@ -15,8 +15,8 @@ #pragma once -#include "FtbFilterModel.h" -#include "FtbListModel.h" +#include "MCHFilterModel.h" +#include "MCHListModel.h" #include @@ -73,8 +73,8 @@ private slots: private: Ui::FtbPage *ui = nullptr; NewInstanceDialog* dialog = nullptr; - Ftb::ListModel* listModel = nullptr; - Ftb::FilterModel* filterModel = nullptr; + ModpacksCH::ListModel* listModel = nullptr; + ModpacksCH::FilterModel* filterModel = nullptr; ModpacksCH::Modpack selected; QString selectedVersion; diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.ui b/launcher/ui/pages/modplatform/modpacksch/FtbPage.ui similarity index 100% rename from launcher/ui/pages/modplatform/ftb/FtbPage.ui rename to launcher/ui/pages/modplatform/modpacksch/FtbPage.ui diff --git a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp b/launcher/ui/pages/modplatform/modpacksch/MCHFilterModel.cpp similarity index 98% rename from launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp rename to launcher/ui/pages/modplatform/modpacksch/MCHFilterModel.cpp index 67e2277c..13ce06b5 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp +++ b/launcher/ui/pages/modplatform/modpacksch/MCHFilterModel.cpp @@ -14,14 +14,14 @@ * limitations under the License. */ -#include "FtbFilterModel.h" +#include "MCHFilterModel.h" #include #include "modplatform/modpacksch/FTBPackManifest.h" #include -namespace Ftb { +namespace ModpacksCH { FilterModel::FilterModel(QObject *parent) : QSortFilterProxyModel(parent) { diff --git a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h b/launcher/ui/pages/modplatform/modpacksch/MCHFilterModel.h similarity index 98% rename from launcher/ui/pages/modplatform/ftb/FtbFilterModel.h rename to launcher/ui/pages/modplatform/modpacksch/MCHFilterModel.h index 1be28e99..12014c3a 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h +++ b/launcher/ui/pages/modplatform/modpacksch/MCHFilterModel.h @@ -18,7 +18,7 @@ #include -namespace Ftb { +namespace ModpacksCH { class FilterModel : public QSortFilterProxyModel { diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp b/launcher/ui/pages/modplatform/modpacksch/MCHListModel.cpp similarity index 77% rename from launcher/ui/pages/modplatform/ftb/FtbListModel.cpp rename to launcher/ui/pages/modplatform/modpacksch/MCHListModel.cpp index e1c08691..e876508d 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/ui/pages/modplatform/modpacksch/MCHListModel.cpp @@ -14,15 +14,16 @@ * limitations under the License. */ -#include "FtbListModel.h" +#include "MCHListModel.h" #include "BuildConfig.h" #include "Application.h" #include "Json.h" #include +#include -namespace Ftb { +namespace ModpacksCH { ListModel::ListModel(QObject *parent) : QAbstractListModel(parent) { @@ -50,7 +51,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const return QString("INVALID INDEX %1").arg(pos); } - ModpacksCH::Modpack pack = modpacks.at(pos); + auto &pack = modpacks.at(pos); if(role == Qt::DisplayRole) { return pack.name; @@ -103,6 +104,13 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac void ListModel::request() { + if(jobPtr) { + jobPtr->abort(); + jobPtr.reset(); + } + + requestedPackType = PackType::FTB; + beginResetModel(); modpacks.clear(); endResetModel(); @@ -117,6 +125,29 @@ void ListModel::request() QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed); } +void ListModel::requestCurse(const QString & searchTerm) { + + if(jobPtr) { + jobPtr->abort(); + jobPtr.reset(); + } + + requestedPackType = PackType::CurseForge; + + beginResetModel(); + modpacks.clear(); + endResetModel(); + + auto *netJob = new NetJob("Ftb::RequestCurse", APPLICATION->network()); + auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/search/25?term=" + searchTerm); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); + jobPtr = netJob; + jobPtr->start(); + + QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished); + QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed); +} + void ListModel::requestFinished() { jobPtr.reset(); @@ -129,11 +160,22 @@ void ListModel::requestFinished() qWarning() << response; return; } + qDebug() << response; - auto packs = doc.object().value("packs").toArray(); - for(auto pack : packs) { - auto packId = pack.toInt(); - remainingPacks.append(packId); + if(requestedPackType == PackType::FTB) { + auto packs = doc.object().value("packs").toArray(); + for(auto pack : packs) { + auto packId = pack.toInt(); + remainingPacks.append({ModpacksCH::PackType::FTB, packId}); + } + } + + if(requestedPackType == PackType::CurseForge) { + auto cfpacks = doc.object().value("curseforge").toArray(); + for(auto pack : cfpacks) { + auto packId = pack.toInt(); + remainingPacks.append({ModpacksCH::PackType::CurseForge, packId}); + } } if(!remainingPacks.isEmpty()) { @@ -151,8 +193,17 @@ void ListModel::requestFailed(QString reason) void ListModel::requestPack() { auto *netJob = new NetJob("Ftb::Search", APPLICATION->network()); - auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1").arg(currentPack); - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); + QString requestUrl; + switch(currentPack.type) { + case ModpacksCH::PackType::FTB: { + requestUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1").arg(currentPack.identifier); + break; + } + case ModpacksCH::PackType::CurseForge: { + requestUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/curseforge/%1").arg(currentPack.identifier); + } + } + netJob->addNetAction(Net::Download::makeByteArray(QUrl(requestUrl), &response)); jobPtr = netJob; jobPtr->start(); @@ -163,6 +214,7 @@ void ListModel::requestPack() void ListModel::packRequestFinished() { jobPtr.reset(); + auto type = currentPack.type; remainingPacks.removeOne(currentPack); QJsonParseError parse_error; @@ -176,10 +228,14 @@ void ListModel::packRequestFinished() auto obj = doc.object(); - ModpacksCH::Modpack pack; + Modpack pack; try { ModpacksCH::loadModpack(pack, obj); + pack.packType = type; + if(type == ModpacksCH::PackType::CurseForge) { + std::reverse(pack.versions.begin(), pack.versions.end()); + } } catch (const JSONValidationError &e) { diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.h b/launcher/ui/pages/modplatform/modpacksch/MCHListModel.h similarity index 80% rename from launcher/ui/pages/modplatform/ftb/FtbListModel.h rename to launcher/ui/pages/modplatform/modpacksch/MCHListModel.h index 314cb789..899333cf 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.h +++ b/launcher/ui/pages/modplatform/modpacksch/MCHListModel.h @@ -19,10 +19,11 @@ #include #include "modplatform/modpacksch/FTBPackManifest.h" +#include "modplatform/modpacksch/MCHPackType.h" #include "net/NetJob.h" #include -namespace Ftb { +namespace ModpacksCH { struct Logo { QString fullpath; @@ -34,6 +35,14 @@ struct Logo { typedef QMap LogoMap; typedef std::function LogoCallback; +struct PackCoord { + bool operator==(const PackCoord& other) { + return type == other.type && identifier == other.identifier; + } + PackType type; + int identifier; +}; + class ListModel : public QAbstractListModel { Q_OBJECT @@ -47,6 +56,7 @@ public: QVariant data(const QModelIndex &index, int role) const override; void request(); + void requestCurse(const QString & searchTerm); void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback); @@ -65,12 +75,13 @@ private: void requestLogo(QString file, QString url); private: - QList modpacks; + PackType requestedPackType = PackType::FTB; + QList modpacks; LogoMap m_logoMap; NetJob::Ptr jobPtr; - int currentPack; - QList remainingPacks; + PackCoord currentPack; + QList remainingPacks; QByteArray response; };