From 122744454c9befc06b582a8f0feb03bfbb85aa71 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Wed, 31 Oct 2018 20:00:20 -0500 Subject: Improve changing mod and plugin priorities --- src/pluginlist.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/pluginlist.cpp') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 4097ba98..8f714afd 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -1183,17 +1183,35 @@ void PluginList::setPluginPriority(int row, int &newPriority) void PluginList::changePluginPriority(std::vector rows, int newPriority) { ChangeBracket layoutChange(this); - // sort rows to insert by their old priority (ascending) and insert them move them in that order const std::vector &esp = m_ESPs; + + int minPriority = INT_MAX; + int maxPriority = INT_MIN; + + // don't try to move plugins before force-enabled plugins + for (std::vector::const_iterator iter = m_ESPs.begin(); + iter != m_ESPs.end(); ++iter) { + if (iter->m_ForceEnabled) { + newPriority = std::max(newPriority, iter->m_Priority+1); + } + maxPriority = std::max(maxPriority, iter->m_Priority+1); + minPriority = std::min(minPriority, iter->m_Priority); + } + + // limit the new priority to existing priorities + newPriority = std::min(newPriority, maxPriority); + newPriority = std::max(newPriority, minPriority); + + // sort the moving plugins by ascending priorities std::sort(rows.begin(), rows.end(), - [&esp](const int &LHS, const int &RHS) { - return esp[LHS].m_Priority < esp[RHS].m_Priority; - }); + [&esp](const int &LHS, const int &RHS) { + return esp[LHS].m_Priority < esp[RHS].m_Priority; + }); - // odd stuff: if any of the dragged sources has priority lower than the destination then the - // target idx is that of the row BELOW the dropped location, otherwise it's the one above. why? + // if at least on plugin is increasing in priority, the target index is + // that of the row BELOW the dropped location, otherwise it's the one above for (std::vector::const_iterator iter = rows.begin(); - iter != rows.end(); ++iter) { + iter != rows.end(); ++iter) { if (m_ESPs[*iter].m_Priority < newPriority) { --newPriority; break; -- cgit v1.3.1