extends CanvasLayer

var timer = true
var t = 1200
var m = 0
var s = 0

signal time_is_over()

func _process(delta):
	if timer:
		t -= delta
		m = floor(int(t)/60)
		s = int(t) - m * 60
		update_timer(m,s)
		if t <= 0:
			timer = false
			emit_signal("time_is_over")
			
func update_timer(minutes, secconds):
	get_node("info/time").set_text("%02d:%02d" % [minutes, secconds])
	
func ui_fade_in():
	get_node("anim").play("fade_in")
	
func ui_fade_out():
	get_node("anim").play("fade_out")
		
func ui_update_score(new_score):
	get_node("info/score").set_text(str("%0*d" % [6, new_score]))
	
func ui_show_hint(text, bottom):
	if bottom:
		get_node("hint").set_pos(Vector2(40,128))
	else:
		get_node("hint").set_pos(Vector2(40,32))
	get_node("hint").show()
	get_node("hint/label").set_text(text)
	get_node("hint/anim").play("show")
	
func ui_hide_hint():
	get_node("hint/anim").play("hide")
	yield(get_node("hint/anim"),"finished")
	get_node("hint").hide()
	
func ui_pause_menu(show):
	if show:
		get_node("pause_menu").show()
	else:
		get_node("pause_menu").hide()

func ui_update_progress():
	get_node("info/progress").set_text("зона-" + str(global.current_zone_id) + " уровень-" + str(global.current_level_id))
	
func _ready():
	connect("time_is_over", global, "_on_time_is_over")
	global.gui = self
	set_process(true)
	ui_update_progress()
	ui_update_score(global.current_score)
	
func _on_music_volume_value_changed( value ):
	audio.change_music_volume(value)

func _on_sounds_volume_value_changed( value ):
	audio.get_node("sounds").set_default_volume(value)

func _on_resume_button_pressed():
	global.toogle_pause()

func _on_exit_button_pressed():
	get_tree().change_scene("res://scenes/main_menu.scn")

func _on_cancel_button_pressed():
	get_node("pause_menu").show()
	get_node("options_menu").hide()
	
func _on_options_button_pressed():
	get_node("pause_menu").hide()
	get_node("options_menu").show()
