using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HUD : MonoBehaviour
{
    public GameObject p1Panel;
    public GameObject p2Panel;
    public GameObject p3Panel;
    public GameObject p4Panel;

    public GameObject m_TimerPanel;

    private bool p1 = false;
    private bool p2 = false;
    private bool p3 = false;
    private bool p4 = false;

    private InGameState m_InGameState = null;

    // Use this for initialization
    void Start ()
    {
        p1 = (GameManager.GetPersistantGameInfo().ActivePlayers.Count > 0);
        p2 = (GameManager.GetPersistantGameInfo().ActivePlayers.Count > 1);
        p3 = (GameManager.GetPersistantGameInfo().ActivePlayers.Count > 2);
        p4 = (GameManager.GetPersistantGameInfo().ActivePlayers.Count > 3);

        p1Panel.SetActive(p1);
        p2Panel.SetActive(p2);
        p3Panel.SetActive(p3);
        p4Panel.SetActive(p4);

        m_InGameState = (InGameState)GameManager.Instance.CurrentGameState;
    }
	
	// Update is called once per frame
	void Update ()
    {
        if (p1) 
        {
            GameObject.Find("Score1Text").GetComponent<Text>().text = GameManager.GetPersistantGameInfo().ActivePlayers[0].Score.ToString();
        }

        if (p2)
        {
            GameObject.Find("Score2Text").GetComponent<Text>().text = GameManager.GetPersistantGameInfo().ActivePlayers[1].Score.ToString();
        }

        if (p3)
        {
            GameObject.Find("Score3Text").GetComponent<Text>().text = GameManager.GetPersistantGameInfo().ActivePlayers[2].Score.ToString();
        }

        if (p4)
        {
            GameObject.Find("Score4Text").GetComponent<Text>().text = GameManager.GetPersistantGameInfo().ActivePlayers[3].Score.ToString();
        }


        if (m_InGameState.TimerRunning)
        {
            m_TimerPanel.SetActive(true);
            GameObject.Find("TimerText").GetComponent<Text>().text = m_InGameState.TimeLeft.ToString("F0");
        }
        
    }
}
