aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/pages/modplatform
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui/pages/modplatform')
-rw-r--r--launcher/ui/pages/modplatform/ModModel.cpp15
-rw-r--r--launcher/ui/pages/modplatform/ModPage.cpp18
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.cpp62
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.h4
-rw-r--r--launcher/ui/pages/modplatform/ResourcePage.cpp6
-rw-r--r--launcher/ui/pages/modplatform/ResourcePage.h3
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackPage.cpp8
7 files changed, 99 insertions, 17 deletions
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp
index 3ffe6cb0..251200f7 100644
--- a/launcher/ui/pages/modplatform/ModModel.cpp
+++ b/launcher/ui/pages/modplatform/ModModel.cpp
@@ -6,12 +6,23 @@
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
+#include "minecraft/mod/ModFolderModel.h"
+#include "modplatform/ModIndex.h"
#include <QMessageBox>
namespace ResourceDownload {
-ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
+ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst)
+{
+ auto folder = static_cast<MinecraftInstance const&>(m_base_instance).loaderModList();
+ for (auto mod : folder->allMods()) {
+ auto meta = mod->metadata();
+ ModPlatform::IndexedPack pack{ meta->project_id, meta->provider, meta->name, meta->slug };
+ pack.loadedFileId = meta->file_id;
+ addPack(pack);
+ }
+}
/******** Make data requests ********/
@@ -24,7 +35,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
std::optional<std::list<Version>> versions{};
- { // Version filter
+ { // Version filter
if (!m_filter->versions.empty())
versions = m_filter->versions;
}
diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp
index 04be43ad..efff1ff4 100644
--- a/launcher/ui/pages/modplatform/ModPage.cpp
+++ b/launcher/ui/pages/modplatform/ModPage.cpp
@@ -55,8 +55,7 @@
namespace ResourceDownload {
-ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance)
- : ResourcePage(dialog, instance)
+ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
{
connect(m_ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
@@ -75,12 +74,10 @@ void ModPage::setFilterWidget(unique_qobject_ptr<ModFilterWidget>& widget)
m_filter_widget->setInstance(&static_cast<MinecraftInstance&>(m_base_instance));
m_filter = m_filter_widget->getFilter();
- connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this, [&]{
- m_ui->searchButton->setStyleSheet("text-decoration: underline");
- });
- connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this, [&]{
- m_ui->searchButton->setStyleSheet("text-decoration: none");
- });
+ connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this,
+ [&] { m_ui->searchButton->setStyleSheet("text-decoration: underline"); });
+ connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this,
+ [&] { m_ui->searchButton->setStyleSheet("text-decoration: none"); });
}
/******** Callbacks to events in the UI (set up in the derived classes) ********/
@@ -128,8 +125,8 @@ void ModPage::updateVersionList()
for (int i = 0; i < current_pack.versions.size(); i++) {
auto version = current_pack.versions[i];
bool valid = false;
- for(auto& mcVer : m_filter->versions){
- //NOTE: Flame doesn't care about loader, so passing it changes nothing.
+ for (auto& mcVer : m_filter->versions) {
+ // NOTE: Flame doesn't care about loader, so passing it changes nothing.
if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
valid = true;
break;
@@ -151,6 +148,7 @@ void ModPage::updateVersionList()
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
{
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
+ m_model->addPack(pack);
m_parent_dialog->addResource(pack, version, is_indexed);
}
diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp
index db7d26f8..459c8c72 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.cpp
+++ b/launcher/ui/pages/modplatform/ResourceModel.cpp
@@ -6,9 +6,11 @@
#include <QCryptographicHash>
#include <QIcon>
+#include <QList>
#include <QMessageBox>
#include <QPixmapCache>
#include <QUrl>
+#include <algorithm>
#include "Application.h"
#include "BuildConfig.h"
@@ -335,6 +337,14 @@ void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
ModPlatform::IndexedPack pack;
try {
loadIndexedPack(pack, packObj);
+ if (auto sel =
+ std::find_if(m_selected.begin(), m_selected.end(),
+ [&pack](ModPlatform::IndexedPack& i) { return i.provider == pack.provider && i.addonId == pack.addonId; });
+ sel != m_selected.end()) {
+ pack.versionsLoaded = sel->versionsLoaded;
+ pack.versions = sel->versions;
+ pack.loadedFileId = sel->loadedFileId;
+ }
newList.append(pack);
} catch (const JSONValidationError& e) {
qWarning() << "Error while loading resource from " << debugName() << ": " << e.cause();
@@ -398,6 +408,11 @@ void ResourceModel::versionRequestSucceeded(QJsonDocument& doc, ModPlatform::Ind
try {
auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
loadIndexedPackVersions(current_pack, arr);
+ if (current_pack.loadedFileId.isValid())
+ if (auto ver = std::find_if(current_pack.versions.begin(), current_pack.versions.end(),
+ [&current_pack](ModPlatform::IndexedVersion v) { return v.fileId == current_pack.loadedFileId; });
+ ver != current_pack.versions.end())
+ ver->is_currently_selected = true;
} catch (const JSONValidationError& e) {
qDebug() << doc;
qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
@@ -441,4 +456,51 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
emit projectInfoUpdated();
}
+void ResourceModel::removePack(QString& rem)
+{
+ auto pred = [&rem](ModPlatform::IndexedPack i) { return rem == i.name; };
+#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
+ m_selected.removeIf(pred);
+#else
+ { // well partial implementation of remove_if in case the QT Version is not high enough
+ const auto cbegin = m_selected.cbegin();
+ const auto cend = m_selected.cend();
+ const auto t_it = std::find_if(cbegin, cend, pred);
+ auto result = std::distance(cbegin, t_it);
+ if (result != m_selected.size()) {
+ // now detach:
+ const auto e = m_selected.end();
+
+ auto it = std::next(m_selected.begin(), result);
+ auto dest = it;
+
+ // Loop Invariants:
+ // - it != e
+ // - [next(it), e[ still to be checked
+ // - [c.begin(), dest[ are result
+ while (++it != e) {
+ if (!pred(*it)) {
+ *dest = std::move(*it);
+ ++dest;
+ }
+ }
+
+ result = std::distance(dest, e);
+ m_selected.erase(dest, e);
+ }
+ }
+#endif
+ // m_selected.removeAt(qsizetype i)
+ auto pack = std::find_if(m_packs.begin(), m_packs.end(), [&rem](ModPlatform::IndexedPack i) { return rem == i.name; });
+ if (pack == m_packs.end()) { // ignore it if is not in the current search
+ return;
+ }
+ if (!pack->versionsLoaded) {
+ pack->loadedFileId = {};
+ return;
+ }
+ for (auto& ver : pack->versions)
+ ver.is_currently_selected = false;
+}
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ResourceModel.h b/launcher/ui/pages/modplatform/ResourceModel.h
index 46a02d6e..5eb63901 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.h
+++ b/launcher/ui/pages/modplatform/ResourceModel.h
@@ -80,6 +80,9 @@ class ResourceModel : public QAbstractListModel {
/** Gets the icon at the URL for the given index. If it's not fetched yet, fetch it and update when fisinhed. */
std::optional<QIcon> getIcon(QModelIndex&, const QUrl&);
+ void addPack(ModPlatform::IndexedPack& add) { m_selected.append(add); }
+ void removePack(QString& rem);
+
protected:
/** Resets the model's data. */
void clearData();
@@ -124,6 +127,7 @@ class ResourceModel : public QAbstractListModel {
QSet<QUrl> m_failed_icon_actions;
QList<ModPlatform::IndexedPack> m_packs;
+ QList<ModPlatform::IndexedPack> m_selected;
// HACK: We need this to prevent callbacks from calling the model after it has already been deleted.
// This leaks a tiny bit of memory per time the user has opened a resource dialog. How to make this better?
diff --git a/launcher/ui/pages/modplatform/ResourcePage.cpp b/launcher/ui/pages/modplatform/ResourcePage.cpp
index bbd465bc..24347dbd 100644
--- a/launcher/ui/pages/modplatform/ResourcePage.cpp
+++ b/launcher/ui/pages/modplatform/ResourcePage.cpp
@@ -308,6 +308,7 @@ void ResourcePage::onVersionSelectionChanged(QString data)
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
{
+ m_model->addPack(pack);
m_parent_dialog->addResource(pack, version);
}
@@ -316,6 +317,11 @@ void ResourcePage::removeResourceFromDialog(ModPlatform::IndexedPack& pack, ModP
m_parent_dialog->removeResource(pack, version);
}
+void ResourcePage::removeResourceFromPage(QString& name)
+{
+ m_model->removePack(name);
+}
+
void ResourcePage::onResourceSelected()
{
if (m_selected_version_index < 0)
diff --git a/launcher/ui/pages/modplatform/ResourcePage.h b/launcher/ui/pages/modplatform/ResourcePage.h
index 1896d53e..a9db52e3 100644
--- a/launcher/ui/pages/modplatform/ResourcePage.h
+++ b/launcher/ui/pages/modplatform/ResourcePage.h
@@ -74,10 +74,11 @@ class ResourcePage : public QWidget, public BasePage {
virtual void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
virtual void removeResourceFromDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
+ virtual void removeResourceFromPage(QString& name);
protected slots:
virtual void triggerSearch() {}
-
+
void onSelectionChanged(QModelIndex first, QModelIndex second);
void onVersionSelectionChanged(QString data);
void onResourceSelected();
diff --git a/launcher/ui/pages/modplatform/ShaderPackPage.cpp b/launcher/ui/pages/modplatform/ShaderPackPage.cpp
index 251c07e7..1b9b2b83 100644
--- a/launcher/ui/pages/modplatform/ShaderPackPage.cpp
+++ b/launcher/ui/pages/modplatform/ShaderPackPage.cpp
@@ -13,8 +13,7 @@
namespace ResourceDownload {
-ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
- : ResourcePage(dialog, instance)
+ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
{
connect(m_ui->searchButton, &QPushButton::clicked, this, &ShaderPackResourcePage::triggerSearch);
connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
@@ -38,7 +37,8 @@ QMap<QString, QString> ShaderPackResourcePage::urlHandlers() const
{
QMap<QString, QString> map;
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/shaders\\/([^\\/]+)\\/?"), "modrinth");
- map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/customization\\/([^\\/]+)\\/?"), "curseforge");
+ map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/customization\\/([^\\/]+)\\/?"),
+ "curseforge");
map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
return map;
}
@@ -47,7 +47,7 @@ void ShaderPackResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack,
{
if (version.loaders.contains(QStringLiteral("canvas")))
version.custom_target_folder = QStringLiteral("resourcepacks");
-
+ m_model->addPack(pack);
m_parent_dialog->addResource(pack, version);
}