Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add some deadzone for joypad motion detection #3

Merged
merged 5 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions addons/input_prompts/input_prompt_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ var preferred_icons := InputPrompt.Icons.AUTOMATIC:
icons = value
emit_signal("icons_changed")

## The deadzone value used to detect joypad activity. The default value is determined by the
## "addons/input_prompts/joypad_detection_deadzone" setting in [ProjectSettings].
var joypad_detection_deadzone := ProjectSettings.get_setting(
"addons/input_prompts/joypad_detection_deadzone", 0.5
)


## Force all [InputPrompt] nodes to refresh their icons and events.
## Must be called if the [InputMap] is changed.
Expand Down Expand Up @@ -106,6 +112,10 @@ func _input(event: InputEvent):
icons = InputPrompt.Icons.KEYBOARD
emit_signal("icons_changed")
if event is InputEventJoypadButton or event is InputEventJoypadMotion:
# Do not detect Joypad unless value exceeds deadzone
if event is InputEventJoypadMotion and absf(event.axis_value) < joypad_detection_deadzone:
return

var device = event.device
var joy_name = Input.get_joy_name(device)
if joy_name.find("Xbox"):
Expand Down
14 changes: 14 additions & 0 deletions addons/input_prompts/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ func _enter_tree():
add_autoload_singleton("PromptManager", "res://addons/input_prompts/input_prompt_manager.gd")
add_inspector_plugin(inspector_plugin)

if Engine.is_editor_hint():
var deadzone_setting := "addons/input_prompts/joypad_detection_deadzone"
if not ProjectSettings.has_setting(deadzone_setting):
ProjectSettings.set_setting(deadzone_setting, 0.5)
ProjectSettings.set_initial_value(deadzone_setting, 0.5)
ProjectSettings.set_as_basic(deadzone_setting, true)
var property_info = {
"name": deadzone_setting,
"type": TYPE_FLOAT,
"hint": PROPERTY_HINT_RANGE,
"hint_string": "0,1"
}
ProjectSettings.save()


func _exit_tree():
remove_inspector_plugin(inspector_plugin)
Expand Down