Merge pull request #1135 from Trial97/installed_mods
This commit is contained in:
commit
412349ac58
@ -6,12 +6,14 @@
|
|||||||
|
|
||||||
#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 {
|
||||||
|
|
||||||
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
|
ModModel::ModModel(BaseInstance& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
|
||||||
|
|
||||||
/******** Make data requests ********/
|
/******** Make data requests ********/
|
||||||
|
|
||||||
@ -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&>(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
|
||||||
|
@ -24,7 +24,7 @@ class ModModel : public ResourceModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModModel(const BaseInstance&, ResourceAPI* api);
|
ModModel(BaseInstance&, ResourceAPI* api);
|
||||||
|
|
||||||
/* Ask the API for more information */
|
/* Ask the API for more information */
|
||||||
void searchWithTerm(const QString& term, unsigned int sort, bool filter_changed);
|
void searchWithTerm(const QString& term, unsigned int sort, bool filter_changed);
|
||||||
@ -42,9 +42,10 @@ 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;
|
BaseInstance& m_base_instance;
|
||||||
|
|
||||||
std::shared_ptr<ModFilterWidget::Filter> m_filter = nullptr;
|
std::shared_ptr<ModFilterWidget::Filter> m_filter = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
FlameModModel::FlameModModel(BaseInstance const& base) : ModModel(base, new FlameAPI) {}
|
FlameModModel::FlameModModel(BaseInstance& base) : ModModel(base, new FlameAPI) {}
|
||||||
|
|
||||||
void FlameModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
|
void FlameModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ class FlameModModel : public ModModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FlameModModel(const BaseInstance&);
|
FlameModModel(BaseInstance&);
|
||||||
~FlameModModel() override = default;
|
~FlameModModel() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ModrinthModModel::ModrinthModModel(BaseInstance const& base) : ModModel(base, new ModrinthAPI) {}
|
ModrinthModModel::ModrinthModModel(BaseInstance& base) : ModModel(base, new ModrinthAPI) {}
|
||||||
|
|
||||||
void ModrinthModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
|
void ModrinthModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ class ModrinthModModel : public ModModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModrinthModModel(const BaseInstance&);
|
ModrinthModModel(BaseInstance&);
|
||||||
~ModrinthModModel() override = default;
|
~ModrinthModModel() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -64,6 +64,17 @@ 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()) {
|
||||||
|
auto hRect = opt.rect;
|
||||||
|
hRect.setX(hRect.x() + 1);
|
||||||
|
hRect.setY(hRect.y() + 1);
|
||||||
|
hRect.setHeight(hRect.height() - 2);
|
||||||
|
hRect.setWidth(hRect.width() - 2);
|
||||||
|
// Set nice font
|
||||||
|
font.setItalic(true);
|
||||||
|
font.setOverline(true);
|
||||||
|
painter->drawRect(hRect);
|
||||||
|
}
|
||||||
|
|
||||||
font.setPointSize(font.pointSize() + 2);
|
font.setPointSize(font.pointSize() + 2);
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
|
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user