hellbound/Assets/Scripts/Game/UI/Market/ConfirmationWindow.cs

50 lines
1.1 KiB
C#

using System;
using game;
using UnityEngine;
using UnityEngine.UI;
public class ConfirmationWindow : Window
{
public event Action<ConfBaseShopItem, EnumClickResult> OnHaveResult;
[SerializeField] private Button closeButton;
[SerializeField] private Button buyButton;
[SerializeField] private Image image;
[SerializeField] private Text priceText;
private ConfBaseShopItem _itemToBuy;
public override int ZOrder => -6;
private void Start()
{
buyButton.onClick.AddListener(() => BuyButtonClick());
closeButton.onClick.AddListener(() => CloseButtonClick());
}
public void SetItemForBuy(ConfBaseShopItem item)
{
_itemToBuy = item;
UpdateView();
}
private void BuyButtonClick()
{
OnHaveResult?.Invoke(_itemToBuy, EnumClickResult.Purchased);
Close();
}
private void UpdateView()
{
priceText.text = _itemToBuy.price.ToString();
image.sprite = Assets.Create<Sprite>(_itemToBuy.openPreviewIcon);
}
private void CloseButtonClick()
{
OnHaveResult?.Invoke(_itemToBuy, EnumClickResult.None);
Close();
}
}