Skip to content

Commit

Permalink
Support combo box interaction with gamepad (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 11, 2025
1 parent a0c02d0 commit f5bbb31
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/xrUICore/ComboBox/UIComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/xrUICore/ComboBox/UIComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f5bbb31

Please sign in to comment.