extends Control

@export var volume_slider : HSlider
@export var fullscreen_check : CheckBox
@export var vsync_check : CheckBox
@export var glow_check : CheckBox

func _ready():
	_update_settings()


func _update_settings():
	volume_slider.value = Settings.master_volume
	fullscreen_check.button_pressed = Settings.fullscreen
	vsync_check.button_pressed = Settings.vsync
	glow_check.button_pressed = Settings.glow
	
func _input(event: InputEvent) -> void:
	_update_settings()
	if (event.is_action_pressed("ui_cancel")):
		get_viewport().set_input_as_handled()
		visible = !visible
		get_tree().paused = visible
	elif (event.is_action_pressed("fullscreen")):
		get_viewport().set_input_as_handled()
		Settings.fullscreen = !Settings.fullscreen
		Settings.apply_fullscreen()

func _on_volume_changed(value: float):
	Settings.master_volume = value
	Settings.apply_volume()

func _on_fullscreen_toggled(enabled: bool):
	Settings.fullscreen = enabled
	Settings.apply_fullscreen()

func _on_max_fps_changed(value: float):
	Settings.max_fps = int(value)
	Settings.apply_max_fps()

func _on_vsync_toggled(enabled : bool):
	Settings.vsync = enabled
	Settings.apply_vsync()

func _on_exit_button_pressed() -> void:
	get_tree().quit()


func _on_continue_button_pressed() -> void:
	visible = false
	get_tree().paused = visible


func _on_glow_toggled(enabled: bool) -> void:
	Settings.glow = enabled
	Settings.apply_glow()
