extends VBoxContainer

signal changed
signal leave_stage

var has_stage:bool = false:
	set(stage):
		has_stage = stage
		if is_node_ready() and has_stage:
			y_switch.grab_focus()

var current_music_decay:float = 0

@onready var y_switch: CheckBox = %InvertY
@onready var input_sensitivity_slider: HSlider = %InputSensitivitySlider
@onready var stream_overlay_picker: OptionButton = %StreamOverlayPicker

func _ready() -> void:
	update_ui_from_state()

	y_switch.toggled.connect(func(value): State.inverty_y_axis = value)
	input_sensitivity_slider.value_changed.connect(func(value): State.input_sensitivity = value)
	stream_overlay_picker.item_selected.connect(func(value): State.stream_overlay = value)
	
	%SaveButton.pressed.connect(_on_exit_button_pressed)

func update_ui_from_state():
	y_switch.button_pressed = State.inverty_y_axis
	input_sensitivity_slider.value = State.input_sensitivity
	stream_overlay_picker.select(State.stream_overlay_position)
	
func _on_exit_button_pressed() -> void:
	leave_stage.emit()
	State.save_settings()
	State.leave_stage(self)
