using UnityEngine;
using System.Collections;

public class GameGUI : MonoBehaviour
{
    private GameModel _model;
    public Texture icon;

    void Start()
    {
        _model = FindObjectOfType(typeof(GameModel)) as GameModel;
        Screen.lockCursor = true;
    }

    void Update()
    {
        if ((Input.GetMouseButton(0)) && (_model.lives > 0) && (!_model.isWin))
        {
            Screen.lockCursor = true;
        }
    }
    void OnGUI()
    {
        GUI.skin.box.fontSize = 40;
        GUI.skin.button.fontSize = 20;
        GUI.skin.box.normal.textColor = Color.white;

        if (_model.isWin)
        {
            GUI.Box(new Rect(Screen.width / 2f - 250, Screen.height / 2f - 75, 500, 150), "Congratulations!");

            if (GUI.Button(new Rect(Screen.width / 2f - 80, Screen.height / 2f - 20 + 150, 160, 40), "Menu"))
            {
                Application.LoadLevel("Menu");
            }

            return;
        }

        if (_model.lives > 0)
        {
            GUI.skin.box.alignment = TextAnchor.MiddleCenter;
            GUI.Box(new Rect(10, 10, 150, 80), new GUIContent("x" + _model.lives, icon));
            GUI.Label(new Rect(10, 40, 100, 20), GUI.tooltip);
        }
        else
        {
            
            GUI.Box(new Rect(Screen.width / 2f - 250, Screen.height / 2f - 75, 500, 150), "Game over");

            if (GUI.Button(new Rect(Screen.width / 2f - 80, Screen.height / 2f - 20 + 150, 160, 40), "Menu"))
            {
                Application.LoadLevel("Menu");
            }
        }
    }

}
