extends Node

export (PackedScene) var title = load("res://scenes/UI/title/Title.tscn")
export (PackedScene) var setting = load("res://scenes/UI/settings/Settings.tscn")
export (PackedScene) var choose_scene = load("res://scenes/UI/choose_scenes/ChooseScene.tscn")

onready var current_scene = "title"
onready var stream_button = preload("res://assets/sounds/click-button.ogg")
onready var home = $MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/CenterContainer/TextureRect

func _ready():
	_translation()
	home.set_focus_mode(2)
	home.grab_focus()
	_apply_scene(title)
	_configure_sound()

func _configure_sound():
	stream_button.set_loop(false)
	$MarginContainer/HBoxContainer/UI_summary/ClickButton.stream = stream_button

## PRIVATE
func _translation():
	$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonPuzzle/Label.text = tr("MAIN_BUTTON_PUZZLES")
	$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonSetting/Label.text = tr("MAIN_BUTTON_SETTINGS")
	$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonQuit/Label.text = tr("MAIN_BUTTON_QUIT")
	$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ContainerVersion/LabelVersion.text = Setting.get_setting_version()

func _apply_scene(actual_scene):
	var node = get_node("MarginContainer/HBoxContainer/MarginContainer/")
	
	if node.get_child_count() != 0:
		node.get_child(0).queue_free()
	
	node.add_child(actual_scene.instance())

# Load scene for select game
func _on_ButtonPuzzle_pressed():
	_sound_button()
	_apply_scene(choose_scene)

# Load scene settings
func _on_ButtonSetting_pressed():
	_sound_button()
	_apply_scene(setting)

# Click to icon game
func _on_TextureRect_pressed():
	_sound_button()
	_apply_scene(title)

# Quit the game
func _on_ButtonQuit_pressed():
	_sound_button()
	get_tree().quit(0)

func _sound_button():
	$MarginContainer/HBoxContainer/UI_summary/ClickButton.play()
