diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-08-29 12:48:17 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-08-29 12:48:17 +0200 |
| commit | 600a4b3b14db8d7610757c852876641c49612864 (patch) | |
| tree | aa92bc736b1513081945b5c897a2ead064131502 /src/modlist.cpp | |
| parent | f0e94c26aebae6f86a59ed974e433f96e77faec7 (diff) | |
Add a bulk-version of ModList::setActive.
Diffstat (limited to 'src/modlist.cpp')
| -rw-r--r-- | src/modlist.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/modlist.cpp b/src/modlist.cpp index cb08c6f4..b093fd88 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -962,6 +962,40 @@ bool ModList::setActive(const QString &name, bool active) } } +int ModList::setActive(const QStringList& names, bool active) { + + // We only add indices for mods that exist (modIndex != UINT_MAX) + // and that can be enabled / disabled. + QList<unsigned int> indices; + for (const auto& name : names) { + auto modIndex = ModInfo::getIndex(name); + if (modIndex != UINT_MAX) { + + // This check is not done by the bulk Profile::setModsEnabled, so we + // do it here. + ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); + if (!modInfo->alwaysEnabled()) { + indices.append(modIndex); + } + } + } + + if (active) { + m_Profile->setModsEnabled(indices, {}); + } + else { + m_Profile->setModsEnabled({}, indices); + } + + // Notify callbacks: + for (auto modIndex : indices) { + IModList::ModStates newState = state(modIndex); + m_ModStateChanged(ModInfo::getByIndex(modIndex)->name(), newState); + } + + return indices.size(); +} + int ModList::priority(const QString &name) const { unsigned int modIndex = ModInfo::getIndex(name); |
