Higlight installed mods

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-06-08 20:26:09 +03:00
parent 7fb4c8358b
commit f96b135ef7
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
21 changed files with 67 additions and 51 deletions

View File

@ -1109,10 +1109,9 @@ JavaVersion MinecraftInstance::getJavaVersion()
return JavaVersion(settings()->get("JavaVersion").toString()); 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(); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_loader_mod_list.reset(new ModFolderModel(modsRoot(), this, is_indexed)); m_loader_mod_list.reset(new ModFolderModel(modsRoot(), this, is_indexed));
m_loader_mod_list->disableInteraction(isRunning()); m_loader_mod_list->disableInteraction(isRunning());
@ -1121,10 +1120,9 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList()
return m_loader_mod_list; 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(); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_core_mod_list.reset(new ModFolderModel(coreModsDir(), this, is_indexed)); m_core_mod_list.reset(new ModFolderModel(coreModsDir(), this, is_indexed));
m_core_mod_list->disableInteraction(isRunning()); m_core_mod_list->disableInteraction(isRunning());
@ -1133,10 +1131,9 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList()
return m_core_mod_list; 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(); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), this, is_indexed, false)); m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), this, is_indexed, false));
m_nil_mod_list->disableInteraction(isRunning()); m_nil_mod_list->disableInteraction(isRunning());
@ -1145,46 +1142,41 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList()
return m_nil_mod_list; 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)); m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir(), this));
} }
return m_resource_pack_list; 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)); m_texture_pack_list.reset(new TexturePackFolderModel(texturePacksDir(), this));
} }
return m_texture_pack_list; 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)); m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir(), this));
} }
return m_shader_pack_list; 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)); m_world_list.reset(new WorldList(worldDir(), this));
} }
return m_world_list; 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"))); m_game_options.reset(new GameOptions(FS::PathCombine(gameRoot(), "options.txt")));
} }
return m_game_options; return m_game_options;

View File

@ -115,14 +115,14 @@ public:
std::shared_ptr<PackProfile> getPackProfile() const; std::shared_ptr<PackProfile> getPackProfile() const;
////// Mod Lists ////// ////// Mod Lists //////
std::shared_ptr<ModFolderModel> loaderModList(); std::shared_ptr<ModFolderModel> loaderModList() const;
std::shared_ptr<ModFolderModel> coreModList(); std::shared_ptr<ModFolderModel> coreModList() const;
std::shared_ptr<ModFolderModel> nilModList(); std::shared_ptr<ModFolderModel> nilModList() const;
std::shared_ptr<ResourcePackFolderModel> resourcePackList(); std::shared_ptr<ResourcePackFolderModel> resourcePackList() const;
std::shared_ptr<TexturePackFolderModel> texturePackList(); std::shared_ptr<TexturePackFolderModel> texturePackList() const;
std::shared_ptr<ShaderPackFolderModel> shaderPackList(); std::shared_ptr<ShaderPackFolderModel> shaderPackList() const;
std::shared_ptr<WorldList> worldList(); std::shared_ptr<WorldList> worldList() const;
std::shared_ptr<GameOptions> gameOptionsModel(); std::shared_ptr<GameOptions> gameOptionsModel() const;
////// Launch stuff ////// ////// Launch stuff //////
Task::Ptr createUpdateTask(Net::Mode mode) override; Task::Ptr createUpdateTask(Net::Mode mode) override;

View File

