feat: Introduce a settings manager and UI for configuring video, audio, and control keybinds.

This commit is contained in:
Yogi Wiguna
2026-03-26 17:42:24 +08:00
parent e6d58002a7
commit 078ae4c966
2 changed files with 32 additions and 0 deletions
+8
View File
@@ -223,3 +223,11 @@ func get_control_text(action_name: String) -> String:
var code = get_control_keycode(action_name) var code = get_control_keycode(action_name)
if code == -1: return "Unbound" if code == -1: return "Unbound"
return OS.get_keycode_string(code) return OS.get_keycode_string(code)
func is_key_used(keycode: int) -> String:
"""Check if a keycode is already assigned to any action."""
for action in settings.controls.keys():
if action == "use_controller": continue
if settings.controls[action] == keycode:
return action
return ""
+24
View File
@@ -162,6 +162,30 @@ func _input(event):
if listening_action != "" and event is InputEventKey and event.pressed: if listening_action != "" and event is InputEventKey and event.pressed:
# Capture the key # Capture the key
var keycode = event.keycode var keycode = event.keycode
# PREVENT DUPLICATES (User Request)
var existing_action = SettingsManager.is_key_used(keycode)
if existing_action != "" and existing_action != listening_action:
# Visual Feedback for Error
var error_btn = get_node_or_null("%" + listening_action.to_pascal_case() + "Btn")
if error_btn:
error_btn.text = "ALREADY USED!"
error_btn.modulate = Color(1.0, 0.3, 0.3) # Red error
# Play sound if available
var sfx = get_node_or_null("/root/SfxManager")
if sfx and sfx.has_method("play_rpc"):
sfx.rpc("play_rpc", "error") # Assumes an error sound exists
# Reset listening but keep text for briefly before reverting
listening_action = ""
await get_tree().create_timer(1.2).timeout
_update_all_key_labels()
get_viewport().set_input_as_handled()
return
# Proceed with remapping if not a duplicate
SettingsManager.set_control(listening_action, keycode) SettingsManager.set_control(listening_action, keycode)
# Feedback and Reset # Feedback and Reset