﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GUIController : MonoBehaviour {

	public Text bananaCount;
	public Text title;
	public bool titleVisible = false;
	public Button resumeButton;

	public Image background;
	public Animator backgroundAnimator;

	void Start() {
		resumeButton.gameObject.SetActive (false);
		Cursor.visible = false;
		Cursor.lockState = CursorLockMode.Locked;
		backgroundAnimator.updateMode = AnimatorUpdateMode.UnscaledTime;
	}

	void Update() {
		if (titleVisible && title.color.a < 1f) {
			Color c = title.color;
			c = new Color (c.r, c.g, c.b, c.a + 0.1f);
			title.color = c;
		} else if (title.color.a > 0f) {
			Color c = title.color;
			c = new Color (c.r, c.g, c.b, c.a - 0.1f);
			title.color = c;
		}
	}

	public void UpdateBananaCount(int count) {
		bananaCount.text = "" + count;
	}

	public void OpenMenu() {
		Cursor.visible = true;
		Cursor.lockState = CursorLockMode.Confined;
		titleVisible = true;
		backgroundAnimator.SetTrigger ("Open");
		resumeButton.gameObject.SetActive (true);
	}

	public void CloseMenu() {
		Cursor.visible = false;
		Cursor.lockState = CursorLockMode.Locked;
		titleVisible = false;
		backgroundAnimator.SetTrigger ("Close");
		resumeButton.gameObject.SetActive (false);
	}
}
