using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.EventSystems; public class ShopMenuItemController : MonoBehaviour, IPointerClickHandler { [SerializeField] public TextMeshProUGUI itemNameText; [SerializeField] public TextMeshProUGUI itemDescriptionText; [SerializeField] public TextMeshProUGUI priceText; [SerializeField] public InventorySlotController shopItemSlot; private PlayerMovement playerMovement; private GameAudioController gameAudioController; Item item; int price; public bool Purchase() { Item tempItem = item; if (State.state.inventory.money >= price) { if (State.state.inventory.GainItem(tempItem) == 0) { Debug.Log("Successfully purchased " + item.data.name); State.state.inventory.money -= price; // TODO: Update inventory UI if present in shop return true; } else { Debug.Log("Failed purchase, no inventory space!"); } } else { Debug.Log("Failed purchase, not enough money!"); } return false; } public void OnPointerClick(PointerEventData eventData) { if (eventData.button.Equals(PointerEventData.InputButton.Left)) { if (Purchase()) { gameAudioController.audioSource.PlayOneShot( gameAudioController.UI_Shop_Purchase); playerMovement.cutscene = false; Destroy(GameObject.FindGameObjectWithTag("ShopPanel")); } else { gameAudioController.audioSource.PlayOneShot( gameAudioController.UI_Shop_PurchaseFail); // TODO: Add Close button and remove this crap. playerMovement.cutscene = false; Destroy(GameObject.FindGameObjectWithTag("ShopPanel")); } } } public void Setup(Item item, int price) { this.item = item; this.price = price; itemNameText.text = item.data.name; itemDescriptionText.text = item.data.description; shopItemSlot.Refresh(item); priceText.text = price.ToString() + "G"; } void Awake() { playerMovement = GameObject.FindGameObjectWithTag("Player").GetComponent(); gameAudioController = GameObject.FindGameObjectWithTag("GameAudio") .GetComponent(); } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }