From d65f2a29a1fb3a9ea1253924f8cce977e8dfbded 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/main.cpp | 2 +- source/utils/config/ConfigRenderer.cpp | 30 ++++++++++++++++---------- source/utils/config/ConfigRenderer.h | 4 +++- source/utils/exports.cpp | 4 ++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 5e77f43..a65d221 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -217,7 +217,7 @@ void CleanupPlugins(std::vector &&pluginsToDeinit) { for (const auto &pluginContainer : pluginsToDeinit) { for (auto &cur : gTrampData) { - if (!pluginContainer.isPluginLinkedAndLoaded() || cur.id != pluginContainer.getPluginLinkInformation()->getTrampolineId()) { + if (!pluginContainer.isLinkedAndLoaded() || cur.id != pluginContainer.getPluginLinkInformation().getTrampolineId()) { continue; } cur.status = RELOC_TRAMP_FREE; diff --git a/source/utils/config/ConfigRenderer.cpp b/source/utils/config/ConfigRenderer.cpp index 3cbe8a1..395d0d3 100644 --- a/source/utils/config/ConfigRenderer.cpp +++ b/source/utils/config/ConfigRenderer.cpp @@ -5,6 +5,11 @@ #include "utils/utils.h" ConfigRenderer::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::~ConfigRenderer() = default; @@ -65,13 +70,13 @@ void ConfigRenderer::ResetNeedsRedraw() { } ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { - if (mConfigs.empty()) { + if (mActiveConfigs.empty()) { mNeedRedraw = true; return SUB_STATE_ERROR; } const auto prevSelectedItem = mCursorPos; - const auto totalElementSize = static_cast(mConfigs.size()); + const auto totalElementSize = mActiveConfigs.size(); if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) { mCursorPos++; } else if (input.data.buttons_d & Input::eButtons::BUTTON_LEFT) { @@ -88,10 +93,12 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { mCursorPos = totalElementSize - 1; } 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; @@ -100,8 +107,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; } @@ -126,18 +133,19 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { return SUB_STATE_RUNNING; } + void ConfigRenderer::RenderStateMain() const { - const auto totalElementSize = static_cast(mConfigs.size()); + auto totalElementSize = (int32_t) mActiveConfigs.size(); // Calculate the range of items to display - const int start = std::max(0, mRenderOffset); - const int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize); + int start = std::max(0, mRenderOffset); + int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize); DrawUtils::beginDraw(); DrawUtils::clear(COLOR_BACKGROUND); 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; } @@ -153,7 +161,7 @@ void ConfigRenderer::RenderStateMain() const { // draw bottom bar DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK); DrawUtils::setFontSize(18); - DrawUtils::print(16, SCREEN_HEIGHT - 10, "\ue07d/\ue07e Navigate "); + DrawUtils::print(16, SCREEN_HEIGHT - 10, "\ue07d Navigate "); DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, "\ue000 Select", true); // draw scroll indicator @@ -167,7 +175,7 @@ void ConfigRenderer::RenderStateMain() const { // draw home button DrawUtils::setFontSize(18); - const auto exitHint = "\ue044 Exit"; + const char *exitHint = "\ue044 Exit"; DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 10, exitHint, true); DrawUtils::endDraw(); diff --git a/source/utils/config/ConfigRenderer.h b/source/utils/config/ConfigRenderer.h index d686bcf..367fae1 100644 --- a/source/utils/config/ConfigRenderer.h +++ b/source/utils/config/ConfigRenderer.h @@ -41,6 +41,7 @@ private: }; std::vector mConfigs; + std::vector> mActiveConfigs; std::unique_ptr mCategoryRenderer = {}; State mState = STATE_MAIN; @@ -49,5 +50,6 @@ private: int32_t mRenderOffset = 0; int32_t mCurrentOpen = -1; - bool mNeedRedraw = true; + bool mSetActivePluginsMode = false; + bool mNeedRedraw = true; }; diff --git a/source/utils/exports.cpp b/source/utils/exports.cpp index ec093b1..5f56053 100644 --- a/source/utils/exports.cpp +++ b/source/utils/exports.cpp @@ -327,8 +327,8 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionMemoryAddresses(const wups_ba continue; } if (curContainer.getHandle() == handle) { - *textAddress = static_cast(curContainer.getPluginLinkInformation().getTextMemory().data()); - *dataAddress = static_cast(curContainer.getPluginLinkInformation().getDataMemory().data()); + *textAddress = (void *) curContainer.getPluginLinkInformation().getTextMemory().data(); + *dataAddress = (void *) curContainer.getPluginLinkInformation().getDataMemory().data(); return PLUGIN_BACKEND_API_ERROR_NONE; } }