Files
Ransom-s-wake/game/presentation/settings/controls_settings_screen.gd

68 lines
2.2 KiB
GDScript

class_name ControlsSettingsScreen
extends Control
signal rebind_requested(action_id: StringName)
signal restore_defaults_requested
signal conflict_resolution_requested(swap_bindings: bool)
signal back_requested
const InputBindingSnapshot = preload(
"res://game/application/input/input_binding_snapshot.gd"
)
const RebindResult = preload("res://game/application/input/rebind_result.gd")
@onready var _rows: VBoxContainer = %Rows
@onready var _status_label: Label = %StatusLabel
@onready var _conflict_panel: PanelContainer = %ConflictPanel
@onready var _conflict_label: Label = %ConflictLabel
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
%RestoreButton.pressed.connect(func() -> void: restore_defaults_requested.emit())
%BackButton.pressed.connect(func() -> void: back_requested.emit())
%SwapButton.pressed.connect(func() -> void: conflict_resolution_requested.emit(true))
%CancelConflictButton.pressed.connect(
func() -> void: conflict_resolution_requested.emit(false)
)
_conflict_panel.visible = false
func present_bindings(bindings: Array[InputBindingSnapshot]) -> void:
for child: Node in _rows.get_children():
child.queue_free()
for binding: InputBindingSnapshot in bindings:
var row := HBoxContainer.new()
row.custom_minimum_size.y = 42.0
var label := Label.new()
label.text = binding.label
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
var button := Button.new()
button.custom_minimum_size.x = 180.0
button.text = binding.binding_text
button.pressed.connect(_on_binding_button_pressed.bind(binding.action_id))
row.add_child(label)
row.add_child(button)
_rows.add_child(row)
func _on_binding_button_pressed(action_id: StringName) -> void:
rebind_requested.emit(action_id)
func present_rebind_result(result: RebindResult) -> void:
_status_label.text = result.message
if result.conflicting_action_id.is_empty():
_conflict_panel.visible = false
return
_conflict_label.text = (
"La touche %s est déjà utilisée. Permuter les deux commandes ?"
% result.binding_text
)
_conflict_panel.visible = true
func show_waiting_for_key() -> void:
_status_label.text = "Appuyez sur une touche · Échap pour annuler"
_conflict_panel.visible = false