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

53 lines
1.3 KiB
C#

using System;
using game;
using UnityEngine;
using UnityEngine.UI;
namespace RND
{
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();
}
}
}