Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight masters of selected plugins #2140

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/colortable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ void ColorTable::load(Settings& s)
[this](auto&& v) {
m_settings->colors().setPluginListContained(v);
});

addColor(
QObject::tr("Plugin is master of selected plugin"), QColor(255, 255, 0, 64),
[this] {
return m_settings->colors().pluginListMaster();
},
[this](auto&& v) {
m_settings->colors().setPluginListMaster(v);
});
}

void ColorTable::resetColors()
Expand Down
31 changes: 28 additions & 3 deletions src/pluginlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ void PluginList::highlightPlugins(const std::vector<unsigned int>& modIndices,
this->columnCount() - 1));
}

void PluginList::highlightMasters(
const std::vector<unsigned int>& selectedPluginIndices)
{
for (auto& esp : m_ESPs) {
esp.isMasterOfSelectedPlugin = false;
}

for (const auto& pluginIndex : selectedPluginIndices) {
const ESPInfo& plugin = m_ESPs[pluginIndex];
for (const auto& master : plugin.masters) {
const auto iter = m_ESPsByName.find(master);
if (iter != m_ESPsByName.end()) {
m_ESPs[iter->second].isMasterOfSelectedPlugin = true;
}
}
}

emit dataChanged(this->index(0, 0), this->index(static_cast<int>(m_ESPs.size()) - 1,
this->columnCount() - 1));
}

void PluginList::refresh(const QString& profileName,
const DirectoryEntry& baseDirectory,
const QString& lockedOrderFile, bool force)
Expand Down Expand Up @@ -1306,10 +1327,13 @@ QVariant PluginList::foregroundData(const QModelIndex& modelIndex) const

QVariant PluginList::backgroundData(const QModelIndex& modelIndex) const
{
const int index = modelIndex.row();
const int index = modelIndex.row();
const ESPInfo& plugin = m_ESPs[index];

if (m_ESPs[index].modSelected) {
if (plugin.modSelected) {
return Settings::instance().colors().pluginListContained();
} else if (plugin.isMasterOfSelectedPlugin) {
return Settings::instance().colors().pluginListMaster();
}

return {};
Expand Down Expand Up @@ -1921,7 +1945,8 @@ PluginList::ESPInfo::ESPInfo(const QString& name, bool forceLoaded, bool forceEn
: name(name), fullPath(fullPath), enabled(forceLoaded), forceLoaded(forceLoaded),
forceEnabled(forceEnabled), forceDisabled(forceDisabled), priority(0),
loadOrder(-1), originName(originName), hasIni(hasIni),
archives(archives.begin(), archives.end()), modSelected(false)
archives(archives.begin(), archives.end()), modSelected(false),
isMasterOfSelectedPlugin(false)
{
try {
ESP::File file(ToWString(fullPath));
Expand Down
3 changes: 3 additions & 0 deletions src/pluginlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class PluginList : public QAbstractItemModel
void highlightPlugins(const std::vector<unsigned int>& modIndices,
const MOShared::DirectoryEntry& directoryEntry);

void highlightMasters(const std::vector<unsigned int>& selectedPluginIndices);

void refreshLoadOrder();

void disconnectSlots();
Expand Down Expand Up @@ -342,6 +344,7 @@ public slots:
bool isBlueprintFlagged;
bool hasNoRecords;
bool modSelected;
bool isMasterOfSelectedPlugin;
QString author;
QString description;
bool hasIni;
Expand Down
2 changes: 2 additions & 0 deletions src/pluginlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow*
pluginIndices.push_back(idx.row());
}
mwui->modList->setHighlightedMods(pluginIndices);
m_core->pluginList()->highlightMasters(pluginIndices);
verticalScrollBar()->repaint();
});

// using a lambda here to avoid storing the mod list actions
Expand Down
10 changes: 10 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,16 @@ void ColorSettings::setPluginListContained(const QColor& c)
set(m_Settings, "Settings", "containedColor", c);
}

QColor ColorSettings::pluginListMaster() const
{
return get<QColor>(m_Settings, "Settings", "masterColor", QColor(255, 255, 0, 64));
}

void ColorSettings::setPluginListMaster(const QColor& c)
{
set(m_Settings, "Settings", "masterColor", c);
}

std::optional<QColor> ColorSettings::previousSeparatorColor() const
{
const auto c = getOptional<QColor>(m_Settings, "General", "previousSeparatorColor");
Expand Down
3 changes: 3 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class ColorSettings
QColor pluginListContained() const;
void setPluginListContained(const QColor& c);

QColor pluginListMaster() const;
void setPluginListMaster(const QColor& c);

std::optional<QColor> previousSeparatorColor() const;
void setPreviousSeparatorColor(const QColor& c) const;
void removePreviousSeparatorColor();
Expand Down
Loading