From 58e72e89c35bd90b7a7a8574cf45c5a61afdf71f Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 18 Jan 2021 23:01:24 +0100 Subject: Fix editing priority. --- src/modlist.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index 1c097db4..ffa841ed 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -609,8 +609,7 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role) newPriority = 0; } if (ok) { - m_Profile->setModPriority(modID, newPriority); - emit modPrioritiesChanged({ index }); + changeModPriority(modID, newPriority); result = true; } else { result = false; -- cgit v1.3.1 From 8a49f2232e546e022a6f435b8a0d466911b0b58c Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 18 Jan 2021 23:02:15 +0100 Subject: Clamp priority to the correct value, taking backups into account. --- src/profile.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/profile.cpp b/src/profile.cpp index 029265e2..b77a8295 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -650,14 +650,22 @@ void Profile::setModPriority(unsigned int index, int &newPriority) return; } - for (std::map::iterator iter = m_ModIndexByPriority.begin(); iter != m_ModIndexByPriority.end(); iter++) { - if (newPriority < oldPriority && iter->first >= newPriority && iter->first < oldPriority) { - m_ModStatus.at(iter->second).m_Priority += 1; + // we need to put the mod before backups + auto it = std::find_if(m_ModIndexByPriority.begin(), m_ModIndexByPriority.end(), [](auto&& p) { + return ModInfo::getByIndex(p.second)->isBackup(); + }); + if (it != m_ModIndexByPriority.end() && it->first <= newPriority) { + newPriority = it->first - 1; + } + + for (auto& [priority, index] : m_ModIndexByPriority) { + if (newPriority < oldPriority && priority >= newPriority && priority < oldPriority) { + m_ModStatus.at(index).m_Priority += 1; } - else if (newPriority > oldPriority && iter->first <= newPriority && iter->first > oldPriority) { - m_ModStatus.at(iter->second).m_Priority -= 1; + else if (newPriority > oldPriority && priority <= newPriority && priority > oldPriority) { + m_ModStatus.at(index).m_Priority -= 1; } - lastPriority = std::max(lastPriority, iter->first); + lastPriority = std::max(lastPriority, priority); } newPriority = std::min(newPriority, lastPriority); -- cgit v1.3.1