extends CanvasLayer

var time_options: Array = [30, 60, 90, 120, 150]

var player_count: int = 1

func _ready():
	%InstBR.visible = false
	%InstEN.visible = false
	%MainOptions.visible = true
	%TimeOptions.visible = false
	%ButtonSinglePlayer.grab_focus()
	
	%ButtonChangeTime.text = tr("STR_TEMPO") + " : " + str(time_options[SceneManager.time_option_index]) + " " + tr("STR_SEC")
	
	AudioPlayer.play_main_menu_music()

func _on_button_quit_pressed():
	get_tree().quit()


func _on_button_single_player_pressed():
	player_count = 1
	%MainOptions.visible = false
	%TimeOptions.visible = true
	%ButtonStartPlay.grab_focus()
	if (TranslationServer.get_locale() == "br"):
		%InstBR.visible = true
	else:
		%InstEN.visible = true


func _on_button_2_players_pressed():
	player_count = 2
	%MainOptions.visible = false
	%TimeOptions.visible = true
	%ButtonStartPlay.grab_focus()
	if (TranslationServer.get_locale() == "br"):
		%InstBR.visible = true
	else:
		%InstEN.visible = true


func _on_button_back_pressed():
	%MainOptions.visible = true
	%ButtonSinglePlayer.grab_focus()
	%InstBR.visible = false
	%InstEN.visible = false


func play():
	SceneManager.set_player_count(player_count)
	SceneManager.go_to_play()

func _on_button_change_language_pressed():
	if (TranslationServer.get_locale() == "br"):
		TranslationServer.set_locale("en")
	else:
		TranslationServer.set_locale("br")
		
	%ButtonChangeTime.text = tr("STR_TEMPO") + " : " + str(time_options[SceneManager.time_option_index]) + " " + tr("STR_SEC")


func _on_button_change_time_pressed():
	SceneManager.time_option_index += 1
	if (SceneManager.time_option_index >= time_options.size()):
		SceneManager.time_option_index = 0

	SceneManager.play_time = time_options[SceneManager.time_option_index]

	%ButtonChangeTime.text = tr("STR_TEMPO") + " : " + str(time_options[SceneManager.time_option_index]) + " " + tr("STR_SEC")


func _on_button_time_back_pressed():
	%TimeOptions.visible = false
	%MainOptions.visible = true
	%ButtonSinglePlayer.grab_focus()
	%InstBR.visible = false
	%InstEN.visible = false


func _on_button_start_play_pressed():
	play()
