From 1e28f63bcf7b465cc940af18a08855d377370ac3 Mon Sep 17 00:00:00 2001 From: Nibodhika Date: Tue, 3 Apr 2018 22:29:07 +0000 Subject: Allows to map an action to all devices. This is accomplished by setting a special value (-1) to the device variable in the InputEvent that's being used to compare with the one received from the OS. This special value is invalid for a regular input, so it should be safe. Implements #17942 --- core/input_map.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/input_map.cpp') diff --git a/core/input_map.cpp b/core/input_map.cpp index bd03d6119..ea724d259 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -35,6 +35,8 @@ InputMap *InputMap::singleton = NULL; +int InputMap::ALL_DEVICES = -1; + void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action); @@ -103,10 +105,10 @@ List >::Element *InputMap::_find_event(List > &p //if (e.type != Ref::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here? // continue; - if (e->get_device() != p_event->get_device()) - continue; - if (e->action_match(p_event)) - return E; + int device = e->get_device(); + if (device == ALL_DEVICES || device == p_event->get_device()) + if (e->action_match(p_event)) + return E; } return NULL; -- cgit v1.2.3-70-g09d2