extends Control

onready var exit_to_menu_button = $CenterContainer/VBoxContainer/ExitToMenuButton

var sure_left = 1

func _unhandled_input(event):
	if event is InputEventKey:
		if event.pressed and event.scancode == KEY_ESCAPE:
			show_or_hide()

func show_or_hide():
	visible = not visible
	if not visible:
		yield(get_tree().create_timer(0.1), "timeout")
	get_tree().paused = visible
	exit_to_menu_button.text = "Menu"
	sure_left = 1

func _on_ContinueButton_pressed():
	show_or_hide()

func _on_ExitToMenuButton_pressed():
	if sure_left == 0:
		exit_to_menu_button.text = "Quitting..."
	else:
		exit_to_menu_button.text = "You sure?"
	sure_left -= 1
	if sure_left < 0:
		get_tree().paused = false
# warning-ignore:return_value_discarded
		get_tree().reload_current_scene()

func _on_PauseControl_tree_entered():
	hide()

