From ea1ecf7c5107655363333df7f88f3cbb526c35f4 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 9 Aug 2024 15:42:12 +0200 Subject: [PATCH] Fix config menu when no plugins are loaded, improve UI --- source/utils/config/ConfigRenderer.cpp | 72 ++++++++++++++++++-------- source/utils/config/ConfigUtils.cpp | 1 - source/utils/utils.cpp | 4 +- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/source/utils/config/ConfigRenderer.cpp b/source/utils/config/ConfigRenderer.cpp index 78a2d3f..715aa75 100644 --- a/source/utils/config/ConfigRenderer.cpp +++ b/source/utils/config/ConfigRenderer.cpp @@ -2,11 +2,11 @@ #include "globals.h" #include "plugin/PluginLoadWrapper.h" #include "utils/DrawUtils.h" +#include "utils/StringTools.h" #include "utils/logger.h" #include "utils/utils.h" #include -#include ConfigRenderer::ConfigRenderer(std::vector &&vec) : mConfigs(std::move(vec)) { std::copy(mConfigs.begin(), mConfigs.end(), @@ -77,13 +77,9 @@ void ConfigRenderer::ResetNeedsRedraw() { ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { auto &configs = GetConfigList(); - if (configs.empty()) { - mNeedRedraw = true; - return SUB_STATE_ERROR; - } + auto prevSelectedItem = mCursorPos; - auto totalElementSize = configs.size(); if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) { mCursorPos++; } else if (input.data.buttons_d & Input::eButtons::BUTTON_UP) { @@ -95,7 +91,7 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { return SUB_STATE_RETURN_WITH_PLUGIN_RELOAD; } } else if (input.data.buttons_d & Input::eButtons::BUTTON_X) { - if (!mSetActivePluginsMode) { + if (!mSetActivePluginsMode && !mAllConfigs.empty()) { mSetActivePluginsMode = true; mNeedRedraw = true; return SUB_STATE_RUNNING; @@ -106,7 +102,7 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { mNeedRedraw = true; configs[mCursorPos].get().toggleIsActivePlugin(); return SUB_STATE_RUNNING; - } else { + } else if (!configs.empty()) { if (mCursorPos != mCurrentOpen) { mCategoryRenderer.reset(); mCategoryRenderer = make_unique_nothrow(&(configs[mCursorPos].get().getConfigInformation()), &(configs[mCursorPos].get().getConfig()), true); @@ -134,9 +130,13 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { } } + auto totalElementSize = (int32_t) configs.size(); + if (mCursorPos < 0) { + mCursorPos = totalElementSize - 1; + } else if (mCursorPos > (totalElementSize - 1)) { + mCursorPos = 0; + } if (mCursorPos < 0) { - mCursorPos = (int32_t) totalElementSize - 1; - } else if (mCursorPos > (int32_t) (totalElementSize - 1)) { mCursorPos = 0; } @@ -155,19 +155,37 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { } void ConfigRenderer::RenderStateMain() const { - auto &configs = GetConfigList(); - auto totalElementSize = (int32_t) configs.size(); - // Calculate the range of items to display - int start = std::max(0, mRenderOffset); - int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize); + auto &configs = GetConfigList(); DrawUtils::beginDraw(); DrawUtils::clear(COLOR_BACKGROUND); - uint32_t yOffset = 8 + 24 + 8 + 4; - for (int32_t i = start; i < end; i++) { - DrawConfigEntry(yOffset, configs[i].get().getConfigInformation(), i == mCursorPos, configs[i].get().isActivePlugin()); - yOffset += 42 + 8; + auto totalElementSize = (int32_t) configs.size(); + + // Calculate the range of items to display + int start = std::max(0, mRenderOffset); + int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize); + + if (mActiveConfigs.empty() && !mSetActivePluginsMode) { + DrawUtils::setFontSize(24); + std::string noConfigText = "No active plugins"; + uint32_t szNoConfig = DrawUtils::getTextWidth(noConfigText.data()); + + if (!mAllConfigs.empty()) { + std::string activateHint = "Press \ue002 to activate inactive plugins"; + auto szHint = DrawUtils::getTextWidth(activateHint.c_str()); + + DrawUtils::print((SCREEN_WIDTH / 2) - (szNoConfig / 2), (SCREEN_HEIGHT / 2) - 16, noConfigText.data()); + DrawUtils::print((SCREEN_WIDTH / 2) - (szHint / 2), (SCREEN_HEIGHT / 2) + 16, activateHint.data()); + } else { + DrawUtils::print((SCREEN_WIDTH / 2) - (szNoConfig / 2), (SCREEN_HEIGHT / 2), noConfigText.data()); + } + } else { + uint32_t yOffset = 8 + 24 + 8 + 4; + for (int32_t i = start; i < end; i++) { + DrawConfigEntry(yOffset, configs[i].get().getConfigInformation(), i == mCursorPos, configs[i].get().isActivePlugin()); + yOffset += 42 + 8; + } } DrawUtils::setFontColor(COLOR_TEXT); @@ -178,6 +196,13 @@ void ConfigRenderer::RenderStateMain() const { DrawUtils::print(16, 6 + 24, "Please select the plugin that should be active"); } else { DrawUtils::print(16, 6 + 24, "Wii U Plugin System Config Menu"); + + auto countInactivePlugins = mAllConfigs.size() - mActiveConfigs.size(); + if (countInactivePlugins > 0) { + DrawUtils::setFontSize(14); + std::string plugin_unloaded = string_format("Found %d inactive plugins", countInactivePlugins); + DrawUtils::print(SCREEN_WIDTH - 16 - DrawUtils::getTextWidth(MODULE_VERSION_FULL) - 32, 8 + 24, plugin_unloaded.c_str(), true); + } } DrawUtils::setFontSize(18); DrawUtils::print(SCREEN_WIDTH - 16, 8 + 24, MODULE_VERSION_FULL, true); @@ -188,9 +213,9 @@ void ConfigRenderer::RenderStateMain() const { DrawUtils::setFontSize(18); DrawUtils::print(16, SCREEN_HEIGHT - 10, "\ue07d Navigate "); if (mSetActivePluginsMode) { - DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, "\ue000 Select | \uE045 Apply", true); - } else { - DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, "\ue000 Activate", true); + DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, "\ue000 Activate | \uE045 Apply", true); + } else if (totalElementSize > 0) { + DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, "\ue000 Select", true); } // draw scroll indicator @@ -205,6 +230,9 @@ void ConfigRenderer::RenderStateMain() const { // draw home button DrawUtils::setFontSize(18); const char *exitHint = "\ue044 Exit"; + if (mSetActivePluginsMode) { + exitHint = "\ue001 Abort"; + } DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 10, exitHint, true); DrawUtils::endDraw(); diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index 380e53e..b8f265c 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -219,7 +219,6 @@ void ConfigUtils::displayMenu() { startTime = OSGetTime(); - DEBUG_FUNCTION_LINE_INFO("."); std::vector newActivePluginsList; if (renderer.GetActivePluginsIfChanged(newActivePluginsList)) { diff --git a/source/utils/utils.cpp b/source/utils/utils.cpp index b9040c1..44b777e 100644 --- a/source/utils/utils.cpp +++ b/source/utils/utils.cpp @@ -115,11 +115,11 @@ void CustomDynLoadFree(void *addr) { bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson) { CFile file(filePath, CFile::ReadOnly); if (!file.isOpen() || file.size() == 0) { - return WUPS_STORAGE_ERROR_NOT_FOUND; + return false; } auto *json_data = (uint8_t *) memalign(0x40, ROUNDUP(file.size() + 1, 0x40)); if (!json_data) { - return WUPS_STORAGE_ERROR_MALLOC_FAILED; + return false; } bool result = true; uint64_t readRes = file.read(json_data, file.size());