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

public class ItemUI : MonoBehaviour {

	public Image background;
	public Text itemName, itemType, itemSubType, itemRarity;
	public GameObject displayObj;


	void Update () {
		if (displayObj) {
			Vector3 namePos = Camera.main.WorldToScreenPoint (displayObj.transform.position) + new Vector3 (175f, 75f, 0f);
			background.transform.position = namePos;
			if (!background.gameObject.activeInHierarchy)
				background.gameObject.SetActive (true);
		} else if (background.gameObject.activeInHierarchy) {
			background.gameObject.SetActive (false);
		}
	}

	public void AssignUIWand (WandScript script) {
		displayObj = script.gameObject;
		itemName.text = (script.gameObject.name.Contains ("(")) ? itemName.text = script.gameObject.name.Remove (script.gameObject.name.IndexOf ("(")) : itemName.text = script.gameObject.name;
		itemType.text = "Type: " + script.wand.type.ToString ();
		itemSubType.text = "Sub Type: " + script.wand.subType.ToString ();
		itemRarity.text =  "Rarity: " + script.wand.rarity.ToString ();
		background.color =script.wand.iconColor;
	}

	public void AssignUIPotion (PotionScript script) {
		displayObj = script.gameObject;
		itemName.text = (script.gameObject.name.Contains ("(")) ? itemName.text = script.gameObject.name.Remove (script.gameObject.name.IndexOf ("(")) : itemName.text = script.gameObject.name;
		itemType.text = "Type: " + script.potion.type.ToString ();
		itemSubType.text = "Size: " + script.potion.size.ToString ();
		itemRarity.text = "Rarity: " + script.potion.potionRarity.ToString ();
		background.color = script.potion.iconColor;
	}
}
