From 5d5d14a5a601cb186f0a3f1e33a79c9c927cfc76 Mon Sep 17 00:00:00 2001 From: Andrew Lanzone Date: Tue, 29 Jul 2025 17:28:52 -0700 Subject: [PATCH] Fix spurious button presses causing controller tooltip to wiggle --- apps/openmw/mwgui/itemview.cpp | 76 ++++++++-------- apps/openmw/mwgui/spellbuyingwindow.cpp | 2 + apps/openmw/mwgui/spellcreationdialog.cpp | 2 + apps/openmw/mwgui/spellview.cpp | 105 ++++++++++++---------- 4 files changed, 100 insertions(+), 85 deletions(-) diff --git a/apps/openmw/mwgui/itemview.cpp b/apps/openmw/mwgui/itemview.cpp index a01eaad2e8..243837bb65 100644 --- a/apps/openmw/mwgui/itemview.cpp +++ b/apps/openmw/mwgui/itemview.cpp @@ -206,44 +206,46 @@ namespace MWGui int prevFocus = mControllerFocus; - if (button == SDL_CONTROLLER_BUTTON_A) + switch (button) { - // Select the focused item, if any. - if (mControllerFocus >= 0 && mControllerFocus < mItemCount) - { - MyGUI::Widget* dragArea = mScrollView->getChildAt(0); - onSelectedItem(dragArea->getChildAt(mControllerFocus)); - } - } - else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK) - { - // Toggle info tooltip - MWBase::Environment::get().getWindowManager()->setControllerTooltip( - !MWBase::Environment::get().getWindowManager()->getControllerTooltip()); - updateControllerFocus(-1, mControllerFocus); - } - else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP) - { - if (mControllerFocus % mRows == 0) - mControllerFocus = std::min(mControllerFocus + mRows - 1, mItemCount - 1); - else - mControllerFocus--; - } - else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - { - if (mControllerFocus % mRows == mRows - 1 || mControllerFocus == mItemCount - 1) - mControllerFocus -= mControllerFocus % mRows; - else - mControllerFocus++; - } - else if (button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mControllerFocus >= mRows) - mControllerFocus -= mRows; - else if (button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) - { - if (mControllerFocus + mRows < mItemCount) - mControllerFocus += mRows; - else if (mControllerFocus / mRows != (mItemCount - 1) / mRows) - mControllerFocus = mItemCount - 1; + case SDL_CONTROLLER_BUTTON_A: + // Select the focused item, if any. + if (mControllerFocus >= 0 && mControllerFocus < mItemCount) + { + MyGUI::Widget* dragArea = mScrollView->getChildAt(0); + onSelectedItem(dragArea->getChildAt(mControllerFocus)); + } + break; + case SDL_CONTROLLER_BUTTON_RIGHTSTICK: + // Toggle info tooltip + MWBase::Environment::get().getWindowManager()->setControllerTooltip( + !MWBase::Environment::get().getWindowManager()->getControllerTooltip()); + updateControllerFocus(-1, mControllerFocus); + break; + case SDL_CONTROLLER_BUTTON_DPAD_UP: + if (mControllerFocus % mRows == 0) + mControllerFocus = std::min(mControllerFocus + mRows - 1, mItemCount - 1); + else + mControllerFocus--; + break; + case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + if (mControllerFocus % mRows == mRows - 1 || mControllerFocus == mItemCount - 1) + mControllerFocus -= mControllerFocus % mRows; + else + mControllerFocus++; + break; + case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + if (mControllerFocus >= mRows) + mControllerFocus -= mRows; + break; + case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + if (mControllerFocus + mRows < mItemCount) + mControllerFocus += mRows; + else if (mControllerFocus / mRows != (mItemCount - 1) / mRows) + mControllerFocus = mItemCount - 1; + break; + default: + return; } if (prevFocus != mControllerFocus) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 854b2f53ec..4a9f118d75 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -263,6 +263,8 @@ namespace MWGui mControllerFocus = wrap(mControllerFocus + 1, mSpellButtons.size()); mSpellButtons[mControllerFocus].first->setStateSelected(true); } + else + return true; if (mControllerFocus < mSpellButtons.size()) { diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index e30dd03fd5..558c25fb9a 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -1109,6 +1109,8 @@ namespace MWGui winMgr->setControllerTooltip(false); } + else + return true; // Scroll the list to keep the active item in view if (mAvailableFocus <= 5) diff --git a/apps/openmw/mwgui/spellview.cpp b/apps/openmw/mwgui/spellview.cpp index ee1755e706..ff77284bdf 100644 --- a/apps/openmw/mwgui/spellview.cpp +++ b/apps/openmw/mwgui/spellview.cpp @@ -351,58 +351,67 @@ namespace MWGui int prevFocus = mControllerFocus; - if (button == SDL_CONTROLLER_BUTTON_A) + switch (button) { - // Select the focused item, if any. - if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size())) - { - onSpellSelected(mButtons[mControllerFocus].first); - MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); - } - } - else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK) - { - // Toggle info tooltip - MWBase::Environment::get().getWindowManager()->setControllerTooltip( - !MWBase::Environment::get().getWindowManager()->getControllerTooltip()); - } - else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP) - mControllerFocus--; - else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - mControllerFocus++; - else if (button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) - mControllerFocus = std::max(0, mControllerFocus - 10); - else if (button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) - mControllerFocus = std::min(mControllerFocus + 10, static_cast(mButtons.size()) - 1); - else if (button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) - { - // Jump to first item in previous group - int prevGroupIndex = 0; - for (int groupIndex : mGroupIndices) - { - if (groupIndex >= mControllerFocus) - break; - else - prevGroupIndex = groupIndex; - } - mControllerFocus = prevGroupIndex; - } - else if (button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) - { - // Jump to first item in next group - int newFocus = mControllerFocus; - for (int groupIndex : mGroupIndices) - { - if (groupIndex > mControllerFocus) + case SDL_CONTROLLER_BUTTON_A: + // Select the focused item, if any. + if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size())) { - newFocus = groupIndex; - break; + onSpellSelected(mButtons[mControllerFocus].first); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); } + break; + case SDL_CONTROLLER_BUTTON_RIGHTSTICK: + // Toggle info tooltip + MWBase::Environment::get().getWindowManager()->setControllerTooltip( + !MWBase::Environment::get().getWindowManager()->getControllerTooltip()); + break; + case SDL_CONTROLLER_BUTTON_DPAD_UP: + mControllerFocus--; + break; + case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + mControllerFocus++; + break; + case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + mControllerFocus = std::max(0, mControllerFocus - 10); + break; + case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + mControllerFocus = std::min(mControllerFocus + 10, static_cast(mButtons.size()) - 1); + break; + case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + { + // Jump to first item in previous group + int prevGroupIndex = 0; + for (int groupIndex : mGroupIndices) + { + if (groupIndex >= mControllerFocus) + break; + else + prevGroupIndex = groupIndex; + } + mControllerFocus = prevGroupIndex; } - // If on last group, jump to bottom of whole list - if (newFocus == mControllerFocus) - newFocus = mButtons.size() - 1; - mControllerFocus = newFocus; + break; + case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + { + // Jump to first item in next group + int newFocus = mControllerFocus; + for (int groupIndex : mGroupIndices) + { + if (groupIndex > mControllerFocus) + { + newFocus = groupIndex; + break; + } + } + // If on last group, jump to bottom of whole list + if (newFocus == mControllerFocus) + newFocus = mButtons.size() - 1; + mControllerFocus = newFocus; + } + break; + default: + return; } mControllerFocus = wrap(mControllerFocus, mButtons.size());