From 58c4e0ddf735747105c5fc4c2db7a0aa912888a3 Mon Sep 17 00:00:00 2001 From: Andrew Lanzone Date: Sat, 10 May 2025 01:41:53 -0700 Subject: [PATCH] Minimal controller bindings for save/load window --- apps/openmw/mwgui/savegamedialog.cpp | 58 ++++++++++++++++++++++++++++ apps/openmw/mwgui/savegamedialog.hpp | 2 + 2 files changed, 60 insertions(+) diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 94f25e118b..fc6171b8dc 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -63,6 +63,9 @@ namespace MWGui // To avoid accidental deletions mDeleteButton->setNeedKeyFocus(false); + + trackFocusEvents(mCancelButton); + trackFocusEvents(mDeleteButton); } void SaveGameDialog::onSlotActivated(MyGUI::ListBox* sender, size_t pos) @@ -487,4 +490,59 @@ namespace MWGui mScreenshotTexture = std::make_unique(texture); mScreenshot->setRenderItemTexture(mScreenshotTexture.get()); } + + bool SaveGameDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) + { + if (arg.button == SDL_CONTROLLER_BUTTON_A) + { + if (mMouseFocus != nullptr) + return false; + + onOkButtonClicked(mOkButton); + return true; + } + 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; + } + 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; + } + else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) + { + uint32_t index = mCharacterSelection->getIndexSelected(); + if (index <= 0) + index = mCharacterSelection->getItemCount() - 1; + else + index--; + mCharacterSelection->setIndexSelected(index); + + return true; + } + else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) + { + uint32_t index = mCharacterSelection->getIndexSelected(); + if (index >= mCharacterSelection->getItemCount() - 1) + index = 0; + else + index++; + mCharacterSelection->setIndexSelected(index); + + return true; + } + + return false; + } } diff --git a/apps/openmw/mwgui/savegamedialog.hpp b/apps/openmw/mwgui/savegamedialog.hpp index 35e65fbed0..caabff2431 100644 --- a/apps/openmw/mwgui/savegamedialog.hpp +++ b/apps/openmw/mwgui/savegamedialog.hpp @@ -24,6 +24,8 @@ namespace MWGui void setLoadOrSave(bool load); + bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; + private: void confirmDeleteSave();