From aa3cf2e07776b0c1dc2e107b89e4673155eec1d2 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 21 Aug 2024 13:34:33 -0500 Subject: [PATCH] Add Gamepad buttons to Axis Config. --- Source/Engine/Input/Input.cpp | 6 ++++-- Source/Engine/Input/VirtualInput.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 0faa26f39..7d267f21b 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -157,6 +157,8 @@ void InputSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* m config.Gamepad = JsonTools::GetEnum(v, "Gamepad", InputGamepadIndex::All); config.PositiveButton = JsonTools::GetEnum(v, "PositiveButton", KeyboardKeys::None); config.NegativeButton = JsonTools::GetEnum(v, "NegativeButton", KeyboardKeys::None); + config.GamepadPositiveButton = JsonTools::GetEnum(v, "GamepadPositiveButton", GamepadButton::None); + config.GamepadNegativeButton = JsonTools::GetEnum(v, "GamepadNegativeButton", GamepadButton::None); config.DeadZone = JsonTools::GetFloat(v, "DeadZone", 0.1f); config.Sensitivity = JsonTools::GetFloat(v, "Sensitivity", 0.4f); config.Gravity = JsonTools::GetFloat(v, "Gravity", 1.0f); @@ -873,8 +875,8 @@ void InputService::Update() const AxisData& data = Axes[name]; // Get key raw value - const bool isPositiveKey = Input::GetKey(config.PositiveButton); - const bool isNegativeKey = Input::GetKey(config.NegativeButton); + const bool isPositiveKey = Input::GetKey(config.PositiveButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadPositiveButton); + const bool isNegativeKey = Input::GetKey(config.NegativeButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadNegativeButton); float keyRawValue = 0; if (isPositiveKey && !isNegativeKey) { diff --git a/Source/Engine/Input/VirtualInput.h b/Source/Engine/Input/VirtualInput.h index 3028fc661..1adad2056 100644 --- a/Source/Engine/Input/VirtualInput.h +++ b/Source/Engine/Input/VirtualInput.h @@ -87,6 +87,18 @@ API_STRUCT() struct AxisConfig API_FIELD(Attributes="EditorOrder(40)") KeyboardKeys NegativeButton; + /// + /// The button to be pressed for movement in positive direction. Use to ignore it. + /// + API_FIELD(Attributes="EditorOrder(45)") + GamepadButton GamepadPositiveButton; + + /// + /// The button to be pressed for movement in negative direction. Use to ignore it. + /// + API_FIELD(Attributes="EditorOrder(46)") + GamepadButton GamepadNegativeButton; + /// /// Any positive or negative values that are less than this number will register as zero. Useful for gamepads to specify the deadzone. ///