From 32a787396befbe86bea06275a090a9791304384c Mon Sep 17 00:00:00 2001 From: ZeroInternalReflection <89038572+ZeroInternalReflection@users.noreply.github.com> Date: Mon, 12 Sep 2022 13:36:14 -0400 Subject: [PATCH] Allow both mouse movement and click-and-drag without local keybinds (#60946) --- data/raw/keybindings.json | 2 +- src/action.cpp | 2 ++ src/action.h | 2 ++ src/game.cpp | 1 + src/handle_action.cpp | 5 +++++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index fb74c8a55f97a..7aadf0ab67a5a 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -1333,7 +1333,7 @@ "type": "keybinding", "id": "MOUSE_MOVE", "name": "Mouse move", - "bindings": [ { "input_method": "mouse", "key": "MOUSE_MOVE" }, { "input_method": "mouse", "key": "MOUSE_LEFT_PRESSED" } ] + "bindings": [ { "input_method": "mouse", "key": "MOUSE_MOVE" } ] }, { "type": "keybinding", diff --git a/src/action.cpp b/src/action.cpp index bfd0450b3af64..a6d9cd4d8f01c 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -381,6 +381,8 @@ std::string action_ident( action_id act ) return "SELECT"; case ACTION_SEC_SELECT: return "SEC_SELECT"; + case ACTION_CLICK_AND_DRAG: + return "CLICK_AND_DRAG"; case ACTION_AUTOATTACK: return "autoattack"; case ACTION_MAIN_MENU: diff --git a/src/action.h b/src/action.h index eacd276bb1518..77185dc5bfc62 100644 --- a/src/action.h +++ b/src/action.h @@ -31,6 +31,8 @@ enum action_id : int { ACTION_SELECT, /** Click on a point with secondary mouse button (usually right button) */ ACTION_SEC_SELECT, + /** action on left mouse button-down, for clicking and dragging */ + ACTION_CLICK_AND_DRAG, /**@}*/ // Character movement actions diff --git a/src/game.cpp b/src/game.cpp index d45b08c54592b..aad34f9db031c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2476,6 +2476,7 @@ input_context get_default_mode_input_context() ctxt.register_action( "COORDINATE" ); ctxt.register_action( "MOUSE_MOVE" ); ctxt.register_action( "SELECT" ); + ctxt.register_action( "CLICK_AND_DRAG" ); ctxt.register_action( "SEC_SELECT" ); return ctxt; } diff --git a/src/handle_action.cpp b/src/handle_action.cpp index c5a527033e970..ec6bb513b3844 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -2884,6 +2884,11 @@ bool game::handle_action() user_action_counter += 1; } + if( act == ACTION_CLICK_AND_DRAG ) { + // Need to return false to avoid disrupting actions like character mouse movement that require two clicks + return false; + } + if( act == ACTION_SELECT || act == ACTION_SEC_SELECT ) { // Mouse button click if( veh_ctrl ) {