From ab3fe74c97158fd0f979c15a0d1b0f7eb9976e7d Mon Sep 17 00:00:00 2001 From: Janrupf Date: Wed, 28 Feb 2018 19:42:30 +0100 Subject: Added FTB pack selection ad download, WIP --- application/dialogs/ChooseFtbPackDialog.cpp | 64 +++++++++++ application/dialogs/ChooseFtbPackDialog.h | 32 ++++++ application/dialogs/ChooseFtbPackDialog.ui | 163 ++++++++++++++++++++++++++++ application/dialogs/NewInstanceDialog.cpp | 61 ++++++++++- application/dialogs/NewInstanceDialog.h | 14 +++ application/dialogs/NewInstanceDialog.ui | 129 +++++++++++++++++----- 6 files changed, 430 insertions(+), 33 deletions(-) create mode 100644 application/dialogs/ChooseFtbPackDialog.cpp create mode 100644 application/dialogs/ChooseFtbPackDialog.h create mode 100644 application/dialogs/ChooseFtbPackDialog.ui (limited to 'application/dialogs') diff --git a/application/dialogs/ChooseFtbPackDialog.cpp b/application/dialogs/ChooseFtbPackDialog.cpp new file mode 100644 index 00000000..ae7c72e1 --- /dev/null +++ b/application/dialogs/ChooseFtbPackDialog.cpp @@ -0,0 +1,64 @@ +#include "ChooseFtbPackDialog.h" +#include "widgets/FtbModpackListItem.h" + +ChooseFtbPackDialog::ChooseFtbPackDialog(FtbModpackList modpacks) : ui(new Ui::ChooseFtbPackDialog) { + ui->setupUi(this); + + for(int i = 0; i < modpacks.size(); i++) { + FtbModpackListItem *item = new FtbModpackListItem(ui->packList, modpacks.at(i)); + + item->setText(modpacks.at(i).name); + } + + //TODO: Use a model/view instead of a widget + connect(ui->packList, &QListWidget::itemClicked, this, &ChooseFtbPackDialog::onListItemClicked); + connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onVersionSelectionItemChanged); + + ui->modpackInfo->setOpenExternalLinks(true); + +} + +ChooseFtbPackDialog::~ChooseFtbPackDialog(){ + delete ui; +} + +void ChooseFtbPackDialog::onListItemClicked(QListWidgetItem *item){ + ui->packVersionSelection->clear(); + FtbModpack selectedPack = static_cast(item)->getModpack(); + + ui->modpackInfo->setHtml("Pack by " + selectedPack.author + "" + "
Minecraft " + selectedPack.mcVersion + "
" + "
" + selectedPack.description + ""); + + 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; + +} + +void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data) { + if(data.isNull() || data.isEmpty()) { + selectedVersion = ""; + return; + } + + selectedVersion = data; +} + +FtbModpack ChooseFtbPackDialog::getSelectedModpack() { + return selected; +} + +QString ChooseFtbPackDialog::getSelectedVersion() { + return selectedVersion; +} diff --git a/application/dialogs/ChooseFtbPackDialog.h b/application/dialogs/ChooseFtbPackDialog.h new file mode 100644 index 00000000..212aa27b --- /dev/null +++ b/application/dialogs/ChooseFtbPackDialog.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include +#include "ui_ChooseFtbPackDialog.h" +#include + +namespace Ui { + class ChooseFtbPackDialog; +} + +class ChooseFtbPackDialog : public QDialog { + + Q_OBJECT + +private: + Ui::ChooseFtbPackDialog *ui; + FtbModpack selected; + QString selectedVersion; + +private slots: + void onListItemClicked(QListWidgetItem *item); + void onVersionSelectionItemChanged(QString data); + +public: + ChooseFtbPackDialog(FtbModpackList packs); + ~ChooseFtbPackDialog(); + + FtbModpack getSelectedModpack(); + QString getSelectedVersion(); +}; diff --git a/application/dialogs/ChooseFtbPackDialog.ui b/application/dialogs/ChooseFtbPackDialog.ui new file mode 100644 index 00000000..fdf845a9 --- /dev/null +++ b/application/dialogs/ChooseFtbPackDialog.ui @@ -0,0 +1,163 @@ + + + ChooseFtbPackDialog + + + + 0 + 0 + 730 + 437 + + + + + 0 + 0 + + + + false + + + + + 540 + 400 + 176 + 25 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 261 + 381 + + + + true + + + + + 0 + 0 + 259 + 379 + + + + + + 0 + 0 + 261 + 381 + + + + + + + + + 280 + 10 + 441 + 381 + + + + true + + + + + 0 + 0 + 439 + 379 + + + + + + 0 + 0 + 441 + 381 + + + + + + + + + 450 + 400 + 72 + 25 + + + + + + + 340 + 400 + 101 + 21 + + + + Version selected: + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + buttonBox + accepted() + ChooseFtbPackDialog + accept() + + + 666 + 422 + + + 889 + 501 + + + + + buttonBox + rejected() + ChooseFtbPackDialog + reject() + + + 680 + 411 + + + 524 + 458 + + + + + diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp index 5424a119..5faf57ac 100644 --- a/application/dialogs/NewInstanceDialog.cpp +++ b/application/dialogs/NewInstanceDialog.cpp @@ -25,6 +25,7 @@ #include "VersionSelectDialog.h" #include "ProgressDialog.h" #include "IconPickerDialog.h" +#include "ChooseFtbPackDialog.h" #include #include @@ -92,9 +93,12 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString connect(ui->modpackEdit, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState); connect(ui->modpackBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); + connect(ui->versionBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); connect(ui->versionTextBox, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState); + connect(ui->ftbBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); + auto groups = MMC->instances()->getGroups().toSet(); auto groupList = QStringList(groups.toList()); groupList.sort(Qt::CaseInsensitive); @@ -117,6 +121,14 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString ui->modpackBox->setChecked(true); ui->modpackEdit->setText(url); } + + ftbPackDownloader = new FtbPackDownloader(); + + connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &NewInstanceDialog::ftbPackDataDownloadSuccessfully); + connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &NewInstanceDialog::ftbPackDataDownloadFailed); + + ftbPackDownloader->fetchModpacks(false); + updateDialogState(); } @@ -147,6 +159,17 @@ void NewInstanceDialog::updateDialogState() QFileInfo fi(url.fileName()); suggestedName = fi.completeBaseName(); } + else if (ui->ftbBox->isChecked()) + { + if(ftbPackDownloader->isValidPackSelected()) { + suggestedName = ftbPackDownloader->getSuggestedInstanceName(); + ui->labelFtbPack->setText(selectedPack.name); + } + + } + + ftbModpackRequested = ui->ftbBox->isChecked(); + if(suggestedName.isEmpty()) { ui->instNameTextBox->setPlaceholderText(originalPlaceholderText); @@ -156,9 +179,10 @@ void NewInstanceDialog::updateDialogState() ui->instNameTextBox->setPlaceholderText(suggestedName); } bool allowOK = !instName().isEmpty() && ( - (ui->versionBox->isChecked() && m_selectedVersion) || - (ui->modpackBox->isChecked() && ui->modpackEdit->hasAcceptableInput()) - ); + (ui->versionBox->isChecked() && m_selectedVersion) || + (ui->modpackBox->isChecked() && ui->modpackEdit->hasAcceptableInput()) || + (ui->ftbBox->isChecked() && ftbPackDownloader && ftbPackDownloader->isValidPackSelected() ) + ); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(allowOK); } @@ -271,3 +295,34 @@ void NewInstanceDialog::on_modpackBtn_clicked() } } } + +bool NewInstanceDialog::isFtbModpackRequested() { + return ftbModpackRequested; +} + +FtbPackDownloader *NewInstanceDialog::getFtbPackDownloader() { + return ftbPackDownloader; +} + +void NewInstanceDialog::on_btnChooseFtbPack_clicked() { + ChooseFtbPackDialog dl(ftbPackDownloader->getModpacks()); + dl.exec(); + if(dl.result() == QDialog::Accepted) { + selectedPack = dl.getSelectedModpack(); + ftbPackDownloader->selectPack(selectedPack, dl.getSelectedVersion()); + } + updateDialogState(); +} + +void NewInstanceDialog::ftbPackDataDownloadSuccessfully() { + ui->packDataDownloadStatus->setText(tr("(Pack data download complete)")); + // ui->labelFtbPack->setText(tr("Disabled for now... not completed!")); + + // Disable for PR + ui->ftbBox->setEnabled(true); +} + +void NewInstanceDialog::ftbPackDataDownloadFailed() { + ui->packDataDownloadStatus->setText(tr("(Pack data download failed)")); +} + diff --git a/application/dialogs/NewInstanceDialog.h b/application/dialogs/NewInstanceDialog.h index 820a8d46..9b0f7f53 100644 --- a/application/dialogs/NewInstanceDialog.h +++ b/application/dialogs/NewInstanceDialog.h @@ -18,6 +18,8 @@ #include #include "BaseVersion.h" +#include "modplatform/FtbPackDownloader.h" +#include "modplatform/PackHelpers.h" namespace Ui { @@ -42,19 +44,31 @@ public: QUrl modpackUrl() const; BaseVersionPtr selectedVersion() const; + bool isFtbModpackRequested(); + FtbPackDownloader* getFtbPackDownloader(); + private slots: void on_btnChangeVersion_clicked(); void on_iconButton_clicked(); void on_modpackBtn_clicked(); + void on_btnChooseFtbPack_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); void versionListUpdated(); + void ftbPackDataDownloadSuccessfully(); + void ftbPackDataDownloadFailed(); + private: Ui::NewInstanceDialog *ui; bool m_versionSetByUser = false; + bool ftbModpackRequested = false; + BaseVersionPtr m_selectedVersion; QString InstIconKey; QString originalPlaceholderText; + + FtbPackDownloader* ftbPackDownloader; + FtbModpack selectedPack; }; diff --git a/application/dialogs/NewInstanceDialog.ui b/application/dialogs/NewInstanceDialog.ui index 6b875ff4..428b9c57 100644 --- a/application/dialogs/NewInstanceDialog.ui +++ b/application/dialogs/NewInstanceDialog.ui @@ -10,7 +10,7 @@ 0 0 281 - 404 + 407 @@ -107,37 +107,50 @@ - - + + false + + Install FTB Pack + + + + + ... - - + + false - http:// + ... - - - - true + + + + false + + + ... - - + + + + false + - ... + No Pack choosen @@ -158,6 +171,30 @@ + + + + true + + + + + + + false + + + http:// + + + + + + + (Loading Pack data...) + + + @@ -219,8 +256,8 @@ accept() - 257 - 333 + 266 + 378 157 @@ -235,11 +272,11 @@ reject() - 325 - 333 + 271 + 378 - 286 + 280 274 @@ -251,12 +288,12 @@ setEnabled(bool) - 81 - 229 + 91 + 251 - 236 - 221 + 240 + 278 @@ -267,12 +304,12 @@ setEnabled(bool) - 129 - 225 + 139 + 251 - 328 - 229 + 270 + 278 @@ -287,8 +324,8 @@ 195 - 213 - 191 + 223 + 224 @@ -303,8 +340,40 @@ 198 - 322 - 192 + 270 + 224 + + + + + ftbBox + toggled(bool) + btnChooseFtbPack + setEnabled(bool) + + + 67 + 301 + + + 254 + 327 + + + + + ftbBox + toggled(bool) + labelFtbPack + setEnabled(bool) + + + 81 + 310 + + + 73 + 334 -- cgit v1.2.3