extends Control

var original_node : Control
@onready var language_option_button : OptionButton = $VBoxContainer/VBoxContainer/LanguageOption
@onready var display_option_button : OptionButton = $VBoxContainer/VBoxContainer/DisplayOption
@onready var screen_flash_check_button: CheckButton = $VBoxContainer/VBoxContainer/ScreenFlashCheckButton
@onready var skip_cutscenes_check_button: CheckButton = $VBoxContainer/VBoxContainer/SkipCutscenesCheckButton

func _ready():
	add_languages()
	add_display_options()
	screen_flash_check_button.button_pressed = Globals.screen_flash_effects
	skip_cutscenes_check_button.button_pressed = Globals.skip_cutscenes

func add_languages():
	var tmp = 0
	for lang in TranslationServer.get_loaded_locales():
		language_option_button.add_item(lang)
		if lang == Globals.lang:
				language_option_button.selected = tmp
		tmp+=1

func add_display_options():
	for option in ["Windowed", "Fullscreen", "Exclusive Fullscreen"]:
		display_option_button.add_item(str(option));

func _on_display_mode_selected(index: int):
	if (index == 0):
		DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED);
	elif (index == 1):
		DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN);
	elif (index == 2):
		DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_EXCLUSIVE_FULLSCREEN);

func _on_language_option_item_selected(index: int) -> void:
	var lang = language_option_button.get_item_text(index)
	Globals.lang = lang
	TranslationServer.set_locale(lang)

func update():
	pass

func _on_return_button_pressed() -> void:
	GUI.return_from_submenu(self)


func _on_screen_flash_check_button_toggled(toggled_on: bool) -> void:
	Globals.screen_flash_effects = toggled_on


func _on_skip_cutscenes_check_button_toggled(toggled_on: bool) -> void:
	Globals.skip_cutscenes = toggled_on
