From 15926b2b4a50daa9eb20a0ad7255c6b5fb0d7246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 6 Apr 2018 21:59:04 +0200 Subject: [PATCH] NOISSUE make FTB pack selection fancier --- application/pages/modplatform/FTBPage.cpp | 89 ++++++++++++++--------- application/pages/modplatform/FTBPage.h | 6 +- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp index bdfd1d8e..70e3ebd4 100644 --- a/application/pages/modplatform/FTBPage.cpp +++ b/application/pages/modplatform/FTBPage.cpp @@ -115,41 +115,52 @@ void FTBPage::ftbPackDataDownloadFailed(QString reason) //TODO: Display the error } -void FTBPage::onPublicPackSelectionChanged(QModelIndex first, QModelIndex second) +void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev) { - onPackSelectionChanged(first, second, publicFilterModel); + if(!now.isValid()) + { + onPackSelectionChanged(); + return; + } + FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value(); + onPackSelectionChanged(&selectedPack); } -void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second) +void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev) { - onPackSelectionChanged(first, second, thirdPartyFilterModel); + if(!now.isValid()) + { + onPackSelectionChanged(); + return; + } + FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value(); + onPackSelectionChanged(&selectedPack); } -void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model) +void FTBPage::onPackSelectionChanged(FtbModpack* pack) { ui->packVersionSelection->clear(); - FtbModpack selectedPack = model->data(now, Qt::UserRole).value(); - - ui->modpackInfo->setHtml("Pack by " + selectedPack.author + "" + "
Minecraft " + selectedPack.mcVersion + "
" - "
" + selectedPack.description + "
  • " + selectedPack.mods.replace(";", "
  • ") + "
"); - - bool currentAdded = false; - - for(int i = 0; i < selectedPack.oldVersions.size(); i++) + if(pack) { - if(selectedPack.currentVersion == selectedPack.oldVersions.at(i)) + ui->modpackInfo->setHtml("Pack by " + pack->author + "" + "
Minecraft " + pack->mcVersion + "
" + "
" + pack->description + "
  • " + pack->mods.replace(";", "
  • ") + "
"); + bool currentAdded = false; + + for(int i = 0; i < pack->oldVersions.size(); i++) { - currentAdded = true; + if(pack->currentVersion == pack->oldVersions.at(i)) + { + currentAdded = true; + } + ui->packVersionSelection->addItem(pack->oldVersions.at(i)); } - ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i)); - } - if(!currentAdded) - { - ui->packVersionSelection->addItem(selectedPack.currentVersion); + if(!currentAdded) + { + ui->packVersionSelection->addItem(pack->currentVersion); + } + selected = *pack; } - - selected = selectedPack; suggestCurrent(); } @@ -164,16 +175,6 @@ void FTBPage::onVersionSelectionItemChanged(QString data) selectedVersion = data; } -FtbModpack FTBPage::getSelectedModpack() -{ - return selected; -} - -QString FTBPage::getSelectedVersion() -{ - return selectedVersion; -} - void FTBPage::onSortingSelectionChanged(QString data) { FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data); @@ -183,6 +184,26 @@ void FTBPage::onSortingSelectionChanged(QString data) void FTBPage::onTabChanged(int tab) { - ui->publicPackList->selectionModel()->reset(); - ui->thirdPartyPackList->selectionModel()->reset(); + FtbFilterModel* currentModel = nullptr; + QTreeView* currentList = nullptr; + if (tab == 0) + { + currentModel = publicFilterModel; + currentList = ui->publicPackList; + } + else + { + currentModel = thirdPartyFilterModel; + currentList = ui->thirdPartyPackList; + } + QModelIndex idx = currentList->currentIndex(); + if(idx.isValid()) + { + auto pack = currentModel->data(idx, Qt::UserRole).value(); + onPackSelectionChanged(&pack); + } + else + { + onPackSelectionChanged(); + } } diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h index a5327d31..00c5e9c5 100644 --- a/application/pages/modplatform/FTBPage.h +++ b/application/pages/modplatform/FTBPage.h @@ -58,12 +58,9 @@ public: bool shouldDisplay() const override; void openedImpl() override; - FtbModpack getSelectedModpack(); - QString getSelectedVersion(); - private: void suggestCurrent(); - void onPackSelectionChanged(QModelIndex first, QModelIndex second, FtbFilterModel *model); + void onPackSelectionChanged(FtbModpack *pack = nullptr); private slots: void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks); @@ -79,7 +76,6 @@ private slots: private: bool initialized = false; - FtbModpack selectedPack; FtbModpack selected; QString selectedVersion;