using UnityEngine;
using System.Collections;

public class CharacterStatsGui : MonoBehaviour {

    const int WIDTH = 110;
    const int HEIGHT = 80;

    const int YPOS = 0;
    public bool m_playerGui;

    public CharacterObject m_monitorObject;

    private static CharacterStatsGui ms_enemyGui;

	// Use this for initialization
	void Start () 
    {
        if ((m_playerGui == false) && (ms_enemyGui == null))
        {
            ms_enemyGui = this;
        }
	}

    static public void SetEnemy( Transform trans )
    {
        ms_enemyGui.m_monitorObject = trans.GetComponent<CharacterObject>();
    }

    static public void ClearEnemy()
    {
        ms_enemyGui.m_monitorObject = null;
    }

	// Update is called once per frame
	void Update ()
    {
	}

    void OnGUI()
    {
        if (MenuSystem.InIntro)
        {
            return;
        }
        if (m_monitorObject != null)
        {
            if (GridManager.Instance.m_objectList.Contains(m_monitorObject.GetComponent<GridObject>()) == false)
            {
                m_monitorObject = null;
                return;
            }

            int xpos = 0;
            int ypos = 0;

            if (m_playerGui == false)
            {
                // Right align enemies
                xpos = Screen.width - WIDTH;
            }

            CharacterInfo info = m_monitorObject.Info;

            string name = info.m_name;
            if ( m_playerGui )
            {
                name = string.Format("{0} Lv{1}", name, info.m_level);
            }

            GUI.Box(new Rect(xpos, ypos, WIDTH, HEIGHT), name);

            string hpLine = string.Format("HP {0}/{1}", info.m_currentHp, info.m_maxHp);
            string mpLine = string.Format("MP {0}/{1}", info.m_currentMp, info.m_maxMp);
            string atkDefLine = string.Format("ATK:{0} DEF:{1}", info.m_attack, info.m_defense);

            ypos += 20;
            GUI.Label(new Rect(xpos, ypos, WIDTH, HEIGHT), hpLine);
            ypos += 20;
            GUI.Label(new Rect(xpos, ypos, WIDTH, HEIGHT), mpLine);
            ypos += 20;
            GUI.Label(new Rect(xpos, ypos, WIDTH, HEIGHT), atkDefLine);
        }
    }
}
