diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-06-02 21:11:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-02 21:11:10 +0200 |
commit | 688933ea18fa1da136927da9a3615945379f0fd1 (patch) | |
tree | 6ca764f3fbb663294cf5c5adb15b29741511ec46 | |
parent | 512f8c7e62a67dcb0540b63bbae2b523283d004d (diff) | |
parent | f24783283201a7508720c5bbc2548ef0563c8b99 (diff) |
Merge pull request #29383 from groud/strength_for_inputeventaction
Add configurable strength value to InputEventAction
-rw-r--r-- | core/input_map.cpp | 2 | ||||
-rw-r--r-- | core/os/input_event.cpp | 13 | ||||
-rw-r--r-- | core/os/input_event.h | 4 | ||||
-rw-r--r-- | doc/classes/InputEventAction.xml | 3 |
4 files changed, 21 insertions, 1 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp index 15f68f9c2a..012c6a7c4f 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -202,7 +202,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str if (p_pressed != NULL) *p_pressed = input_event_action->is_pressed(); if (p_strength != NULL) - *p_strength = (*p_pressed) ? 1.0f : 0.0f; + *p_strength = (*p_pressed) ? input_event_action->get_strength() : 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 a072017353..9c5066da3d 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -1010,6 +1010,14 @@ bool InputEventAction::is_pressed() const { return pressed; } +void InputEventAction::set_strength(float p_strength) { + strength = CLAMP(p_strength, 0.0f, 1.0f); +} + +float InputEventAction::get_strength() const { + return strength; +} + bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { if (p_event.is_null()) return false; @@ -1051,14 +1059,19 @@ void InputEventAction::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed); //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed); + 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("is_action", "name"), &InputEventAction::is_action); ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength"); } InputEventAction::InputEventAction() { pressed = false; + strength = 1.0f; } ///////////////////////////// diff --git a/core/os/input_event.h b/core/os/input_event.h index ba01516519..7a9a1f71c3 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -475,6 +475,7 @@ class InputEventAction : public InputEvent { StringName action; bool pressed; + float strength; protected: static void _bind_methods(); @@ -486,6 +487,9 @@ public: void set_pressed(bool p_pressed); virtual bool is_pressed() const; + void set_strength(float p_strength); + float get_strength() const; + virtual bool is_action(const StringName &p_action) const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; diff --git a/doc/classes/InputEventAction.xml b/doc/classes/InputEventAction.xml index 25e9073ec7..9df7bbca74 100644 --- a/doc/classes/InputEventAction.xml +++ b/doc/classes/InputEventAction.xml @@ -18,6 +18,9 @@ <member name="pressed" type="bool" setter="set_pressed" getter="is_pressed"> If [code]true[/code], the action's state is pressed. If [code]false[/code], the action's state is released. </member> + <member name="strength" type="float" setter="set_strength" getter="get_strength"> + The action's strength between 0 and 1. This value is consired as equal to 0 if pressed is [code]false[/code]. The event strength allows faking analog joypad motion events, by precising how strongly is the joypad axis bent or pressed. + </member> </members> <constants> </constants> |