From bf16f89a302239ea1abc4dd767eda01f61cb9feb Mon Sep 17 00:00:00 2001 From: isaacremnant Date: Mon, 10 Sep 2018 15:15:06 -0400 Subject: Fix is_action_pressed for InputEventAction. --- core/input_map.cpp | 4 ++++ core/os/input_event.cpp | 16 ++++++++++++++++ core/os/input_event.h | 2 ++ 3 files changed, 22 insertions(+) (limited to 'core') diff --git a/core/input_map.cpp b/core/input_map.cpp index ffc8a39da5..23dc0e6a79 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -199,6 +199,10 @@ bool InputMap::event_get_action_status(const Ref &p_event, const Str Ref input_event_action = p_event; if (input_event_action.is_valid()) { + if (p_pressed != NULL) + *p_pressed = input_event_action->is_pressed(); + if (p_strength != NULL) + *p_strength = (*p_pressed) ? 1.0f : 0.0f; return input_event_action->get_action() == p_action; } diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 12c6ef7d3b..dd3b85c597 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -962,6 +962,22 @@ bool InputEventAction::is_action(const StringName &p_action) const { return action == p_action; } +bool InputEventAction::action_match(const Ref &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { + + Ref act = p_event; + if (act.is_null()) + return false; + + bool match = action == act->action; + if (match) { + if (p_pressed != NULL) + *p_pressed = act->pressed; + if (p_strength != NULL) + *p_strength = (*p_pressed) ? 1.0f : 0.0f; + } + return match; +} + String InputEventAction::as_text() const { return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false"); diff --git a/core/os/input_event.h b/core/os/input_event.h index 8732c7e377..7f3da380d4 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -480,6 +480,8 @@ public: virtual bool is_action(const StringName &p_action) const; + virtual bool action_match(const Ref &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; + virtual bool shortcut_match(const Ref &p_event) const; virtual bool is_action_type() const { return true; } virtual String as_text() const; -- cgit v1.2.3