From 9c8177405e94411e52cf0c227a508ed858fd0b26 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 4 Aug 2024 15:39:08 +0200 Subject: [PATCH] Only show active plugins in config menu --- source/utils/config/ConfigRenderer.cpp | 16 +++++++++------- source/utils/config/ConfigRenderer.h | 7 +++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/source/utils/config/ConfigRenderer.cpp b/source/utils/config/ConfigRenderer.cpp index d38e79c..39a08b7 100644 --- a/source/utils/config/ConfigRenderer.cpp +++ b/source/utils/config/ConfigRenderer.cpp @@ -1,7 +1,7 @@ #include "ConfigRenderer.h" void ConfigRenderer::RenderStateMain() const { - auto totalElementSize = (int32_t) mConfigs.size(); + auto totalElementSize = (int32_t) mActiveConfigs.size(); // Calculate the range of items to display int start = std::max(0, mRenderOffset); int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize); @@ -11,7 +11,7 @@ void ConfigRenderer::RenderStateMain() const { uint32_t yOffset = 8 + 24 + 8 + 4; for (int32_t i = start; i < end; i++) { - drawConfigEntry(yOffset, mConfigs[i].getConfigInformation(), i == mCursorPos); + drawConfigEntry(yOffset, mActiveConfigs[i].get().getConfigInformation(), i == mCursorPos); yOffset += 42 + 8; } @@ -65,21 +65,23 @@ void ConfigRenderer::drawConfigEntry(uint32_t yOffset, const GeneralConfigInform } ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { - if (mConfigs.empty()) { + if (mActiveConfigs.empty()) { mNeedRedraw = true; return SUB_STATE_ERROR; } auto prevSelectedItem = mCursorPos; - auto totalElementSize = mConfigs.size(); + auto totalElementSize = mActiveConfigs.size(); if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) { mCursorPos++; } else if (input.data.buttons_d & Input::eButtons::BUTTON_UP) { mCursorPos--; + } else if (input.data.buttons_d & Input::eButtons::BUTTON_X) { + mSetActivePluginsMode = !mSetActivePluginsMode; } else if (input.data.buttons_d & Input::eButtons::BUTTON_A) { if (mCursorPos != mCurrentOpen) { mCategoryRenderer.reset(); - mCategoryRenderer = make_unique_nothrow(&(mConfigs[mCursorPos].getConfigInformation()), &(mConfigs[mCursorPos].getConfig()), true); + mCategoryRenderer = make_unique_nothrow(&(mActiveConfigs[mCursorPos].get().getConfigInformation()), &(mActiveConfigs[mCursorPos].get().getConfig()), true); } mNeedRedraw = true; mCurrentOpen = mCursorPos; @@ -88,8 +90,8 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { } else if (input.data.buttons_d & (Input::eButtons::BUTTON_B | Input::eButtons::BUTTON_HOME)) { mNeedRedraw = true; mCategoryRenderer.reset(); - for (const auto &element : mConfigs) { - CallOnCloseCallback(element.getConfigInformation(), element.getConfig()); + for (const auto &element : mActiveConfigs) { + CallOnCloseCallback(element.get().getConfigInformation(), element.get().getConfig()); } return SUB_STATE_RETURN; } diff --git a/source/utils/config/ConfigRenderer.h b/source/utils/config/ConfigRenderer.h index 9309714..5e69bd2 100644 --- a/source/utils/config/ConfigRenderer.h +++ b/source/utils/config/ConfigRenderer.h @@ -11,7 +11,13 @@ class ConfigRenderer { public: explicit ConfigRenderer(std::vector &&vec) : mConfigs(std::move(vec)) { + std::copy_if(mConfigs.begin(), mConfigs.end(), + std::back_inserter(mActiveConfigs), + [&](const auto & value) { + return value.isActivePlugin(); + }); } + ~ConfigRenderer() = default; ConfigSubState Update(Input &input, const WUPSConfigSimplePadData &simpleInputData, const WUPSConfigComplexPadData &complexInputData); @@ -35,6 +41,7 @@ private: }; std::vector mConfigs; + std::vector> mActiveConfigs; std::unique_ptr mCategoryRenderer = {}; State mState = STATE_MAIN;