From f80d46dc94af710079d66bbc2351e76f4229c26e Mon Sep 17 00:00:00 2001 From: Andrew Lanzone Date: Sun, 18 May 2025 15:34:22 -0700 Subject: [PATCH] Add controller support to count dialog --- apps/openmw/mwgui/countdialog.cpp | 17 +++++++++++++++++ apps/openmw/mwgui/countdialog.hpp | 1 + 2 files changed, 18 insertions(+) diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp index 2ca6657a17..75a2fc6034 100644 --- a/apps/openmw/mwgui/countdialog.cpp +++ b/apps/openmw/mwgui/countdialog.cpp @@ -27,6 +27,9 @@ namespace MWGui mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved); // make sure we read the enter key being pressed to accept multiple items mItemEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &CountDialog::onEnterKeyPressed); + + mControllerButtons.a = "#{sOk}"; + mControllerButtons.b = "#{sCancel}"; } void CountDialog::openCountDialog(const std::string& item, const std::string& message, const int maxCount) @@ -86,4 +89,18 @@ namespace MWGui { mItemEdit->setValue(_position + 1); } + + bool CountDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) + { + if (arg.button == SDL_CONTROLLER_BUTTON_A) + onOkButtonClicked(mOkButton); + else if (arg.button == SDL_CONTROLLER_BUTTON_B) + onCancelButtonClicked(mCancelButton); + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); + + return true; + } } diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp index 95d4a9a8d4..695de09215 100644 --- a/apps/openmw/mwgui/countdialog.hpp +++ b/apps/openmw/mwgui/countdialog.hpp @@ -38,6 +38,7 @@ namespace MWGui void onEditValueChanged(int value); void onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position); void onEnterKeyPressed(MyGUI::EditBox* _sender); + bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; }; }