Files
pgs/Assets/Scripts/UI/CraftingMenuItemController.cs
2026-02-21 16:58:22 -08:00

50 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
public class CraftingMenuItemController : MonoBehaviour, IPointerClickHandler {
[SerializeField] public TextMeshProUGUI itemNameText;
[SerializeField] public TextMeshProUGUI requirementsText;
[SerializeField] public InventorySlotController craftingItemSlot;
private PlayerMovement playerMovement;
Item item;
Hashtable craftingRequirements;
public void OnPointerClick(PointerEventData eventData) {
if (eventData.button.Equals(PointerEventData.InputButton.Left)) {
if (State.state.inventory.CraftItem(item, craftingRequirements)) {
Debug.Log("Successfully crafted " + item.data.name);
playerMovement.controller.PlaySound(playerMovement.controller.audioClipCraft);
playerMovement.cutscene = false;
Destroy(GameObject.FindGameObjectWithTag("CraftingPanel"));
} else {
playerMovement.controller.PlaySound(playerMovement.controller.audioClipCraftFail);
Debug.LogError("Failed to craft " + item.data.name);
}
}
}
public void Setup(Item item, Hashtable craftingRequirements) {
this.item = item;
this.craftingRequirements = craftingRequirements;
craftingItemSlot.Refresh(item);
itemNameText.text = item.data.name;
requirementsText.text = "A bunch of stuff";
// TODO: Populate fields
}
void Awake() {
playerMovement = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMovement>();
}
// Update is called once per frame
void Update()
{
}
}