extends Control

onready var current_menu = $CenterContainer/MainContainer
onready var select_class_container = $CenterContainer/SelectClassContainer/HBoxContainer/GridContainer
onready var start_button = $CenterContainer/SelectClassContainer/HBoxContainer/VBoxContainer/StartButton
onready var description_label = $CenterContainer/SelectClassContainer/DescriptionLabel

signal new_game(extras)

var current_select_class = null
var infinite_mode = false

func _ready():
	for i in select_class_container.get_children():
		i.connect("selected", self, "select_class_button_pressed")

func select_class_button_pressed(index):
	var selected = select_class_container.get_child(index)
	for i in select_class_container.get_children():
		if selected != i:
			i.pressed = false
	current_select_class = selected.player_class
	if current_select_class is PlayerClass:
		description_label.text = current_select_class.description
	start_button.disabled = (current_select_class == null)
	
	#Global.current_select_class = current_select_class

func set_menu(node_path):
	$CenterContainer/SelectClassContainer.hide()
	$CenterContainer/MainContainer.hide()
	current_menu = node_path
	current_menu.show()

func _on_NewGameButton_pressed():
	set_menu($CenterContainer/SelectClassContainer)

func _on_ExitGameButton_pressed():
	get_tree().quit()

func _on_BackButton_pressed():
	set_menu($CenterContainer/MainContainer)

func _on_StartButton_pressed():
	emit_signal("new_game", {"player_class": current_select_class, "infinite_mode": infinite_mode})

func _on_ModeButton_toggled(button_pressed):
	infinite_mode = button_pressed
	description_label.text = "Infinite Mode: " + str(infinite_mode)
