using Kryz.CharacterStats.Examples; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CraftingUI : MonoBehaviour { public GameObject craftingUI; public List slots = new List(); [SerializeField] private GameEvent onCraftingUIClosed; [SerializeField] private GameEvent onVendorReleased; [SerializeField] private GameEventListener onCraftingAnvilInteracted; [SerializeField] private GameEventListener onCraftingAnvilReleased; public EquippableItemInstance currentlySelectedCraftingItem; private void Awake() { onCraftingAnvilInteracted.Response.AddListener(OpenCrafting); onCraftingAnvilReleased.Response.AddListener(CloseCrafting); Inventory.Instance.OnItemRightClickedEventWhileCrafting.AddListener(AddToCrafting); craftingUI.SetActive(false); } private void InitializeCraftingUI() { for (int i = 0; i < slots.Count; i++) //TODO: Remove these extra slots or convert them into crafting stone slots (list of stones to apply) { slots[i].ClearSlot(); } //TODO: Add currently selected crafting item to the crafting item slot if not already present } public void OpenCrafting() { InitializeCraftingUI(); craftingUI.SetActive(true); Inventory.Instance.isVendoring = false; Inventory.Instance.isCrafting = true; Inventory.Instance.OpenInventory(); //Close remaining vendors in case there is one open to avoid conflicts onVendorReleased.Raise(); } public void CloseCrafting() { craftingUI.SetActive(false); Inventory.Instance.isCrafting = false; Inventory.Instance.CloseInventory(); onCraftingUIClosed.Raise(); } private void AddToCrafting(ItemInstance item) { if (item is not EquippableItemInstance) return; if (Inventory.Instance.RemoveItem(item)) { CoinBag.Instance.ChangeAmount(item.sellPricePlayer); ItemTooltip.Instance.HideTooltip(); EquippedItemTooltip.Instance.HideTooltip(); } } }