Skip to content

Commit

Permalink
Read joypad deadzone from ProjectSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
Pennycook committed Apr 20, 2024
1 parent c494069 commit c416437
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion addons/input_prompts/input_prompt_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ var preferred_icons := InputPrompt.Icons.AUTOMATIC:
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)


## Return the [KeyboardTextures] used by [KeyPrompt] nodes.
func get_keyboard_textures() -> KeyboardTextures:
return preload("res://addons/input_prompts/key_prompt/keys.tres")
Expand Down Expand Up @@ -98,8 +103,10 @@ func _input(event: InputEvent):
icons = InputPrompt.Icons.KEYBOARD
emit_signal("icons_changed")
if event is InputEventJoypadButton or event is InputEventJoypadMotion:
if event is InputEventJoypadMotion and event.axis_value < 0.05:
# 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
13 changes: 13 additions & 0 deletions addons/input_prompts/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ 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)
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

0 comments on commit c416437

Please sign in to comment.