From f5bbb31cffba93ff1eda4ff9bde675ed49d5553c Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Sun, 12 Jan 2025 01:13:05 +0300 Subject: [PATCH] Support combo box interaction with gamepad (#943) --- src/xrUICore/ComboBox/UIComboBox.cpp | 90 ++++++++++++++++++++++++++++ src/xrUICore/ComboBox/UIComboBox.h | 2 + 2 files changed, 92 insertions(+) diff --git a/src/xrUICore/ComboBox/UIComboBox.cpp b/src/xrUICore/ComboBox/UIComboBox.cpp index 35e633a1969..5742d135884 100644 --- a/src/xrUICore/ComboBox/UIComboBox.cpp +++ b/src/xrUICore/ComboBox/UIComboBox.cpp @@ -290,6 +290,8 @@ void CUIComboBox::OnFocusLost() CUIWindow::OnFocusLost(); if (m_bIsEnabled) m_frameLine.SetCurrentState(S_Enabled); + if (m_eState == LIST_EXPANDED && pInput->IsCurrentInputTypeController()) + ShowList(false); } void CUIComboBox::OnFocusReceive() @@ -326,6 +328,94 @@ bool CUIComboBox::OnMouseAction(float x, float y, EUIMessages mouse_action) return false; } +bool CUIComboBox::OnKeyboardAction(int dik, EUIMessages keyboard_action) +{ + if (CUIWindow::OnKeyboardAction(dik, keyboard_action)) + return true; + + if (CursorOverWindow() && keyboard_action == WINDOW_KEY_PRESSED) + { + switch (GetBindedAction(dik, EKeyContext::UI)) + { + case kUI_ACCEPT: + case kUI_BACK: + if (m_list_frame.IsShown()) + { + ShowList(false); + return true; + } + break; + case kUI_MOVE_LEFT: + { + if (!m_list_frame.IsShown()) + SetNextItemSelected(false, false); + return true; + } + case kUI_MOVE_RIGHT: + { + if (!m_list_frame.IsShown()) + SetNextItemSelected(true, false); + return true; + } + case kUI_MOVE_UP: + { + if (m_list_frame.IsShown()) + { + SetNextItemSelected(false, false); + if (CUIListBoxItem* itm = m_list_box.GetSelectedItem()) + UI().Focus().SetFocused(itm); + return true; + } + break; + } + case kUI_MOVE_DOWN: + { + if (m_list_frame.IsShown()) + { + SetNextItemSelected(true, false); + if (CUIListBoxItem* itm = m_list_box.GetSelectedItem()) + UI().Focus().SetFocused(itm); + return true; + } + break; + } + } // switch (action) + } + + return false; +} + +bool CUIComboBox::OnControllerAction(int axis, float x, float y, EUIMessages controller_action) +{ + if (CUIWindow::OnControllerAction(axis, x, y, controller_action)) + return true; + + if (CursorOverWindow()) + { + if (IsBinded(kUI_MOVE, axis, EKeyContext::UI)) + { + if (!fis_zero(x)) + { + if (!m_list_frame.IsShown()) + SetNextItemSelected(x > 0, false); + return true; + } + if (!fis_zero(y)) + { + if (m_list_frame.IsShown()) + { + SetNextItemSelected(y > 0, false); + if (CUIListBoxItem* itm = m_list_box.GetSelectedItem()) + UI().Focus().SetFocused(itm); + return true; + } + } + } + } + + return false; +} + void CUIComboBox::SendMessage(CUIWindow* pWnd, s16 msg, void* pData) { CUIWindow::SendMessage(pWnd, msg, pData); diff --git a/src/xrUICore/ComboBox/UIComboBox.h b/src/xrUICore/ComboBox/UIComboBox.h index 31dc9304790..191365585f4 100644 --- a/src/xrUICore/ComboBox/UIComboBox.h +++ b/src/xrUICore/ComboBox/UIComboBox.h @@ -53,6 +53,8 @@ class XRUICORE_API CUIComboBox final : public CUIWindow, public CUIOptionsItem, protected: virtual bool OnMouseAction(float x, float y, EUIMessages mouse_action); + bool OnKeyboardAction(int dik, EUIMessages keyboard_action) override; + bool OnControllerAction(int axis, float x, float y, EUIMessages controller_action) override; virtual void OnBtnClicked(); void ShowList(bool bShow); void OnListItemSelect();