summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNibodhika <vitochiarella@gmail.com>2018-04-03 22:29:07 +0000
committerNibodhika <vitochiarella@gmail.com>2018-04-07 20:08:09 +0000
commit1e28f63bcf7b465cc940af18a08855d377370ac3 (patch)
tree64f5c3ae1d3bf01071c9f51e07f5e26c39384ac2 /core
parentbcf5b748b52271774c0362717cab242527baf99d (diff)
downloadredot-engine-1e28f63bcf7b465cc940af18a08855d377370ac3.tar.gz
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
Diffstat (limited to 'core')
-rw-r--r--core/input_map.cpp10
-rw-r--r--core/input_map.h5
2 files changed, 11 insertions, 4 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp
index bd03d61196..ea724d2595 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<Ref<InputEvent> >::Element *InputMap::_find_event(List<Ref<InputEvent> > &p
//if (e.type != Ref<InputEvent>::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;
diff --git a/core/input_map.h b/core/input_map.h
index 84d90f6f2a..9f3c13c2cf 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -39,6 +39,11 @@ class InputMap : public Object {
GDCLASS(InputMap, Object);
public:
+ /**
+ * A special value used to signify that a given Action can be triggered by any device
+ */
+ static int ALL_DEVICES;
+
struct Action {
int id;
List<Ref<InputEvent> > inputs;