Skip to content

Commit

Permalink
Support for emulating mouse clicks when using gamepad (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 11, 2025
1 parent 56f099c commit 393c399
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/xrEngine/key_binding_registrator_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ SCRIPT_EXPORT(KeyBindings, (),

value("kUI_MOVE_SECONDARY", int(kUI_MOVE_SECONDARY)),

value("kUI_CLICK_1", int(kUI_CLICK_1)),
value("kUI_CLICK_2", int(kUI_CLICK_2)),

value("kUI_ACCEPT", int(kUI_ACCEPT)),
value("kUI_BACK", int(kUI_BACK)),
value("kUI_ACTION_1", int(kUI_ACTION_1)),
Expand Down
6 changes: 6 additions & 0 deletions src/xrEngine/xr_level_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ game_action actions[] =

{ "ui_move_secondary", kUI_MOVE_SECONDARY, _both, EKeyContext::UI },

{ "ui_click_1", kUI_CLICK_1, _both, EKeyContext::UI },
{ "ui_click_2", kUI_CLICK_2, _both, EKeyContext::UI },

{ "ui_accept", kUI_ACCEPT, _both, EKeyContext::UI },
{ "ui_back", kUI_BACK, _both, EKeyContext::UI },
{ "ui_action_1", kUI_ACTION_1, _both, EKeyContext::UI },
Expand Down Expand Up @@ -998,6 +1001,9 @@ class CCC_DefControls : public CCC_UnBindAll

{ kUI_MOVE_SECONDARY, { SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_AXIS_LEFT } },

{ kUI_CLICK_1, { SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_AXIS_TRIGGER_RIGHT } },
{ kUI_CLICK_2, { SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_AXIS_TRIGGER_LEFT } },

{ kUI_ACCEPT, { SDL_SCANCODE_RETURN, SDL_SCANCODE_F, XR_CONTROLLER_BUTTON_A } },
{ kUI_BACK, { SDL_SCANCODE_ESCAPE, SDL_SCANCODE_G, XR_CONTROLLER_BUTTON_B } },
{ kUI_ACTION_1, { SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_Y, XR_CONTROLLER_BUTTON_X } },
Expand Down
3 changes: 3 additions & 0 deletions src/xrEngine/xr_level_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ enum EGameActions : u32

kUI_MOVE_SECONDARY,

kUI_CLICK_1,
kUI_CLICK_2,

kUI_ACCEPT,
kUI_BACK,
kUI_ACTION_1,
Expand Down
33 changes: 33 additions & 0 deletions src/xrGame/UIDialogHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ bool CDialogHolder::IR_UIOnKeyboardPress(int dik)
return false;
if (!TIR->IR_process())
return false;

// mouse click
if (dik == MOUSE_1 || dik == MOUSE_2 || dik == MOUSE_3)
{
Expand Down Expand Up @@ -510,6 +511,22 @@ bool CDialogHolder::IR_UIOnControllerPress(int dik, float x, float y)
if (TIR->OnControllerAction(dik, x, y, WINDOW_KEY_PRESSED))
return true;

// simulate mouse click
if (TIR->NeedCursor())
{
int action = -1;
if (IsBinded(kUI_CLICK_1, dik, EKeyContext::UI))
action = WINDOW_LBUTTON_DOWN;
else if (IsBinded(kUI_CLICK_2, dik, EKeyContext::UI))
action = WINDOW_RBUTTON_DOWN;
if (action != -1)
{
Fvector2 cp = GetUICursor().GetCursorPosition();
if (TIR->OnMouseAction(cp.x, cp.y, (EUIMessages)action))
return true;
}
}

if (!TIR->StopAnyMove() && g_pGameLevel)
{
IGameObject* O = Level().CurrentEntity();
Expand Down Expand Up @@ -540,6 +557,22 @@ bool CDialogHolder::IR_UIOnControllerRelease(int dik, float x, float y)
if (TIR->OnControllerAction(dik, x, y, WINDOW_KEY_RELEASED))
return true;

// simulate mouse click
if (TIR->NeedCursor())
{
int action = -1;
if (IsBinded(kUI_CLICK_1, dik, EKeyContext::UI))
action = WINDOW_LBUTTON_UP;
else if (IsBinded(kUI_CLICK_2, dik, EKeyContext::UI))
action = WINDOW_RBUTTON_UP;
if (action != -1)
{
Fvector2 cp = GetUICursor().GetCursorPosition();
if (TIR->OnMouseAction(cp.x, cp.y, (EUIMessages)action))
return true;
}
}

if (!TIR->StopAnyMove() && g_pGameLevel)
{
IGameObject* O = Level().CurrentEntity();
Expand Down

0 comments on commit 393c399

Please sign in to comment.