From a02df47b0d3e8c03efef66d3bf1a08d2122a53ec Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 17 Jul 2016 14:30:09 +0100 Subject: [PATCH] Add active load order indices to sidebar Closes #555. --- resources/ui/css/dark-theme.css | 4 +++ src/backend/game/game.cpp | 33 ++++++++++++++++++ src/backend/game/game.h | 6 ++++ src/gui/html/elements/loot-plugin-item.html | 37 +++++++++++++++++++-- src/gui/html/index.html | 1 + src/gui/html/js/plugin.js | 1 + src/gui/query_handler.cpp | 1 + src/tests/backend/game/game_test.h | 25 ++++++++++++++ 8 files changed, 105 insertions(+), 3 deletions(-) diff --git a/resources/ui/css/dark-theme.css b/resources/ui/css/dark-theme.css index 96c23716..84009941 100644 --- a/resources/ui/css/dark-theme.css +++ b/resources/ui/css/dark-theme.css @@ -31,6 +31,10 @@ the background behind cards. */ --secondary-background-color: #303030; --paper-progress-container-color: var(--secondary-background-color); + + /* --loot-plugin-item-index-border-color is used to control the colour of the + border around load order indices in the sidebar. */ + --loot-plugin-item-index-border-color: var(--paper-color-300); } #main { diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index e73c72f1..ebfd6255 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -196,4 +196,37 @@ bool Game::IsPluginActive(const std::string& pluginName) const { return LoadOrderHandler::IsPluginActive(pluginName); } } + +short Game::GetActiveLoadOrderIndex(const std::string & pluginName) 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. + + if (!IsPluginActive(pluginName)) + return -1; + + short numberOfActivePlugins = 0; + for (const std::string& plugin : GetLoadOrder()) { + if (boost::iequals(plugin, pluginName)) + return numberOfActivePlugins; + + if (IsPluginActive(plugin)) + ++numberOfActivePlugins; + } + + return -1; +} +std::list Game::GetLoadOrder() const { + if (loadOrder_.empty()) + loadOrder_ = LoadOrderHandler::GetLoadOrder(); + + return loadOrder_; +} +void Game::SetLoadOrder(const std::list& loadOrder) const { + LoadOrderHandler::SetLoadOrder(loadOrder); + loadOrder_ = loadOrder; +} +void Game::SetLoadOrder(const char * const * const loadOrder, const size_t numPlugins) const { + LoadOrderHandler::SetLoadOrder(loadOrder, numPlugins); +} } diff --git a/src/backend/game/game.h b/src/backend/game/game.h index 1f73b662..b7429612 100644 --- a/src/backend/game/game.h +++ b/src/backend/game/game.h @@ -51,8 +51,14 @@ public: // Check if the plugin is active by using the cached value if // available, and otherwise asking the load order handler. bool IsPluginActive(const std::string& pluginName) const; + short GetActiveLoadOrderIndex(const std::string & pluginName) const; + + std::list GetLoadOrder() const; + void SetLoadOrder(const std::list& loadOrder) const; + void SetLoadOrder(const char * const * const loadOrder, const size_t numPlugins) const; private: bool pluginsFullyLoaded_; + mutable std::list loadOrder_; }; } diff --git a/src/gui/html/elements/loot-plugin-item.html b/src/gui/html/elements/loot-plugin-item.html index 93e9fc5a..84378d90 100644 --- a/src/gui/html/elements/loot-plugin-item.html +++ b/src/gui/html/elements/loot-plugin-item.html @@ -37,7 +37,7 @@ } /* paper-item (two-line) */ - paper-item { + paper-icon-item { position: relative; min-height: 32px; line-height: 32px; @@ -46,6 +46,8 @@ --paper-item-focused-before: { opacity: 0; }; + + --paper-item-icon-width: 32px; } paper-item-body[two-line] { min-height: 32px; @@ -54,6 +56,17 @@ :host-context(body[data-editors]) paper-item-body[two-line] { min-height: 40px; } + div[item-icon] { + border: 1px solid var(--loot-plugin-item-index-border-color, var(--paper-grey-400)); + border-radius: 50%; + color: var(--secondary-text-color); + height: 24px; + width: 24px; + line-height: 24px; + text-align: center; + font-family: monospace; + text-transform: uppercase; + } #primary, #secondary, #secondary iron-icon { @@ -94,8 +107,9 @@ color: var(--accent-color); } - + +
[[computeLoadOrderIndexText(loadOrderIndex)]]
@@ -110,13 +124,17 @@
-
+