
extends CanvasLayer

func _fixed_process(delta):
	var data = global.stats
	get_node("info/fps_label").set_text("FPS: " + str(OS.get_frames_per_second()))
	get_node("info/ammo_label").set_text("AMMO:" + str(data[3]))
	get_node("info/health").set_value(clamp(data[0],0,1000))
	get_node("info/energy").set_value(clamp(data[1],0,1000))
	get_node("info/time_power").set_value(clamp(data[2],0,1000))
	get_node("info/timer_count_label").set_text(str(floor(global.time / 60)).pad_zeros(2) + ":" + str(int(global.time) % 60).pad_zeros(2))

func _enter_tree():
	Globals.set("UI", self)
	
func _ready():
	get_node("anim").play("fade_in")
	set_fixed_process(true)
	
func _on_resume_button_pressed():
	Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
	global.pause_setting(false)

func _on_options_button_pressed():
	get_node("opt_menu/control_type").set_text(str(global.control_types[global.curent_control_type]))
	get_node("opt_menu").show()
	get_node("pause_menu").hide()
	
func _on_opt_canc_button_pressed():
	get_node("opt_menu").hide()
	get_node("pause_menu").show()

func _on_exit_to_menu_button_pressed():
	get_node("pause_menu").hide()
	global.exit_to_menu()
	
func show_hide_pause_menu(var state):
	get_node("pause_menu").set_hidden(!state)

func show_screen_effect(var effect, var state):
	if state:
		get_node("effects/"+effect).show()
	else:
		get_node("effects/"+effect).hide()
		
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_control_change(changer):
	var new_text = global.change_control_type(changer)
	get_node("opt_menu/control_type").set_text(new_text)
	global.set_input_map()
	Globals.get("PLAYER").bind_keys()
	get_node("/root/main/level/tips").show_tips()
	
func _on_resolution_change(changer):
	var new_text = global.change_resolution(changer)
	if new_text!="":
		get_node("opt_menu/resolution").set_text(new_text)

func _on_restart_button_pressed():
	global.restart_level()

func _on_missions_button_pressed():
	global.show_missions_list = true
	global.exit_to_menu()
