From fa52fea59b2a5bca2f4574a430f76fb7ee91495b Mon Sep 17 00:00:00 2001 From: Andrew Lanzone Date: Mon, 12 May 2025 20:09:24 -0700 Subject: [PATCH] Better joystick/mouse coordination in save game diaglog --- apps/openmw/mwgui/savegamedialog.cpp | 44 +++++++++++++++++++++------- apps/openmw/mwgui/savegamedialog.hpp | 7 +++-- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 51fa4c6717..37ed137b23 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -161,6 +161,13 @@ namespace MWGui mSaveList->removeAllItems(); onSlotSelected(mSaveList, MyGUI::ITEM_NONE); + if (Settings::gui().mControllerMenus) + { + mOkButtonFocus = true; + mOkButton->setStateSelected(true); + mCancelButton->setStateSelected(false); + } + MWBase::StateManager* mgr = MWBase::Environment::get().getStateManager(); if (mgr->characterBegin() == mgr->characterEnd()) return; @@ -501,30 +508,40 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - if (mMouseFocus != nullptr) + // Have A button do nothing so mouse controller still works. + if (mUsingGamepadGuiCursor) return false; - onOkButtonClicked(mOkButton); - return true; + if (mOkButtonFocus) + onOkButtonClicked(mOkButton); + else + onCancelButtonClicked(mCancelButton); } else if (arg.button == SDL_CONTROLLER_BUTTON_B) { onCancelButtonClicked(mCancelButton); - return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mSaveList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); - return true; + mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mSaveList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - return true; + mUsingGamepadGuiCursor = false; + } + else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mOkButtonFocus) || + (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && mOkButtonFocus)) + { + mOkButtonFocus = !mOkButtonFocus; + mOkButton->setStateSelected(mOkButtonFocus); + mCancelButton->setStateSelected(!mOkButtonFocus); + mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) { @@ -534,8 +551,7 @@ namespace MWGui else index--; mCharacterSelection->setIndexSelected(index); - - return true; + mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) { @@ -545,10 +561,18 @@ namespace MWGui else index++; mCharacterSelection->setIndexSelected(index); - - return true; + mUsingGamepadGuiCursor = false; } + return true; + } + + bool SaveGameDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) + { + if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) + { + mUsingGamepadGuiCursor = true; + } return false; } } diff --git a/apps/openmw/mwgui/savegamedialog.hpp b/apps/openmw/mwgui/savegamedialog.hpp index caabff2431..2561fc60f6 100644 --- a/apps/openmw/mwgui/savegamedialog.hpp +++ b/apps/openmw/mwgui/savegamedialog.hpp @@ -24,8 +24,6 @@ namespace MWGui void setLoadOrSave(bool load); - bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - private: void confirmDeleteSave(); @@ -68,6 +66,11 @@ namespace MWGui const MWState::Character* mCurrentCharacter; const MWState::Slot* mCurrentSlot; + + bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; + bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; + bool mOkButtonFocus = true; + bool mUsingGamepadGuiCursor = false; }; }