Only show active plugins in config menu

This commit is contained in:
Maschell 2024-08-04 15:39:08 +02:00
parent 8941ac9f10
commit d65f2a29a1
4 changed files with 25 additions and 15 deletions

View File

@ -217,7 +217,7 @@ void CleanupPlugins(std::vector<PluginContainer> &&pluginsToDeinit) {
for (const auto &pluginContainer : pluginsToDeinit) { for (const auto &pluginContainer : pluginsToDeinit) {
for (auto &cur : gTrampData) { for (auto &cur : gTrampData) {
if (!pluginContainer.isPluginLinkedAndLoaded() || cur.id != pluginContainer.getPluginLinkInformation()->getTrampolineId()) { if (!pluginContainer.isLinkedAndLoaded() || cur.id != pluginContainer.getPluginLinkInformation().getTrampolineId()) {
continue; continue;
} }
cur.status = RELOC_TRAMP_FREE; cur.status = RELOC_TRAMP_FREE;

View File

@ -5,6 +5,11 @@
#include "utils/utils.h" #include "utils/utils.h"
ConfigRenderer::ConfigRenderer(std::vector<ConfigDisplayItem> &&vec) : mConfigs(std::move(vec)) { ConfigRenderer::ConfigRenderer(std::vector<ConfigDisplayItem> &&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; ConfigRenderer::~ConfigRenderer() = default;
@ -65,13 +70,13 @@ void ConfigRenderer::ResetNeedsRedraw() {
} }
ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
if (mConfigs.empty()) { if (mActiveConfigs.empty()) {
mNeedRedraw = true; mNeedRedraw = true;
return SUB_STATE_ERROR; return SUB_STATE_ERROR;
} }
const auto prevSelectedItem = mCursorPos; const auto prevSelectedItem = mCursorPos;
const auto totalElementSize = static_cast<int32_t>(mConfigs.size()); const auto totalElementSize = mActiveConfigs.size();
if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) { if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) {
mCursorPos++; mCursorPos++;
} else if (input.data.buttons_d & Input::eButtons::BUTTON_LEFT) { } else if (input.data.buttons_d & Input::eButtons::BUTTON_LEFT) {
@ -88,10 +93,12 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
mCursorPos = totalElementSize - 1; mCursorPos = totalElementSize - 1;
} else if (input.data.buttons_d & Input::eButtons::BUTTON_UP) { } else if (input.data.buttons_d & Input::eButtons::BUTTON_UP) {
mCursorPos--; mCursorPos--;
} else if (input.data.buttons_d & Input::eButtons::BUTTON_X) {
mSetActivePluginsMode = !mSetActivePluginsMode;
} else if (input.data.buttons_d & Input::eButtons::BUTTON_A) { } else if (input.data.buttons_d & Input::eButtons::BUTTON_A) {
if (mCursorPos != mCurrentOpen) { if (mCursorPos != mCurrentOpen) {
mCategoryRenderer.reset(); mCategoryRenderer.reset();
mCategoryRenderer = make_unique_nothrow<CategoryRenderer>(&(mConfigs[mCursorPos].getConfigInformation()), &(mConfigs[mCursorPos].getConfig()), true); mCategoryRenderer = make_unique_nothrow<CategoryRenderer>(&(mActiveConfigs[mCursorPos].get().getConfigInformation()), &(mActiveConfigs[mCursorPos].get().getConfig()), true);
} }
mNeedRedraw = true; mNeedRedraw = true;
mCurrentOpen = mCursorPos; 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)) { } else if (input.data.buttons_d & (Input::eButtons::BUTTON_B | Input::eButtons::BUTTON_HOME)) {
mNeedRedraw = true; mNeedRedraw = true;
mCategoryRenderer.reset(); mCategoryRenderer.reset();
for (const auto &element : mConfigs) { for (const auto &element : mActiveConfigs) {
CallOnCloseCallback(element.getConfigInformation(), element.getConfig()); CallOnCloseCallback(element.get().getConfigInformation(), element.get().getConfig());
} }
return SUB_STATE_RETURN; return SUB_STATE_RETURN;
} }
@ -126,18 +133,19 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
return SUB_STATE_RUNNING; return SUB_STATE_RUNNING;
} }
void ConfigRenderer::RenderStateMain() const { void ConfigRenderer::RenderStateMain() const {
const auto totalElementSize = static_cast<int32_t>(mConfigs.size()); auto totalElementSize = (int32_t) mActiveConfigs.size();
// Calculate the range of items to display // Calculate the range of items to display
const int start = std::max(0, mRenderOffset); int start = std::max(0, mRenderOffset);
const int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize); int end = std::min(start + MAX_BUTTONS_ON_SCREEN, totalElementSize);
DrawUtils::beginDraw(); DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BACKGROUND); DrawUtils::clear(COLOR_BACKGROUND);
uint32_t yOffset = 8 + 24 + 8 + 4; uint32_t yOffset = 8 + 24 + 8 + 4;
for (int32_t i = start; i < end; i++) { 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; yOffset += 42 + 8;
} }
@ -153,7 +161,7 @@ void ConfigRenderer::RenderStateMain() const {
// draw bottom bar // draw bottom bar
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK); DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK);
DrawUtils::setFontSize(18); 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); DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, "\ue000 Select", true);
// draw scroll indicator // draw scroll indicator
@ -167,7 +175,7 @@ void ConfigRenderer::RenderStateMain() const {
// draw home button // draw home button
DrawUtils::setFontSize(18); 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::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 10, exitHint, true);
DrawUtils::endDraw(); DrawUtils::endDraw();

View File

@ -41,6 +41,7 @@ private:
}; };
std::vector<ConfigDisplayItem> mConfigs; std::vector<ConfigDisplayItem> mConfigs;
std::vector<std::reference_wrapper<ConfigDisplayItem>> mActiveConfigs;
std::unique_ptr<CategoryRenderer> mCategoryRenderer = {}; std::unique_ptr<CategoryRenderer> mCategoryRenderer = {};
State mState = STATE_MAIN; State mState = STATE_MAIN;
@ -49,5 +50,6 @@ private:
int32_t mRenderOffset = 0; int32_t mRenderOffset = 0;
int32_t mCurrentOpen = -1; int32_t mCurrentOpen = -1;
bool mSetActivePluginsMode = false;
bool mNeedRedraw = true; bool mNeedRedraw = true;
}; };

View File

@ -327,8 +327,8 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionMemoryAddresses(const wups_ba
continue; continue;
} }
if (curContainer.getHandle() == handle) { if (curContainer.getHandle() == handle) {
*textAddress = static_cast<void *>(curContainer.getPluginLinkInformation().getTextMemory().data()); *textAddress = (void *) curContainer.getPluginLinkInformation().getTextMemory().data();
*dataAddress = static_cast<void *>(curContainer.getPluginLinkInformation().getDataMemory().data()); *dataAddress = (void *) curContainer.getPluginLinkInformation().getDataMemory().data();
return PLUGIN_BACKEND_API_ERROR_NONE; return PLUGIN_BACKEND_API_ERROR_NONE;
} }
} }