aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-08 20:26:09 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-06-08 20:26:09 +0300
commitf96b135ef72a762220941681cf1b314a3b2db266 (patch)
tree90f28be402becbf32835d176913d9d36f3c3d703
parent7fb4c8358b9303358e47833bdf7e8fc8bcf5ab17 (diff)
downloadPrismLauncher-f96b135ef72a762220941681cf1b314a3b2db266.tar.gz
PrismLauncher-f96b135ef72a762220941681cf1b314a3b2db266.tar.bz2
PrismLauncher-f96b135ef72a762220941681cf1b314a3b2db266.zip
Higlight installed mods
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
-rw-r--r--launcher/minecraft/MinecraftInstance.cpp40
-rw-r--r--launcher/minecraft/MinecraftInstance.h16
-rw-r--r--launcher/minecraft/WorldList.cpp3
-rw-r--r--launcher/minecraft/WorldList.h4
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/ModFolderModel.h2
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.h4
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.h2
-rw-r--r--launcher/minecraft/mod/ShaderPackFolderModel.h4
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.cpp3
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.h4
-rw-r--r--launcher/ui/pages/modplatform/ModModel.cpp12
-rw-r--r--launcher/ui/pages/modplatform/ModModel.h1
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.cpp3
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.h2
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModel.cpp2
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp2
-rw-r--r--launcher/ui/widgets/ProjectItem.cpp5
-rw-r--r--launcher/ui/widgets/ProjectItem.h3
21 files changed, 67 insertions, 51 deletions
diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp
index 2c624a36..76ff5723 100644
--- a/launcher/minecraft/MinecraftInstance.cpp
+++ b/launcher/minecraft/MinecraftInstance.cpp
@@ -1109,10 +1109,9 @@ JavaVersion MinecraftInstance::getJavaVersion()
return JavaVersion(settings()->get("JavaVersion").toString());
}
-std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList()
+std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList() const
{
- if (!m_loader_mod_list)
- {
+ if (!m_loader_mod_list) {
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_loader_mod_list.reset(new ModFolderModel(modsRoot(), this, is_indexed));
m_loader_mod_list->disableInteraction(isRunning());
@@ -1121,10 +1120,9 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList()
return m_loader_mod_list;
}
-std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList()
+std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList() const
{
- if (!m_core_mod_list)
- {
+ if (!m_core_mod_list) {
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_core_mod_list.reset(new ModFolderModel(coreModsDir(), this, is_indexed));
m_core_mod_list->disableInteraction(isRunning());
@@ -1133,10 +1131,9 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList()
return m_core_mod_list;
}
-std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList()
+std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList() const
{
- if (!m_nil_mod_list)
- {
+ if (!m_nil_mod_list) {
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), this, is_indexed, false));
m_nil_mod_list->disableInteraction(isRunning());
@@ -1145,46 +1142,41 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList()
return m_nil_mod_list;
}
-std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList()
+std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList() const
{
- if (!m_resource_pack_list)
- {
+ if (!m_resource_pack_list) {
m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir(), this));
}
return m_resource_pack_list;
}
-std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList()
+std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList() const
{
- if (!m_texture_pack_list)
- {
+ if (!m_texture_pack_list) {
m_texture_pack_list.reset(new TexturePackFolderModel(texturePacksDir(), this));
}
return m_texture_pack_list;
}
-std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList()
+std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList() const
{
- if (!m_shader_pack_list)
- {
+ if (!m_shader_pack_list) {
m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir(), this));
}
return m_shader_pack_list;
}
-std::shared_ptr<WorldList> MinecraftInstance::worldList()
+std::shared_ptr<WorldList> MinecraftInstance::worldList() const
{
- if (!m_world_list)
- {
+ if (!m_world_list) {
m_world_list.reset(new WorldList(worldDir(), this));
}
return m_world_list;
}
-std::shared_ptr<GameOptions> MinecraftInstance::gameOptionsModel()
+std::shared_ptr<GameOptions> MinecraftInstance::gameOptionsModel() const
{
- if (!m_game_options)
- {
+ if (!m_game_options) {
m_game_options.reset(new GameOptions(FS::PathCombine(gameRoot(), "options.txt")));
}
return m_game_options;
diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h
index 068b3008..a75fa481 100644
--- a/launcher/minecraft/MinecraftInstance.h
+++ b/launcher/minecraft/MinecraftInstance.h
@@ -115,14 +115,14 @@ public:
std::shared_ptr<PackProfile> getPackProfile() const;
////// Mod Lists //////
- std::shared_ptr<ModFolderModel> loaderModList();
- std::shared_ptr<ModFolderModel> coreModList();
- std::shared_ptr<ModFolderModel> nilModList();
- std::shared_ptr<ResourcePackFolderModel> resourcePackList();
- std::shared_ptr<TexturePackFolderModel> texturePackList();
- std::shared_ptr<ShaderPackFolderModel> shaderPackList();
- std::shared_ptr<WorldList> worldList();
- std::shared_ptr<GameOptions> gameOptionsModel();
+ std::shared_ptr<ModFolderModel> loaderModList() const;
+ std::shared_ptr<ModFolderModel> coreModList() const;
+ std::shared_ptr<ModFolderModel> nilModList() const;
+ std::shared_ptr<ResourcePackFolderModel> resourcePackList() const;
+ std::shared_ptr<TexturePackFolderModel> texturePackList() const;
+ std::shared_ptr<ShaderPackFolderModel> shaderPackList() const;
+ std::shared_ptr<WorldList> worldList() const;
+ std::shared_ptr<GameOptions> gameOptionsModel() const;
////// Launch stuff //////
Task::Ptr createUpdateTask(Net::Mode mode) override;
diff --git a/launcher/minecraft/WorldList.cpp b/launcher/minecraft/WorldList.cpp
index 0feee299..42772df5 100644
--- a/launcher/minecraft/WorldList.cpp
+++ b/launcher/minecraft/WorldList.cpp
@@ -45,8 +45,7 @@
#include <QFileSystemWatcher>
#include <QDebug>
-WorldList::WorldList(const QString &dir, BaseInstance* instance)
- : QAbstractListModel(), m_instance(instance), m_dir(dir)
+WorldList::WorldList(const QString& dir, const BaseInstance* instance) : QAbstractListModel(), m_instance(instance), m_dir(dir)
{
FS::ensureFolderPathExists(m_dir.absolutePath());
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);
diff --git a/launcher/minecraft/WorldList.h b/launcher/minecraft/WorldList.h
index 96b64193..92d02b9b 100644
--- a/launcher/minecraft/WorldList.h
+++ b/launcher/minecraft/WorldList.h
@@ -50,7 +50,7 @@ public:
IconFileRole
};
- WorldList(const QString &dir, BaseInstance* instance);
+ WorldList(const QString& dir, const BaseInstance* instance);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
@@ -128,7 +128,7 @@ signals:
void changed();
protected:
- BaseInstance* m_instance;
+ const BaseInstance* m_instance;
QFileSystemWatcher *m_watcher;
bool is_watching;
QDir m_dir;
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 5e3b31e0..eccfe4ae 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -54,7 +54,7 @@
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
#include "modplatform/ModIndex.h"
-ModFolderModel::ModFolderModel(const QString& dir, BaseInstance* instance, bool is_indexed, bool create_dir)
+ModFolderModel::ModFolderModel(const QString& dir, const BaseInstance* instance, bool is_indexed, bool create_dir)
: ResourceFolderModel(QDir(dir), instance, nullptr, create_dir), m_is_indexed(is_indexed)
{
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER };
diff --git a/launcher/minecraft/mod/ModFolderModel.h b/launcher/minecraft/mod/ModFolderModel.h
index d337fe29..261a007a 100644
--- a/launcher/minecraft/mod/ModFolderModel.h
+++ b/launcher/minecraft/mod/ModFolderModel.h
@@ -75,7 +75,7 @@ public:
Enable,
Toggle
};
- ModFolderModel(const QString &dir, BaseInstance* instance, bool is_indexed = false, bool create_dir = true);
+ ModFolderModel(const QString& dir, const BaseInstance* instance, bool is_indexed = false, bool create_dir = true);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp
index d2d875e4..5664ea85 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourceFolderModel.cpp
@@ -16,7 +16,7 @@
#include "tasks/Task.h"
-ResourceFolderModel::ResourceFolderModel(QDir dir, BaseInstance* instance, QObject* parent, bool create_dir)
+ResourceFolderModel::ResourceFolderModel(QDir dir, const BaseInstance* instance, QObject* parent, bool create_dir)
: QAbstractListModel(parent), m_dir(dir), m_instance(instance), m_watcher(this)
{
if (create_dir) {
diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h
index 0a35e1bc..d853b443 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.h
+++ b/launcher/minecraft/mod/ResourceFolderModel.h
@@ -26,7 +26,7 @@ class QSortFilterProxyModel;
class ResourceFolderModel : public QAbstractListModel {
Q_OBJECT
public:
- ResourceFolderModel(QDir, BaseInstance* instance, QObject* parent = nullptr, bool create_dir = true);
+ ResourceFolderModel(QDir, const BaseInstance* instance, QObject* parent = nullptr, bool create_dir = true);
~ResourceFolderModel() override;
/** Starts watching the paths for changes.
@@ -191,7 +191,7 @@ class ResourceFolderModel : public QAbstractListModel {
bool m_can_interact = true;
QDir m_dir;
- BaseInstance* m_instance;
+ const BaseInstance* m_instance;
QFileSystemWatcher m_watcher;
bool m_is_watching = false;
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
index c12d1f23..8036292b 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
@@ -45,7 +45,7 @@
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
#include "minecraft/mod/tasks/LocalResourcePackParseTask.h"
-ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, BaseInstance* instance)
+ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, const BaseInstance* instance)
: ResourceFolderModel(QDir(dir), instance)
{
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE };
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.h b/launcher/minecraft/mod/ResourcePackFolderModel.h
index db4b14fb..9d96253a 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.h
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.h
@@ -17,7 +17,7 @@ public:
NUM_COLUMNS
};
- explicit ResourcePackFolderModel(const QString &dir, BaseInstance* instance);
+ explicit ResourcePackFolderModel(const QString& dir, const BaseInstance* instance);
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
diff --git a/launcher/minecraft/mod/ShaderPackFolderModel.h b/launcher/minecraft/mod/ShaderPackFolderModel.h
index dc5acf80..c05bec1d 100644
--- a/launcher/minecraft/mod/ShaderPackFolderModel.h
+++ b/launcher/minecraft/mod/ShaderPackFolderModel.h
@@ -6,7 +6,5 @@ class ShaderPackFolderModel : public ResourceFolderModel {
Q_OBJECT
public:
- explicit ShaderPackFolderModel(const QString& dir, BaseInstance* instance)
- : ResourceFolderModel(QDir(dir), instance)
- {}
+ explicit ShaderPackFolderModel(const QString& dir, const BaseInstance* instance) : ResourceFolderModel(QDir(dir), instance) {}
};
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp
index c6609ed1..dadf8f77 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.cpp
+++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp
@@ -39,8 +39,7 @@
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
-TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance* instance)
- : ResourceFolderModel(QDir(dir), instance)
+TexturePackFolderModel::TexturePackFolderModel(const QString& dir, const BaseInstance* instance) : ResourceFolderModel(QDir(dir), instance)
{}
Task* TexturePackFolderModel::createUpdateTask()
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.h b/launcher/minecraft/mod/TexturePackFolderModel.h
index 425a71e4..a1492f8b 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.h
+++ b/launcher/minecraft/mod/TexturePackFolderModel.h
@@ -42,8 +42,8 @@ class TexturePackFolderModel : public ResourceFolderModel
{
Q_OBJECT
-public:
- explicit TexturePackFolderModel(const QString &dir, BaseInstance* instance);
+ public:
+ explicit TexturePackFolderModel(const QString& dir, const BaseInstance* instance);
[[nodiscard]] Task* createUpdateTask() override;
[[nodiscard]] Task* createParseTask(Resource&) override;
};
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp
index afd8b292..1579bbf4 100644
--- a/launcher/ui/pages/modplatform/ModModel.cpp
+++ b/launcher/ui/pages/modplatform/ModModel.cpp
@@ -6,8 +6,10 @@
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
+#include "minecraft/mod/ModFolderModel.h"
#include <QMessageBox>
+#include <algorithm>
namespace ResourceDownload {
@@ -67,4 +69,14 @@ void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filte
refresh();
}
+bool ModModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const
+{
+ auto allMods = static_cast<MinecraftInstance const&>(m_base_instance).loaderModList()->allMods();
+ return std::any_of(allMods.cbegin(), allMods.cend(), [pack](Mod* mod) {
+ if (auto meta = mod->metadata(); meta)
+ return meta->provider == pack->provider && meta->project_id == pack->addonId;
+ return false;
+ });
+}
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h
index 5d4a7785..938ce32e 100644
--- a/launcher/ui/pages/modplatform/ModModel.h
+++ b/launcher/ui/pages/modplatform/ModModel.h
@@ -42,6 +42,7 @@ class ModModel : public ResourceModel {
protected:
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0;
+ virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr) const override;
protected:
const BaseInstance& m_base_instance;
diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp
index a5ea1ca9..49405a02 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.cpp
+++ b/launcher/ui/pages/modplatform/ResourceModel.cpp
@@ -77,6 +77,8 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
return pack->description;
case UserDataTypes::SELECTED:
return pack->isAnyVersionSelected();
+ case UserDataTypes::INSTALLED:
+ return this->isPackInstalled(pack);
default:
break;
}
@@ -95,6 +97,7 @@ QHash<int, QByteArray> ResourceModel::roleNames() const
roles[UserDataTypes::TITLE] = "title";
roles[UserDataTypes::DESCRIPTION] = "description";
roles[UserDataTypes::SELECTED] = "selected";
+ roles[UserDataTypes::INSTALLED] = "installed";
return roles;
}
diff --git a/launcher/ui/pages/modplatform/ResourceModel.h b/launcher/ui/pages/modplatform/ResourceModel.h
index 69e23473..6533d9c6 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.h
+++ b/launcher/ui/pages/modplatform/ResourceModel.h
@@ -116,6 +116,8 @@ class ResourceModel : public QAbstractListModel {
virtual void loadExtraPackInfo(ModPlatform::IndexedPack&, QJsonObject&);
virtual void loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArray&);
+ virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr) const { return false; }
+
protected:
/* Basic search parameters */
enum class SearchState { None, CanFetchMore, ResetRequested, Finished } m_search_state = SearchState::None;
diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp
index 5961ea02..d9d5ef5b 100644
--- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp
@@ -60,6 +60,8 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return pack.description;
case UserDataTypes::SELECTED:
return false;
+ case UserDataTypes::INSTALLED:
+ return false;
default:
break;
}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
index 346a00b0..55d287b0 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
@@ -106,6 +106,8 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
return pack.description;
case UserDataTypes::SELECTED:
return false;
+ case UserDataTypes::INSTALLED:
+ return false;
default:
break;
}
diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp
index d1ff9dbc..e8349c10 100644
--- a/launcher/ui/widgets/ProjectItem.cpp
+++ b/launcher/ui/widgets/ProjectItem.cpp
@@ -64,6 +64,11 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
font.setBold(true);
font.setUnderline(true);
}
+ if (index.data(UserDataTypes::INSTALLED).toBool()) {
+ // Set nice font
+ font.setItalic(true);
+ font.setOverline(true);
+ }
font.setPointSize(font.pointSize() + 2);
painter->setFont(font);
diff --git a/launcher/ui/widgets/ProjectItem.h b/launcher/ui/widgets/ProjectItem.h
index f668edf6..196055ea 100644
--- a/launcher/ui/widgets/ProjectItem.h
+++ b/launcher/ui/widgets/ProjectItem.h
@@ -6,7 +6,8 @@
enum UserDataTypes {
TITLE = 257, // QString
DESCRIPTION = 258, // QString
- SELECTED = 259 // bool
+ SELECTED = 259, // bool
+ INSTALLED = 260 // bool
};
/** This is an item delegate composed of: