Skip to content

Commit

Permalink
Gamepad navigation in CUIActorMenu (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 17, 2025
1 parent e4d9d8c commit f5a32f7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
36 changes: 36 additions & 0 deletions src/xrGame/ui/UIActorMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ void CUIActorMenu::Show(bool status)
m_message_static = nullptr;
}

void CUIActorMenu::ShowDialog(bool bDoHideIndicators)
{
CUIDialogWnd::ShowDialog(bDoHideIndicators);

CUIDragDropListEx* bag{};
switch (m_currMenuMode)
{
case mmInventory: bag = m_pLists[eInventoryBagList]; break;
case mmTrade: bag = m_pLists[eTradeActorBagList]; break;
case mmUpgrade: bag = m_pLists[eInventoryBagList]; break;
case mmDeadBodySearch: bag = m_pLists[eSearchLootActorBagList]; break;
}

if (bag && bag->ItemsCount() && pInput->IsCurrentInputTypeController())
{
UI().Focus().SetFocused(bag->GetItemIdx(0));
}
}

void CUIActorMenu::Draw()
{
CurrentGameUI()->UIMainIngameWnd->DrawZoneMap();
Expand Down Expand Up @@ -262,6 +281,23 @@ bool CUIActorMenu::StopAnyMove() // true = актёр не идёт при от
return true;
}

bool CUIActorMenu::NeedCenterCursor() const
{
CUIDragDropListEx* bag{};
switch (m_currMenuMode)
{
case mmInventory: bag = m_pLists[eInventoryBagList]; break;
case mmTrade: bag = m_pLists[eTradeActorBagList]; break;
case mmUpgrade: bag = m_pLists[eInventoryBagList]; break;
case mmDeadBodySearch: bag = m_pLists[eSearchLootActorBagList]; break;
}

if (bag)
return bag->ItemsCount() == 0;

return CUIDialogWnd::NeedCenterCursor();
}

void CUIActorMenu::CheckDistance()
{
CGameObject* pActorGO = smart_cast<CGameObject*>(m_pActorInvOwner);
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui/UIActorMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,12 @@ class CUIActorMenu final : public CUIDialogWnd, public CUIWndCallback
virtual ~CUIActorMenu();

virtual bool StopAnyMove();
bool NeedCenterCursor() const override;
virtual void SendMessage(CUIWindow* pWnd, s16 msg, void* pData = NULL);
virtual void Draw();
virtual void Update();
virtual void Show(bool status);
void ShowDialog(bool bDoHideIndicators) override;

virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action);
virtual bool OnMouseAction(float x, float y, EUIMessages mouse_action);
Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/ui/UIActorMenuInitialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ void CUIActorMenu::Construct()
DeInitTradeMode();
DeInitUpgradeMode();
DeInitDeadBodySearchMode();

// We have shortcuts both for keyboard and gamepad
UI().Focus().UnregisterFocusable(m_exit_button);
}

void CUIActorMenu::InitializeUniversal(CUIXml& uiXml)
Expand Down
9 changes: 5 additions & 4 deletions src/xrGame/ui/UIActorMenu_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ bool CUIActorMenu::OnMouseAction(float x, float y, EUIMessages mouse_action)
bool CUIActorMenu::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
InfoCurItem(NULL);

if (inherited::OnKeyboardAction(dik, keyboard_action))
return true;

if (IsBinded(kDROP, dik))
{
if (WINDOW_KEY_PRESSED == keyboard_action && CurrentIItem() && !CurrentIItem()->IsQuestItem() &&
Expand Down Expand Up @@ -425,7 +429,7 @@ bool CUIActorMenu::OnKeyboardAction(int dik, EUIMessages keyboard_action)
return true;
}

if (IsBinded(kQUIT, dik))
if (IsBinded(kQUIT, dik) || IsBinded(kUI_BACK, dik, EKeyContext::UI))
{
if (WINDOW_KEY_PRESSED == keyboard_action)
{
Expand All @@ -435,9 +439,6 @@ bool CUIActorMenu::OnKeyboardAction(int dik, EUIMessages keyboard_action)
return true;
}

if (inherited::OnKeyboardAction(dik, keyboard_action))
return true;

return false;
}

Expand Down
11 changes: 11 additions & 0 deletions src/xrGame/ui/UICellItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ bool CUICellItem::OnKeyboardAction(int dik, EUIMessages keyboard_action)
GetMessageTarget()->SendMessage(this, DRAG_DROP_ITEM_DB_CLICK, NULL);
return true;
}
if (CursorOverWindow())
{
const auto [x, y] = UI().GetUICursor().GetCursorPosition();
switch (GetBindedAction(dik, EKeyContext::UI))
{
case kUI_ACCEPT:
return OnMouseAction(x, y, WINDOW_LBUTTON_DB_CLICK);
case kUI_ACTION_1:
return OnMouseAction(x, y, WINDOW_RBUTTON_DOWN);
} // switch (GetBindedAction(dik, EKeyContext::UI))
}
}
return inherited::OnKeyboardAction(dik, keyboard_action);
}
Expand Down

0 comments on commit f5a32f7

Please sign in to comment.