extends Node

export var normal_label_color = Color()
export var hover_label_color = Color()
var pause_state = false

func _input(event):
	if event is InputEventKey :
		if event.scancode == 16777217 and event.pressed:
			if pause_state == false:
				if get_parent().game:
					ui_pause(true)
			else:
				ui_pause(false)
				
func ui_pause(state):
	pause_state = state
	get_tree().paused = state
	$pause_menu/resume.modulate = normal_label_color
	$pause_menu/restart.modulate = normal_label_color
	$pause_menu/exit.modulate = normal_label_color
	$pause_menu.visible = state

func _on_resume_button_mouse_entered():
	$pause_menu/resume.modulate = hover_label_color
	$pause_menu/menu_sound.play()

func _on_resume_button_mouse_exited():
	$pause_menu/resume.modulate = normal_label_color

func _on_restart_button_mouse_entered():
	$pause_menu/restart.modulate = hover_label_color
	$pause_menu/menu_sound.play()

func _on_restart_button_mouse_exited():
	$pause_menu/restart.modulate = normal_label_color

func _on_exit_button_mouse_entered():
	$pause_menu/exit.modulate = hover_label_color
	$pause_menu/menu_sound.play()

func _on_exit_button_mouse_exited():
	$pause_menu/exit.modulate = normal_label_color
	
func _on_resume_button_pressed():
	ui_pause(false)

func _on_restart_button_pressed():
# warning-ignore:return_value_discarded
	var fader_anim = get_parent().get_node("fader/anim")
	fader_anim.play("fade_in")
	yield(fader_anim, "animation_finished")
	get_tree().reload_current_scene()
	ui_pause(false)
	
func _on_exit_button_pressed():
	var fader_anim = get_parent().get_node("fader/anim")
	fader_anim.play("fade_in")
	yield(fader_anim, "animation_finished")
# warning-ignore:return_value_discarded
	get_tree().change_scene("res://scenes/title_screen.tscn")
	ui_pause(false)

func _ready():
# warning-ignore:return_value_discarded
	$pause_menu/resume_button.connect("mouse_entered", self, "_on_resume_button_mouse_entered")
# warning-ignore:return_value_discarded
	$pause_menu/resume_button.connect("mouse_exited", self, "_on_resume_button_mouse_exited")
	
# warning-ignore:return_value_discarded
	$pause_menu/restart_button.connect("mouse_entered", self, "_on_restart_button_mouse_entered")
# warning-ignore:return_value_discarded
	$pause_menu/restart_button.connect("mouse_exited", self, "_on_restart_button_mouse_exited")
	
# warning-ignore:return_value_discarded
	$pause_menu/exit_button.connect("mouse_entered", self, "_on_exit_button_mouse_entered")
# warning-ignore:return_value_discarded
	$pause_menu/exit_button.connect("mouse_exited", self, "_on_exit_button_mouse_exited")
	
# warning-ignore:return_value_discarded
	$pause_menu/resume_button.connect("pressed", self, "_on_resume_button_pressed")
# warning-ignore:return_value_discarded
	$pause_menu/restart_button.connect("pressed", self, "_on_restart_button_pressed")
# warning-ignore:return_value_discarded
	$pause_menu/exit_button.connect("pressed", self, "_on_exit_button_pressed")
