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

public class ArenaPortraits : MonoBehaviour {

    private setAppearance appearance;
    private setEnemyAppearance enemyAppearance;
    private PlayerStats stats; // to access name
    public Text playerName;
    public Image playerFace;
    public Image playerHead;
    private Color playerColor;
    public Text healthBar;
    public Image healthBarRed;
    //enemy
    private EnemyAI enemy;
    public Text enemyName;
    public Image enemyFace;
    public Image enemyHead;
    private Color enemyColor;
    public Text enemyHealthBar;
    public Image enemyHealthBarRed;

    // Use this for initialization
    void Start () {
        stats = GameObject.Find("Player").GetComponent<PlayerStats>();
        appearance = GameObject.Find("Player").GetComponent<setAppearance>();
        enemyAppearance = GameObject.Find("Enemy").GetComponent<setEnemyAppearance>();
        healthBarRed = GameObject.Find("playerHealthBar").GetComponent<Image>();
        enemyHealthBarRed = GameObject.Find("enemyHealthBar").GetComponent<Image>();
        enemy = GameObject.Find("Enemy").GetComponent<EnemyAI>();
        // player
        playerColor = appearance.getColor();
        playerName.text = stats.getName();
        playerFace.sprite = appearance.getFace();
        playerHead.sprite = appearance.getHead();
        playerHead.color = playerColor;
        enemyPortrait();
    }
	
	// Update is called once per frame
	void Update () {
        // manipulate player health bar
        if (PlayerStats.curHealth <= 0) {
            healthBarRed.enabled = false;
        }
        else {
            healthBarRed.enabled = true;
        }
        healthBar.text = PlayerStats.curHealth.ToString() + " / " + PlayerStats.maxHealth.ToString();
        healthBarRed.fillAmount = (float)PlayerStats.curHealth / PlayerStats.maxHealth;

        // manipulate enemy health bar
        if (enemy.enemyHealth <= 0) {
            enemyHealthBarRed.enabled = false;
        }
        else {
            enemyHealthBarRed.enabled = true;
        }
        enemyHealthBar.text = enemy.enemyHealth.ToString() + " / " + enemy.original;
        enemyHealthBarRed.fillAmount = (float)enemy.enemyHealth / enemy.original;
    }

    // have to call this from RandomAppearance or else this code executes before the random enemy is genertated.
    public void enemyPortrait() {
        enemyName.text = setEnemyAppearance.enemyName;
        enemyFace.sprite = setEnemyAppearance.face;
        enemyHead.sprite = setEnemyAppearance.head;
        enemyHead.color = setEnemyAppearance.color;
    }
}