@ -45,8 +45,7 @@
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QDebug> #include <QDebug>
WorldList::WorldList(const QString &dir, BaseInstance* instance) WorldList::WorldList(const QString& dir, const BaseInstance* instance) : QAbstractListModel(), m_instance(instance), m_dir(dir)
: QAbstractListModel(), m_instance(instance), m_dir(dir)
{ {
FS::ensureFolderPathExists(m_dir.absolutePath()); FS::ensureFolderPathExists(m_dir.absolutePath());
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);

View File

@ -50,7 +50,7 @@ public:
IconFileRole 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; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
@ -128,7 +128,7 @@ signals:
void changed(); void changed();
protected: protected:
BaseInstance* m_instance; const BaseInstance* m_instance;
QFileSystemWatcher *m_watcher; QFileSystemWatcher *m_watcher;
bool is_watching; bool is_watching;
QDir m_dir; QDir m_dir;

View File

@ -54,7 +54,7 @@
#include "minecraft/mod/tasks/ModFolderLoadTask.h" #include "minecraft/mod/tasks/ModFolderLoadTask.h"
#include "modplatform/ModIndex.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) : 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 }; m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER };

View File

@ -75,7 +75,7 @@ public:
Enable, Enable,
Toggle 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; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

View File

@ -16,7 +16,7 @@
#include "tasks/Task.h" #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) : QAbstractListModel(parent), m_dir(dir), m_instance(instance), m_watcher(this)
{ {
if (create_dir) { if (create_dir) {

View File

@ -26,7 +26,7 @@ class QSortFilterProxyModel;
class ResourceFolderModel : public QAbstractListModel { class ResourceFolderModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: 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; ~ResourceFolderModel() override;
/** Starts watching the paths for changes. /** Starts watching the paths for changes.
@ -191,7 +191,7 @@ class ResourceFolderModel : public QAbstractListModel {
bool m_can_interact = true; bool m_can_interact = true;
QDir m_dir; QDir m_dir;
BaseInstance* m_instance; const BaseInstance* m_instance;
QFileSystemWatcher m_watcher; QFileSystemWatcher m_watcher;
bool m_is_watching = false; bool m_is_watching = false;

View File

@ -45,7 +45,7 @@
#include "minecraft/mod/tasks/BasicFolderLoadTask.h" #include "minecraft/mod/tasks/BasicFolderLoadTask.h"
#include "minecraft/mod/tasks/LocalResourcePackParseTask.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) : ResourceFolderModel(QDir(dir), instance)
{ {
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE }; m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE };

View File

@ -17,7 +17,7 @@ public:
NUM_COLUMNS 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; [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

View File

@ -6,7 +6,5 @@ class ShaderPackFolderModel : public ResourceFolderModel {
Q_OBJECT Q_OBJECT
public: public:
explicit ShaderPackFolderModel(const QString& dir, BaseInstance* instance) explicit ShaderPackFolderModel(const QString& dir, const BaseInstance* instance) : ResourceFolderModel(QDir(dir), instance) {}
: ResourceFolderModel(QDir(dir), instance)
{}
}; };

View File

@ -39,8 +39,7 @@
#include "minecraft/mod/tasks/BasicFolderLoadTask.h" #include "minecraft/mod/tasks/BasicFolderLoadTask.h"
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h" #include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance* instance) TexturePackFolderModel::TexturePackFolderModel(const QString& dir, const BaseInstance* instance) : ResourceFolderModel(QDir(dir), instance)
: ResourceFolderModel(QDir(dir), instance)
{} {}
Task* TexturePackFolderModel::createUpdateTask() Task* TexturePackFolderModel::createUpdateTask()

View File

@ -43,7 +43,7 @@ class TexturePackFolderModel : public ResourceFolderModel
Q_OBJECT Q_OBJECT
public: public:
explicit TexturePackFolderModel(const QString &dir, BaseInstance* instance); explicit TexturePackFolderModel(const QString& dir, const BaseInstance* instance);
[[nodiscard]] Task* createUpdateTask() override; [[nodiscard]] Task* createUpdateTask() override;
[[nodiscard]] Task* createParseTask(Resource&) override; [[nodiscard]] Task* createParseTask(Resource&) override;
}; };

View File

@ -6,8 +6,10 @@
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "minecraft/mod/ModFolderModel.h"
#include <QMessageBox> #include <QMessageBox>
#include <algorithm>
namespace ResourceDownload { namespace ResourceDownload {
@ -67,4 +69,14 @@ void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filte
refresh(); 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 } // namespace ResourceDownload

View File

@ -42,6 +42,7 @@ class ModModel : public ResourceModel {
protected: protected:
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0; auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0;
virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr) const override;
protected: protected:
const BaseInstance& m_base_instance; const BaseInstance& m_base_instance;

View File

@ -77,6 +77,8 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
return pack->description; return pack->description;
case UserDataTypes::SELECTED: case UserDataTypes::SELECTED:
return pack->isAnyVersionSelected(); return pack->isAnyVersionSelected();
case UserDataTypes::INSTALLED:
return this->isPackInstalled(pack);
default: default:
break; break;
} }
@ -95,6 +97,7 @@ QHash<int, QByteArray> ResourceModel::roleNames() const
roles[UserDataTypes::TITLE] = "title"; roles[UserDataTypes::TITLE] = "title";
roles[UserDataTypes::DESCRIPTION] = "description"; roles[UserDataTypes::DESCRIPTION] = "description";
roles[UserDataTypes::SELECTED] = "selected"; roles[UserDataTypes::SELECTED] = "selected";
roles[UserDataTypes::INSTALLED] = "installed";
return roles; return roles;
} }

View File

@ -116,6 +116,8 @@ class ResourceModel : public QAbstractListModel {
virtual void loadExtraPackInfo(ModPlatform::IndexedPack&, QJsonObject&); virtual void loadExtraPackInfo(ModPlatform::IndexedPack&, QJsonObject&);
virtual void loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArray&); virtual void loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArray&);
virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr) const { return false; }
protected: protected:
/* Basic search parameters */ /* Basic search parameters */
enum class SearchState { None, CanFetchMore, ResetRequested, Finished } m_search_state = SearchState::None; enum class SearchState { None, CanFetchMore, ResetRequested, Finished } m_search_state = SearchState::None;

View File

@ -60,6 +60,8 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return pack.description; return pack.description;
case UserDataTypes::SELECTED: case UserDataTypes::SELECTED:
return false; return false;
case UserDataTypes::INSTALLED:
return false;
default: default:
break; break;
} }

View File

@ -106,6 +106,8 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
return pack.description; return pack.description;
case UserDataTypes::SELECTED: case UserDataTypes::SELECTED:
return false; return false;
case UserDataTypes::INSTALLED:
return false;
default: default:
break; break;
} }

View File

@ -64,6 +64,11 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
font.setBold(true); font.setBold(true);
font.setUnderline(true); font.setUnderline(true);
} }
if (index.data(UserDataTypes::INSTALLED).toBool()) {
// Set nice font
font.setItalic(true);
font.setOverline(true);
}
font.setPointSize(font.pointSize() + 2); font.setPointSize(font.pointSize() + 2);
painter->setFont(font); painter->setFont(font);

View File

@ -6,7 +6,8 @@
enum UserDataTypes { enum UserDataTypes {
TITLE = 257, // QString TITLE = 257, // QString
DESCRIPTION = 258, // QString DESCRIPTION = 258, // QString
SELECTED = 259 // bool SELECTED = 259, // bool
INSTALLED = 260 // bool
}; };
/** This is an item delegate composed of: /** This is an item delegate composed of: