From 21565ec7568b830cb7d39ef0e13cde68fa628c1f Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 21 Mar 2021 19:29:53 +0000 Subject: [PATCH] Controller: Move stick click handlers out of !game_menu Fixes clicks on dialog items --- SourceX/controls/game_controls.cpp | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/SourceX/controls/game_controls.cpp b/SourceX/controls/game_controls.cpp index 11e68a035..654988b09 100644 --- a/SourceX/controls/game_controls.cpp +++ b/SourceX/controls/game_controls.cpp @@ -100,6 +100,27 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam if (HandleStartAndSelect(ctrl_event, action)) return true; + // Stick clicks simulate the mouse both in menus and in-game. + switch (ctrl_event.button) { + case ControllerButton_BUTTON_LEFTSTICK: + if (select_modifier_active) { + if (!IsAutomapActive()) + *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrl_event.up }; + return true; + } + break; + case ControllerButton_BUTTON_RIGHTSTICK: + if (!IsAutomapActive()) { + if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) + *action = GameActionSendMouseClick { GameActionSendMouseClick::RIGHT, ctrl_event.up }; + else + *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrl_event.up }; + } + return true; + default: + break; + } + if (!in_game_menu) { switch (ctrl_event.button) { case ControllerButton_BUTTON_LEFTSHOULDER: @@ -132,13 +153,6 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam *action = GameAction(GameActionType_TOGGLE_INVENTORY); } return true; - case ControllerButton_BUTTON_LEFTSTICK: - if (select_modifier_active) { - if (!IsAutomapActive()) - *action = GameActionSendMouseClick{ GameActionSendMouseClick::LEFT, ctrl_event.up }; - return true; - } - break; case ControllerButton_IGNORE: case ControllerButton_BUTTON_START: case ControllerButton_BUTTON_BACK: @@ -289,14 +303,6 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam case ControllerButton_BUTTON_DPAD_RIGHT: // The rest of D-Pad actions are handled in charMovement() on every game_logic() call. return true; - case ControllerButton_BUTTON_RIGHTSTICK: - if (!IsAutomapActive()) { - if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendMouseClick{ GameActionSendMouseClick::RIGHT, ctrl_event.up }; - else - *action = GameActionSendMouseClick{ GameActionSendMouseClick::LEFT, ctrl_event.up }; - } - return true; default: break; }