extends Control

onready var game_tab = find_node("game")
onready var controls_tab = find_node("controls")
onready var graphics_tab = find_node("graphics")
onready var system_tab = find_node("system")


func _ready():
	get_node("menu/back").connect("pressed",self,"_on_back_pressed")
	system_tab.connect("locale_changed", self, "on_locale_changed")


func _draw():
	game_tab.grab_focus()


func _on_back_pressed():
	queue_free()
	if get_parent().has_node("ingame_menu"):
		get_parent().get_node("ingame_menu").show()
		get_tree().get_root().get_node("main_menu").hide()
	elif get_tree().get_root().has_node("main_menu"):
		get_tree().get_root().get_node("main_menu").show()


func on_locale_changed():
	game_tab.set_name(tr("GAME"))
	controls_tab.set_name(tr("CONTROLS"))
	graphics_tab.set_name(tr("GRAPHICS"))
	system_tab.set_name(tr("SYSTEM"))


func _on_save_pressed():
	_on_apply_pressed()
	_on_back_pressed()


func _on_apply_pressed():
	game_tab.apply()
	graphics_tab.apply()
	controls_tab.apply()
	system_tab.apply()

	config.save()
	config_apply.apply_settings()