diff options
author | Luc-Frédéric Langis <lucf.langis@gmail.com> | 2023-02-09 11:25:56 -0500 |
---|---|---|
committer | levrault <lucf.langis@gmail.com> | 2023-06-05 10:20:46 -0400 |
commit | 166ca77f201c86e22d7a6c737729976d2affdbd5 (patch) | |
tree | 38da9b31a09bd23bff69cc53c2cc67cacea7f314 /core/input | |
parent | 27253f3eb2c78a9ad5114c92eae2036b10e1d7e0 (diff) | |
download | redot-engine-166ca77f201c86e22d7a6c737729976d2affdbd5.tar.gz |
feat(gamepad): improve gamepad behavior with slider and popup_menu
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/input_event.cpp | 9 | ||||
-rw-r--r-- | core/input/input_event.h | 2 | ||||
-rw-r--r-- | core/input/input_map.cpp | 4 |
3 files changed, 15 insertions, 0 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 46f07fe041..d91a7bf5a5 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -1096,6 +1096,15 @@ String InputEventJoypadMotion::to_string() { return vformat("InputEventJoypadMotion: axis=%d, axis_value=%.2f", axis, axis_value); } +Ref<InputEventJoypadMotion> InputEventJoypadMotion::create_reference(JoyAxis p_axis, float p_value) { + Ref<InputEventJoypadMotion> ie; + ie.instantiate(); + ie->set_axis(p_axis); + ie->set_axis_value(p_value); + + return ie; +} + void InputEventJoypadMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis); ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis); diff --git a/core/input/input_event.h b/core/input/input_event.h index 4be42d0bd2..ecf2100141 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -321,6 +321,8 @@ public: virtual String as_text() const override; virtual String to_string() override; + static Ref<InputEventJoypadMotion> create_reference(JoyAxis p_axis, float p_value); + InputEventJoypadMotion() {} }; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 910778324c..ddfde0e7cd 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -399,21 +399,25 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::LEFT)); inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_LEFT)); + inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_X, -1.0)); default_builtin_cache.insert("ui_left", inputs); inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::RIGHT)); inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_RIGHT)); + inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_X, 1.0)); default_builtin_cache.insert("ui_right", inputs); inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::UP)); inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_UP)); + inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_Y, -1.0)); default_builtin_cache.insert("ui_up", inputs); inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::DOWN)); inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_DOWN)); + inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_Y, 1.0)); default_builtin_cache.insert("ui_down", inputs); inputs = List<Ref<InputEvent>>(); |