summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input/input.cpp2
-rw-r--r--core/input/input_event.cpp12
-rw-r--r--core/input/input_event.h4
-rw-r--r--core/input/input_map.cpp7
4 files changed, 24 insertions, 1 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 4642ab5f90..aa4b47934e 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -1252,7 +1252,7 @@ void Input::_update_action_cache(const StringName &p_action_name, ActionState &r
r_action_state.cache.strength = 0.0;
r_action_state.cache.raw_strength = 0.0;
- int max_event = InputMap::get_singleton()->action_get_events(p_action_name)->size();
+ int max_event = InputMap::get_singleton()->action_get_events(p_action_name)->size() + 1; // +1 comes from InputEventAction.
for (const KeyValue<int, ActionState::DeviceState> &kv : r_action_state.device_states) {
const ActionState::DeviceState &device_state = kv.value;
for (int i = 0; i < max_event; i++) {
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index bf1de8d3b2..de3efa7a3a 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -1585,6 +1585,14 @@ float InputEventAction::get_strength() const {
return strength;
}
+void InputEventAction::set_event_index(int p_index) {
+ event_index = p_index;
+}
+
+int InputEventAction::get_event_index() const {
+ return event_index;
+}
+
bool InputEventAction::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
if (p_event.is_null()) {
return false;
@@ -1649,9 +1657,13 @@ void InputEventAction::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
+ ClassDB::bind_method(D_METHOD("set_event_index", "index"), &InputEventAction::set_event_index);
+ ClassDB::bind_method(D_METHOD("get_event_index"), &InputEventAction::get_event_index);
+
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "event_index", PROPERTY_HINT_RANGE, "-1,31,1"), "set_event_index", "get_event_index"); // The max value equals to Input::MAX_EVENT - 1.
}
///////////////////////////////////
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 21b61f3bc2..19176f748e 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -453,6 +453,7 @@ class InputEventAction : public InputEvent {
StringName action;
float strength = 1.0f;
+ int event_index = -1;
protected:
static void _bind_methods();
@@ -466,6 +467,9 @@ public:
void set_strength(float p_strength);
float get_strength() const;
+ void set_event_index(int p_index);
+ int get_event_index() const;
+
virtual bool is_action(const StringName &p_action) const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 7fd1806b31..178d02b987 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -274,6 +274,13 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
if (r_raw_strength != nullptr) {
*r_raw_strength = strength;
}
+ if (r_event_index) {
+ if (input_event_action->get_event_index() >= 0) {
+ *r_event_index = input_event_action->get_event_index();
+ } else {
+ *r_event_index = E->value.inputs.size();
+ }
+ }
return input_event_action->get_action() == p_action;
}