- Crafting UI fully functional - Crafting Stat stones and modular equippable items fully functional Notes: - Urgent need for exclusive(auto sorted) inventory for stones only - Something to do with the "trash" modular items instead of just selling - Add new uses for gold besides equipment, preset items will probably be worthless with modular crafting
80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using Kryz.CharacterStats.Examples;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class VendorSlotUI : ItemSlot
|
|
{
|
|
public TMP_Text priceText;
|
|
public Image currencyIcon;
|
|
public bool soldMultipleTimes = false;
|
|
|
|
CoinBag coinBag;
|
|
Inventory inventory;
|
|
private VendorDataInstance currentVendorData;
|
|
VendorItemInstance vendorItem;
|
|
|
|
private void Awake()
|
|
{
|
|
coinBag = FindObjectOfType<CoinBag>();
|
|
inventory = FindObjectOfType<Inventory>();
|
|
}
|
|
|
|
public void AddItem(VendorDataInstance vendor, VendorItemInstance newItem)
|
|
{
|
|
vendorItem = newItem;
|
|
Item = vendorItem.item;
|
|
currentVendorData = vendor;
|
|
priceText.text = Item.sellPriceVendor.ToString();
|
|
image.sprite = Item.Icon;
|
|
image.enabled = true;
|
|
}
|
|
|
|
public void ClearSlot()
|
|
{
|
|
Item = null;
|
|
currentVendorData = null;
|
|
priceText.text = "";
|
|
image.sprite = null;
|
|
image.enabled = false;
|
|
}
|
|
|
|
public void Purchase()
|
|
{
|
|
if (Item == null) return;
|
|
|
|
if(coinBag.HasEnoughCoin(Item.sellPriceVendor))
|
|
{
|
|
if(inventory.AddItem(Item))
|
|
{
|
|
coinBag.SpendCoin(Item.sellPriceVendor);
|
|
|
|
if (vendorItem.soldMultipleTimes) return;
|
|
|
|
currentVendorData.items.Remove(vendorItem);
|
|
ClearSlot();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Failed to purchase");
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
ItemTooltip.Instance.ShowTooltip(Item);
|
|
if(Item is EquippableItemInstance ei)
|
|
{
|
|
EquippableItemInstance equippedInSameSlot = EquipmentPanel.Instance.GetEquippedItemOnSpecificSlot(ei.EquipmentType);
|
|
if (equippedInSameSlot != null && !string.IsNullOrEmpty(equippedInSameSlot.ItemName))
|
|
{
|
|
EquippedItemTooltip.Instance.ShowTooltip(equippedInSameSlot);
|
|
}
|
|
}
|
|
}
|
|
}
|