extends Control

@onready var InvertMouseY := $VBoxContainer/TabContainer/Control/InvertMouse/InvertMouse
@onready var CameraSensSlider := $VBoxContainer/TabContainer/Control/CameraSens/CameraSens



func _ready():
	var control_settings = ConfigHandler.load_control_settings()
	InvertMouseY.button_pressed = control_settings.invert_mouse_y
	CameraSensSlider.value = control_settings.camera_sensitivity * 100

func _input(event):
	if event.is_action_released("ui_cancel"):
		_on_exit_button_pressed()

func _on_invert_mouse_toggled(toggled_on):
	ConfigHandler.save_control_setting("invert_mouse_y", toggled_on)
	ConfigHandler.ControlSettingsChanged.emit()

func _on_camera_sens_drag_ended(value_changed):
	if value_changed:
		ConfigHandler.save_control_setting("camera_sensitivity", CameraSensSlider.value / 100)
		ConfigHandler.ControlSettingsChanged.emit()



func _on_exit_button_pressed():
	hide()
