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

50 lines
1.1 KiB
C#
Raw Permalink Normal View History

2021-11-26 11:16:25 +03:00
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();
}
}