Added items, inventory, basic inv mechanics and art, added item comparison, v1.3.0
This commit is contained in:
158
Assets/Scripts/InventorySlot.cs
Normal file
158
Assets/Scripts/InventorySlot.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class InventorySlot : MonoBehaviour
|
||||
{
|
||||
TooltipHandler tooltip;
|
||||
Item[] items = new Item[3];
|
||||
public bool[] itemRemoved = {false, false, false};
|
||||
int currentBag = 0;
|
||||
public ItemPlace place;
|
||||
Item equip;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
tooltip = GameObject.Find("TooltipHandler").GetComponent<TooltipHandler>();
|
||||
}
|
||||
|
||||
public void updateCurrentBag(int currentBag)
|
||||
{
|
||||
this.currentBag = currentBag;
|
||||
}
|
||||
|
||||
public void setItem(Item item)
|
||||
{
|
||||
items[currentBag] = item;
|
||||
itemRemoved[currentBag] = false;
|
||||
}
|
||||
|
||||
public Item getItem()
|
||||
{
|
||||
return items[currentBag];
|
||||
}
|
||||
|
||||
public void removeItem()
|
||||
{
|
||||
items[currentBag] = null;
|
||||
itemRemoved[currentBag] = true;
|
||||
}
|
||||
|
||||
public void showTooltip()
|
||||
{
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
if (items[currentBag] != null)
|
||||
{
|
||||
string text = items[currentBag].getDisplayText();
|
||||
Item equip = GameObject.Find("Inventory").GetComponent<Inventory>().getEquip(items[currentBag].getPlace());
|
||||
if (equip != null)
|
||||
{
|
||||
text = "(Current)\r\n" + equip.getDisplayText() + "----------\r\n" + text;
|
||||
}
|
||||
tooltip.showTooltip(text);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equip != null)
|
||||
{
|
||||
tooltip.showTooltip(equip.getDisplayText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hideTooltip()
|
||||
{
|
||||
tooltip.hideToolTip();
|
||||
}
|
||||
|
||||
public void onClick()
|
||||
{
|
||||
removeItem();
|
||||
tooltip.hideToolTip();
|
||||
}
|
||||
|
||||
public void OnMouseDrag()
|
||||
{
|
||||
GameObject.Find("Inventory").GetComponent<Inventory>().setDrag(gameObject);
|
||||
}
|
||||
|
||||
public void OnMouseUp()
|
||||
{
|
||||
GameObject startDrag = GameObject.Find("Inventory").GetComponent<Inventory>().getDrag();
|
||||
Item item;
|
||||
bool isSwap = false;
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
item = startDrag.GetComponent<InventorySlot>().getItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
item = startDrag.GetComponent<InventorySlot>().getEquip();
|
||||
}
|
||||
if (item != null)
|
||||
{
|
||||
if (place != item.getPlace() && place != ItemPlace.BAG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
if (items[currentBag] != null)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(items[currentBag]);
|
||||
isSwap = true;
|
||||
}
|
||||
setItem(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equip != null)
|
||||
{
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(equip);
|
||||
isSwap = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
setEquip(item);
|
||||
}
|
||||
if (!isSwap)
|
||||
{
|
||||
if (startDrag.GetComponent<InventorySlot>().place != ItemPlace.BAG)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().removeEquip();
|
||||
}
|
||||
else
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().removeItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Item getEquip()
|
||||
{
|
||||
return equip;
|
||||
}
|
||||
|
||||
public void setEquip(Item item)
|
||||
{
|
||||
equip = item;
|
||||
}
|
||||
|
||||
public void removeEquip()
|
||||
{
|
||||
equip = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user