2022-12-19 03:34:45 +01:00
|
|
|
|
using System.Collections;
|
2022-05-29 21:54:28 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using System; // for Action type
|
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
|
public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler, IDragHandler, IDropHandler, IPointerClickHandler
|
2022-05-29 21:54:28 +02:00
|
|
|
|
{
|
|
|
|
|
[Header("UI Stuff to change")]
|
|
|
|
|
[SerializeField] private TextMeshProUGUI slotItemNumberText;
|
|
|
|
|
[SerializeField] private Image itemImage;
|
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
public DraggablePanelController _PanelController;
|
2022-05-29 21:54:28 +02:00
|
|
|
|
|
|
|
|
|
private Color normalColor = Color.white;
|
|
|
|
|
private Color disabledColor = new Color(1, 1, 1, 0); // transparency = 0
|
|
|
|
|
|
|
|
|
|
[Header("Slot variable")]
|
|
|
|
|
[SerializeField]
|
|
|
|
|
protected int _number;
|
|
|
|
|
public int Number {
|
|
|
|
|
get { return _number; }
|
|
|
|
|
set {
|
|
|
|
|
_number = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[SerializeField]
|
2022-11-19 17:02:31 +01:00
|
|
|
|
protected EquippableItem _item;
|
|
|
|
|
public EquippableItem Item {
|
2022-05-29 21:54:28 +02:00
|
|
|
|
get { return _item; }
|
|
|
|
|
set {
|
|
|
|
|
_item = value;
|
|
|
|
|
|
|
|
|
|
if(_item == null) {
|
|
|
|
|
itemImage.color = disabledColor;
|
|
|
|
|
} else {
|
|
|
|
|
itemImage.sprite = _item.Image;
|
|
|
|
|
itemImage.color = normalColor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int countStackableItems = 0;
|
|
|
|
|
|
2022-06-05 01:57:57 +02:00
|
|
|
|
public event Action<ItemSlot> OnBeginDragEvent;
|
|
|
|
|
public event Action<ItemSlot> OnEndDragEvent;
|
|
|
|
|
public event Action<ItemSlot> OnDragEvent;
|
|
|
|
|
public event Action<ItemSlot> OnDropEvent;
|
2022-12-19 03:34:45 +01:00
|
|
|
|
public event Action<ItemSlot, PointerEventData> OnPointerClickEvent;
|
2022-05-29 21:54:28 +02:00
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
|
/* public ItemSlot() { }
|
|
|
|
|
public ItemSlot(int number, EquippableItem item = null)
|
|
|
|
|
{
|
|
|
|
|
Number = number;
|
|
|
|
|
Item = item;
|
|
|
|
|
}*/
|
2022-12-19 03:34:45 +01:00
|
|
|
|
/*
|
|
|
|
|
public ItemSlot(ItemSlot slot)
|
|
|
|
|
{
|
|
|
|
|
Number = slot.Number;
|
|
|
|
|
Item = slot.Item;
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
|
slotItemNumberText = slot.slotItemNumberText;
|
|
|
|
|
itemImage = slot.itemImage;
|
|
|
|
|
}*/
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
|
|
|
|
public void SetupSlot(int _number, EquippableItem _item, WarehousePanelController _PanelController)
|
2022-05-29 21:54:28 +02:00
|
|
|
|
{
|
2022-06-05 01:57:57 +02:00
|
|
|
|
this._PanelController = _PanelController;
|
2022-05-29 21:54:28 +02:00
|
|
|
|
|
|
|
|
|
Number = _number;
|
|
|
|
|
|
|
|
|
|
if(_item)
|
|
|
|
|
{
|
|
|
|
|
SetItem(_item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
|
public void SetItem(EquippableItem _item) // dont change slot numer after assign new item, numbers are bind during object init
|
2022-05-29 21:54:28 +02:00
|
|
|
|
{
|
|
|
|
|
Item = _item;
|
|
|
|
|
|
|
|
|
|
ChangeEnableImageView(true);
|
|
|
|
|
|
|
|
|
|
countStackableItems +=1;
|
|
|
|
|
|
|
|
|
|
UpdateItemNumberHolder();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 21:34:17 +01:00
|
|
|
|
public void ResetSlot()
|
|
|
|
|
{
|
|
|
|
|
Item = null;
|
|
|
|
|
|
|
|
|
|
ChangeEnableImageView(false);
|
|
|
|
|
|
|
|
|
|
countStackableItems = 0;
|
|
|
|
|
|
|
|
|
|
UpdateItemNumberHolder();
|
|
|
|
|
}
|
2022-05-29 21:54:28 +02:00
|
|
|
|
|
|
|
|
|
private void ChangeEnableImageView(bool _flag)
|
|
|
|
|
{
|
|
|
|
|
itemImage.color = _flag ? normalColor : disabledColor; //!slotImage.enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeNumberHeldView(bool _flag)
|
|
|
|
|
{
|
|
|
|
|
slotItemNumberText.enabled = _flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateItemNumberHolder()
|
|
|
|
|
{
|
|
|
|
|
slotItemNumberText.text = "" + countStackableItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
if(!Item)
|
|
|
|
|
{
|
|
|
|
|
ChangeEnableImageView(false);
|
|
|
|
|
ChangeNumberHeldView(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool CanReceiveItem(Item item)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 21:34:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Events methods
|
2022-05-29 21:54:28 +02:00
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if(OnBeginDragEvent != null)
|
|
|
|
|
OnBeginDragEvent(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if(OnEndDragEvent != null)
|
|
|
|
|
OnEndDragEvent(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if(OnDragEvent != null)
|
|
|
|
|
OnDragEvent(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDrop(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if(OnDropEvent != null)
|
|
|
|
|
OnDropEvent(this);
|
|
|
|
|
}
|
2022-12-19 03:34:45 +01:00
|
|
|
|
|
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if (OnPointerClickEvent != null)
|
|
|
|
|
OnPointerClickEvent(this, eventData);
|
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
|
#endregion
|
2022-05-29 21:54:28 +02:00
|
|
|
|
}
|