using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using TMPro;
public class Slot : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
public GameObject item;
public int ID;
public string type;
public string description;
public bool empty;
public Transform slotIconGO;
public Sprite emptySlotSprite;
public Sprite icon;
public int amount;
public TextMeshProUGUI amountText;
public GameObject tooltipBackground;
public TextMeshProUGUI infoText;
public void OnPointerClick(PointerEventData pointerEventData)
{
UseItem();
}
public void OnPointerEnter(PointerEventData pointerEventData)
{
if (!empty)
{
tooltipBackground.SetActive(true);
infoText.text = type + "n" + description;
}
}
public void OnPointerExit(PointerEventData pointerEventData)
{
tooltipBackground.SetActive(false);
}
private void Start()
{
icon = GetComponent<Sprite>();
// Initialize slot with the manually added item
if (item != null)
{
Item itemComponent = item.GetComponent<Item>();
if (itemComponent != null)
{
UpdateSlot(itemComponent.icon);
amountText.text = amount.ToString();
}
}
}
private void Update()
{
if (tooltipBackground.activeSelf)
{
tooltipBackground.transform.position = Input.mousePosition + new Vector3(10, -10, 0);
}
}
public void UpdateSlot(Sprite newIcon)
{
icon = newIcon;
if (slotIconGO != null)
{
Image slotImage = slotIconGO.GetComponent<Image>();
if (slotImage != null)
{
slotImage.sprite = icon;
}
}
}
public void ClearSlot()
{
icon = null;
if (slotIconGO != null)
{
Image slotImage = slotIconGO.GetComponent<Image>();
if (slotImage != null)
{
slotImage.sprite = emptySlotSprite;
}
}
}
private void UseItem()
{
Item itemComponent = item.GetComponent<Item>();
if (itemComponent != null)
{
itemComponent.ItemUsage();
}
if (!empty)
{
amount--;
if (amount <= 0)
{
ClearSlot();
}
UpdateAmountText();
}
}
void UpdateAmountText()
{
if (amountText != null)
{
if (amount > 1)
{
amountText.text = amount.ToString();
}
else
{
amountText.text = "";
}
}
}
public void increaseAmount()
{
amount++;
amountText.text = amount.ToString();
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}