diff --git a/scripts/managers/settings_manager.gd b/scripts/managers/settings_manager.gd index 4806269..f4fd226 100644 --- a/scripts/managers/settings_manager.gd +++ b/scripts/managers/settings_manager.gd @@ -223,3 +223,11 @@ func get_control_text(action_name: String) -> String: var code = get_control_keycode(action_name) if code == -1: return "Unbound" 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 "" diff --git a/scripts/ui/settings_menu.gd b/scripts/ui/settings_menu.gd index 37bfb87..d9fa7e6 100644 --- a/scripts/ui/settings_menu.gd +++ b/scripts/ui/settings_menu.gd @@ -162,6 +162,30 @@ func _input(event): if listening_action != "" and event is InputEventKey and event.pressed: # Capture the key 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) # Feedback and Reset