jimmy tremblay-Bernier 86fbe09b20 initial commit
2022-03-12 20:32:56 -05:00

72 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class BasicProductUI : MonoBehaviour, IProductUI
{
private delegate void ActionDelegate();
public int id;
public GameObject uiName;
public Image uiImage;
public GameObject uiPrice;
public GameObject uiDescription;
public Button uiPurchaseButton;
public GameObject uiPurchaseText;
public Image frontPanel;
public Sprite frontBackgroundUnlocked;
public Sprite frontBackgroundLocked;
public void SetInformation(int id, string name, string description, Sprite image, int price, bool isBuyable)
{
this.id = id;
uiName.GetComponent<TextMeshProUGUI>().SetText(name);
uiImage.sprite = image;
uiPrice.GetComponent<TextMeshProUGUI>().SetText(price.ToString());
uiDescription.GetComponent<TextMeshProUGUI>().SetText(description);
uiPurchaseText.GetComponent<TextMeshProUGUI>().SetText("Acheter pour " + price.ToString());
StoreManager storeManager = GameObject.FindGameObjectWithTag("GameController")?.GetComponent<StoreManager>();
uiPurchaseButton.GetComponent<ButtonInteraction>().SetClickAction(() => storeManager.BuyProduct(id));
UpdateUI(isBuyable);
}
public void UpdateUI(bool isBuyable)
{
if(isBuyable)
{
uiPurchaseButton.interactable = true;
frontPanel.sprite = frontBackgroundUnlocked;
}
else
{
uiPurchaseButton.interactable = false;
frontPanel.sprite = frontBackgroundLocked;
}
}
public void ClickTrigger()
{
GetComponent<Animator>().SetBool("Acquired", true);
}
public void HighlightTrigger()
{
GetComponent<Animator>().SetBool("Hover", true);
}
public void PressTrigger()
{
HighlightTrigger();
}
public void NormalTrigger()
{
GetComponent<Animator>().SetBool("Hover", false);
GetComponent<Animator>().SetBool("Acquired", false);
}
}