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

public class TileInfo : MonoBehaviour {

    public GameObject panel;
    public WorldInfo worldInfo;
    public Text temperatureDisplay;
    public Text humidityDisplay;
    public Text lifeDisplay;
    public Text nameDisplay;
    
    public string[] humidityText;
	
	void Update () { 
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        var hitinfo = new RaycastHit();
        Physics.Raycast(ray, out hitinfo);
        var col = hitinfo.collider;
        if (col == null)
        {
            panel.SetActive(false);
        }
        else
        {
            panel.SetActive(true);
            Tile tile = col.GetComponentInParent<Tile>();
            if (tile == null)
                return;
            worldInfo.world = tile.world;
            nameDisplay.text = tile.name;
            temperatureDisplay.text = Tile.TempToString(tile.temperature);
            humidityDisplay.text = humidityText[tile.humidity];
            lifeDisplay.text = "Life: ";
            if (tile.abundance <= 0f)
                lifeDisplay.text += "None."; // todo: give reason
            else
            {
                lifeDisplay.text += tile.intelligence.ToString();
            }
        }
	}
}
