using UnityEngine;
using System.Collections;
[System.Serializable]
public class CombatHUD : MonoBehaviour {
	public GUISkin skin;
	
	private string[] who = new string[3];
	private string[] whom = new string[3];
	
	public AudioClip[] sounds;
	
	private string spreeText;
	private float spreeTime;
	private float maxSpreeTime;
	// Use this for initialization
	void Start () {
		
		for(int x=0;x<who.Length;x++)
		{
			whom[x] = " ";
			who[x] = " ";
		}
	}
	
	// Update is called once per frame
	void Update () {
		if(spreeTime>0)
		{
			spreeTime-=Time.deltaTime;
		}
	}
	
	void OnGUI()
	{
		
		GUI.skin = skin;
		float xSizePercent = Screen.width / 1680.0f;
		float ySizePercent = Screen.height / 1050.0f;	
		
		if(spreeTime>0)
		{
			int c =GUI.skin.label.fontSize;
			int resize = 0;
			if((spreeTime/maxSpreeTime)>0.7f) // 30% of all animation
				resize = (int)((spreeTime-maxSpreeTime*0.7f)/maxSpreeTime*0.3f*204);
			GUI.skin.label.fontSize = 72 + resize;
			
			Vector2 size = GUI.skin.label.CalcSize(new GUIContent(spreeText));
			GUI.color = new Color(1,1,1,0.3f + spreeTime/2.5f);
			GUI.Label(new Rect(Screen.width/2 - size.x/2,90*ySizePercent,Screen.width,Screen.height),spreeText);
			GUI.color = Color.white;
			GUI.skin.label.fontSize = c;
		}
		
		
		if(Input.GetKey(KeyCode.Tab))
		{
			CombatLog.DrawTable();
		}
		
		
		for(int x=0;x<who.Length;x++)
		{
			if(who[x]!=" ")
			{
				int o = GUI.skin.label.fontSize;
				GUI.skin.label.fontSize = 24;
				Vector2 size = GUI.skin.label.CalcSize(new GUIContent(who[x]+" owned "+whom[x]));
				GUI.color = Color.green;
				float y =Screen.width - GUI.skin.label.CalcSize(new GUIContent(who[x]+" owned  "+whom[x])).x;
				GUI.Label(new Rect(y,10*ySizePercent + x*40*ySizePercent,400*xSizePercent,200*ySizePercent),who[x]);
				size = GUI.skin.label.CalcSize(new GUIContent(who[x]));
				y+=size.x;
				GUI.color = Color.white;
				GUI.Label(new Rect(y,10*ySizePercent + x*40*ySizePercent,400*xSizePercent,200*ySizePercent)," owned  ");
				y+= GUI.skin.label.CalcSize(new GUIContent(" owned  ")).x;
				GUI.color = Color.red;
				GUI.Label(new Rect(y+ 10,10*ySizePercent + x*40*ySizePercent,400*xSizePercent,200*ySizePercent),whom[x]);
				GUI.skin.label.fontSize = o;
			}
			
		}
	}
	
	public void AddCombat(string killer, string victim)
	{
		who[0] = who[1];
		whom[0] = whom[1];
		
		
		who[1] = who[2];
		whom[1] = whom[2];
		
		
		who[2] = killer;
		whom[2] = victim;
		//Debug.Log(victim);
		
	}
	
	public void KillingSpree(int spree,bool longer)
	{
		SpreeController sprees = GameObject.FindGameObjectWithTag("Game").GetComponent<SpreeController>();
		foreach(Spree a in sprees.sprees)
		{
			if(a.kills==spree & a.longer == longer)
			{
				spreeText = a.text;
				spreeTime = a.time;
				maxSpreeTime = a.time;
				if(GameObject.FindGameObjectWithTag("Player").transform.FindChild("spree_sounds"))
				{
					GameObject.FindGameObjectWithTag("Player").transform.FindChild("spree_sounds").audio.clip = a.sound;
					GameObject.FindGameObjectWithTag("Player").transform.FindChild("spree_sounds").audio.volume = GameOptions.soundVolume;
					GameObject.FindGameObjectWithTag("Player").transform.FindChild("spree_sounds").audio.Play();
				}
			}
		}
	}


}
	
	
	
