From 95f3d6a3c55bb3f4e0cd99342a177f90027d7ece Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 5 Nov 2016 13:23:43 +0000 Subject: [PATCH] Update sidebar load order indices when sorting Fixes #686. --- src/backend/game/game.cpp | 6 +++++- src/backend/game/game.h | 1 + src/gui/query/sort_plugins_query.h | 19 +++++++++---------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index 04749695..b5ff5a59 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -206,6 +206,10 @@ bool Game::IsPluginActive(const std::string& pluginName) const { } short Game::GetActiveLoadOrderIndex(const std::string & pluginName) const { + return GetActiveLoadOrderIndex(pluginName, GetLoadOrder()); +} + +short Game::GetActiveLoadOrderIndex(const std::string & pluginName, const std::vector& loadOrder) const { // Get the full load order, then count the number of active plugins until the // given plugin is encountered. If the plugin isn't active or in the load // order, return -1. @@ -214,7 +218,7 @@ short Game::GetActiveLoadOrderIndex(const std::string & pluginName) const { return -1; short numberOfActivePlugins = 0; - for (const std::string& plugin : GetLoadOrder()) { + for (const std::string& plugin : loadOrder) { if (boost::iequals(plugin, pluginName)) return numberOfActivePlugins; diff --git a/src/backend/game/game.h b/src/backend/game/game.h index a56b78c1..3415a66c 100644 --- a/src/backend/game/game.h +++ b/src/backend/game/game.h @@ -51,6 +51,7 @@ public: // available, and otherwise asking the load order handler. bool IsPluginActive(const std::string& pluginName) const; short GetActiveLoadOrderIndex(const std::string & pluginName) const; + short GetActiveLoadOrderIndex(const std::string & pluginName, const std::vector& loadOrder) const; std::vector GetLoadOrder() const; void SetLoadOrder(const std::vector& loadOrder) const; diff --git a/src/gui/query/sort_plugins_query.h b/src/gui/query/sort_plugins_query.h index 8892c209..ea3f777a 100644 --- a/src/gui/query/sort_plugins_query.h +++ b/src/gui/query/sort_plugins_query.h @@ -51,7 +51,12 @@ public: //Sort plugins into their load order. std::vector plugins = sortPlugins(); - if ((state_.getCurrentGame().Type() == GameType::tes5 + sortedPluginNames.resize(plugins.size()); + std::transform(begin(plugins), end(plugins), begin(sortedPluginNames), [](const Plugin& plugin) { + return plugin.Name(); + }); + + if ((state_.getCurrentGame().Type() == GameType::tes5 || state_.getCurrentGame().Type() == GameType::fo4 || state_.getCurrentGame().Type() == GameType::tes5se)) applyUnchangedLoadOrder(plugins); @@ -100,19 +105,12 @@ private: } YAML::Node generateDerivedMetadata(const Plugin& plugin) { - YAML::Node pluginNode; + YAML::Node pluginNode = MetadataQuery::generateDerivedMetadata(plugin.Name()); pluginNode["name"] = plugin.Name(); pluginNode["crc"] = plugin.Crc(); pluginNode["isEmpty"] = plugin.IsEmpty(); - - // Sorting may have produced a plugin loading error message, so rederive displayed data. - YAML::Node derivedNode = MetadataQuery::generateDerivedMetadata(plugin.Name()); - - for (const auto &pair : derivedNode) { - const std::string key = pair.first.as(); - pluginNode[key] = pair.second; - } + pluginNode["loadOrderIndex"] = state_.getCurrentGame().GetActiveLoadOrderIndex(plugin.Name(), sortedPluginNames); return pluginNode; } @@ -135,6 +133,7 @@ private: LootState& state_; CefRefPtr frame_; + std::vector sortedPluginNames; }; }