PrismLauncher/application/pages/modplatform/FTBPage.cpp

189 lines
5.0 KiB
C++
Raw Normal View History

2018-03-19 01:36:12 +00:00
#include "FTBPage.h"
#include "ui_FTBPage.h"
#include "MultiMC.h"
#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/NewInstanceDialog.h"
#include "modplatform/ftb/FtbPackFetchTask.h"
2018-03-19 01:36:12 +00:00
#include "modplatform/ftb/FtbPackInstallTask.h"
#include "FtbListModel.h"
2018-03-19 01:36:12 +00:00
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
{
ftbFetchTask = new FtbPackFetchTask();
2018-03-19 01:36:12 +00:00
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
2018-03-19 01:36:12 +00:00
{
publicFilterModel = new FtbFilterModel(this);
publicListModel = new FtbListModel(this);
publicFilterModel->setSourceModel(publicListModel);
2018-03-19 01:36:12 +00:00
ui->publicPackList->setModel(publicFilterModel);
ui->publicPackList->setSortingEnabled(true);
ui->publicPackList->header()->hide();
ui->publicPackList->setIndentation(0);
2018-04-06 14:08:59 +01:00
ui->publicPackList->setIconSize(QSize(42, 42));
2018-03-19 01:36:12 +00:00
for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
{
ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
}
2018-03-19 01:36:12 +00:00
ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
}
2018-03-19 01:36:12 +00:00
{
thirdPartyFilterModel = new FtbFilterModel(this);
thirdPartyModel = new FtbListModel(this);
thirdPartyFilterModel->setSourceModel(thirdPartyModel);
ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
ui->thirdPartyPackList->setSortingEnabled(true);
ui->thirdPartyPackList->header()->hide();
ui->thirdPartyPackList->setIndentation(0);
2018-04-06 14:08:59 +01:00
ui->thirdPartyPackList->setIconSize(QSize(42, 42));
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
2018-03-19 01:36:12 +00:00
}
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
2018-03-19 01:36:12 +00:00
2018-04-05 18:33:31 +01:00
connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
2018-03-19 01:36:12 +00:00
ui->modpackInfo->setOpenExternalLinks(true);
2018-04-05 18:33:31 +01:00
ui->publicPackList->selectionModel()->reset();
ui->thirdPartyPackList->selectionModel()->reset();
2018-03-19 01:36:12 +00:00
}
FTBPage::~FTBPage()
{
delete ui;
if(ftbFetchTask) {
ftbFetchTask->deleteLater();
2018-03-19 01:36:12 +00:00
}
}
bool FTBPage::shouldDisplay() const
{
return true;
}
void FTBPage::openedImpl()
{
if(!initialized)
{
connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
ftbFetchTask->fetch();
2018-03-19 01:36:12 +00:00
initialized = true;
}
suggestCurrent();
}
void FTBPage::suggestCurrent()
{
if(isOpened)
{
if(!selected.broken)
{
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
}
else
{
dialog->setSuggestedPack();
}
}
}
void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks)
{
publicListModel->fill(publicPacks);
thirdPartyModel->fill(thirdPartyPacks);
}
void FTBPage::ftbPackDataDownloadFailed(QString reason)
2018-03-19 01:36:12 +00:00
{
//TODO: Display the error
2018-03-19 01:36:12 +00:00
}
void FTBPage::onPublicPackSelectionChanged(QModelIndex first, QModelIndex second)
2018-03-19 01:36:12 +00:00
{
onPackSelectionChanged(first, second, publicFilterModel);
2018-03-19 01:36:12 +00:00
}
void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second)
2018-03-19 01:36:12 +00:00
{
onPackSelectionChanged(first, second, thirdPartyFilterModel);
2018-03-19 01:36:12 +00:00
}
void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model)
2018-03-19 01:36:12 +00:00
{
ui->packVersionSelection->clear();
FtbModpack selectedPack = model->data(now, Qt::UserRole).value<FtbModpack>();
2018-03-19 01:36:12 +00:00
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>"
"<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
bool currentAdded = false;
for(int i = 0; i < selectedPack.oldVersions.size(); i++)
{
if(selectedPack.currentVersion == selectedPack.oldVersions.at(i))
{
currentAdded = true;
}
ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i));
}
if(!currentAdded)
{
ui->packVersionSelection->addItem(selectedPack.currentVersion);
}
selected = selectedPack;
suggestCurrent();
}
void FTBPage::onVersionSelectionItemChanged(QString data)
{
if(data.isNull() || data.isEmpty())
{
selectedVersion = "";
return;
}
selectedVersion = data;
}
FtbModpack FTBPage::getSelectedModpack()
{
return selected;
}
QString FTBPage::getSelectedVersion()
{
return selectedVersion;
}
void FTBPage::onSortingSelectionChanged(QString data)
{
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
publicFilterModel->setSorting(toSet);
thirdPartyFilterModel->setSorting(toSet);
2018-03-19 01:36:12 +00:00
}
2018-04-05 18:33:31 +01:00
void FTBPage::onTabChanged(int tab)
{
ui->publicPackList->selectionModel()->reset();
ui->thirdPartyPackList->selectionModel()->reset();
}