using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class UI_Gameplay : TM_UI_Base
{
    public TextMeshProUGUI txt_health;
    public TextMeshProUGUI txt_energy;
    public TextMeshProUGUI txt_planet;
    public TextMeshProUGUI txt_score;
    public TextMeshProUGUI txt_location;
    public TextMeshProUGUI txt_alart;
    public TextMeshProUGUI txt_how2play;

    private GameManager theGame;

    private float fAlartTimer;
    private float fTutorialTime;

	// Use this for initialization
	void Start () 
    {
		theGame = GameManager.GetGame();
    }

    public void PrepareForNewGame()
    {
        txt_how2play.enabled = true;
        fTutorialTime = 10.0f;
        fAlartTimer = 0f;
    }

    public void RemindPlayerAboutBase()
    {
        fAlartTimer = 3.0f;
    }

	// Update is called once per frame
	void Update ()
	{
	    if (bFirstUpdate)
	    {
            bFirstUpdate = false;
            TurnOff();
	        return;
	    }

	    fTutorialTime -= Time.deltaTime;
	    if (fTutorialTime < 0f)
	    {
	        txt_how2play.enabled = false;
	    }

	    Color dangerColor = Color.Lerp(theGame.color_Gold, theGame.color_Red, Mathf.PingPong(Time.time * 4.0f, 1.0f));

        //Player health
	    int iPlayerHealth = theGame.thePlayer.GetHealth();
	    txt_health.text = "Health\n" + iPlayerHealth + "%";
	    txt_health.color = iPlayerHealth > 30 ? Color.white : dangerColor;

        //Collected energy
	    txt_energy.text = "Enerjumz\n" + theGame.thePlayer.iEnergyCollected.ToString();
	    txt_energy.color = Color.white;

        //planet size
	    txt_planet.text = "Planet size\n" + theGame.GetSizeOfPlanetString();

        //score
	    txt_score.text = "Score\n" + theGame.GetScore();

        //location
	    string strLoc = "[" + theGame.thePlayer.vWorldPos.x.ToString("0.0") + "," + theGame.thePlayer.vWorldPos.y.ToString("0.0") + "]";
	    txt_location.text = strLoc;

        //alart
	    if (fAlartTimer > 0f)
	    {
	        fAlartTimer -= Time.deltaTime;
	        txt_alart.color = dangerColor;
	        txt_location.color = dangerColor;
	    }
	    else
	    {
	        txt_alart.color = Color.clear;
	        txt_location.color = Color.white;
	    }
	}

}
