2022-01-16 15:50:21 +05:30
|
|
|
#include "FlameModPage.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "ui_ModPage.h"
|
2022-01-16 15:50:21 +05:30
|
|
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
|
|
#include "Application.h"
|
|
|
|
#include "FlameModModel.h"
|
2022-02-25 22:13:27 +05:30
|
|
|
#include "InstanceImportTask.h"
|
|
|
|
#include "Json.h"
|
2022-01-16 15:50:21 +05:30
|
|
|
#include "ModDownloadTask.h"
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-02-25 22:13:27 +05:30
|
|
|
#include "ui/dialogs/ModDownloadDialog.h"
|
2022-01-16 15:50:21 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance)
|
2022-03-06 22:24:05 +05:30
|
|
|
: ModPage(dialog, instance, new FlameAPI())
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
|
|
|
listModel = new FlameMod::ListModel(this);
|
|
|
|
ui->packView->setModel(listModel);
|
|
|
|
|
|
|
|
// index is used to set the sorting with the flame api
|
|
|
|
ui->sortByBox->addItem(tr("Sort by Featured"));
|
|
|
|
ui->sortByBox->addItem(tr("Sort by Popularity"));
|
|
|
|
ui->sortByBox->addItem(tr("Sort by last updated"));
|
|
|
|
ui->sortByBox->addItem(tr("Sort by Name"));
|
|
|
|
ui->sortByBox->addItem(tr("Sort by Author"));
|
|
|
|
ui->sortByBox->addItem(tr("Sort by Downloads"));
|
|
|
|
|
|
|
|
// sometimes Qt just ignores virtual slots and doesn't work as intended it seems,
|
|
|
|
// so it's best not to connect them in the parent's contructor...
|
|
|
|
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
|
|
|
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameModPage::onSelectionChanged);
|
|
|
|
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameModPage::onVersionSelectionChanged);
|
|
|
|
connect(ui->modSelectionButton, &QPushButton::clicked, this, &FlameModPage::onModSelected);
|
2022-01-16 15:50:21 +05:30
|
|
|
}
|
|
|
|
|
2022-02-25 22:13:27 +05:30
|
|
|
bool FlameModPage::shouldDisplay() const { return true; }
|
2022-01-16 15:50:21 +05:30
|
|
|
|
2022-03-08 00:52:57 +05:30
|
|
|
void FlameModPage::onRequestVersionsSucceeded(QJsonDocument& doc, QString addonId)
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
|
|
|
if (addonId != current.addonId) {
|
|
|
|
return; // wrong request
|
2022-01-16 15:50:21 +05:30
|
|
|
}
|
2022-03-08 00:52:57 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
QJsonArray arr = doc.array();
|
|
|
|
try {
|
|
|
|
FlameMod::loadIndexedPackVersions(current, arr, APPLICATION->network(), m_instance);
|
|
|
|
} catch (const JSONValidationError& e) {
|
2022-03-08 00:52:57 +05:30
|
|
|
qDebug() << doc;
|
2022-02-25 22:13:27 +05:30
|
|
|
qWarning() << "Error while reading Flame mod version: " << e.cause();
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
auto packProfile = ((MinecraftInstance*)m_instance)->getPackProfile();
|
|
|
|
QString mcVersion = packProfile->getComponentVersion("net.minecraft");
|
|
|
|
QString loaderString = (packProfile->getComponentVersion("net.minecraftforge").isEmpty()) ? "fabric" : "forge";
|
|
|
|
for (int i = 0; i < current.versions.size(); i++) {
|
2022-02-25 22:13:27 +05:30
|
|
|
auto version = current.versions[i];
|
2022-03-03 05:47:10 +05:30
|
|
|
if (!version.mcVersion.contains(mcVersion)) { continue; }
|
2022-02-25 22:13:27 +05:30
|
|
|
ui->versionSelectionBox->addItem(version.version, QVariant(i));
|
2022-01-16 15:50:21 +05:30
|
|
|
}
|
2022-03-03 05:47:10 +05:30
|
|
|
if (ui->versionSelectionBox->count() == 0) { ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1)); }
|
2022-02-22 06:23:21 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
ui->modSelectionButton->setText(tr("Cannot select invalid version :("));
|
2022-02-25 22:13:27 +05:30
|
|
|
updateSelectionButton();
|
2022-01-16 15:50:21 +05:30
|
|
|
}
|