78 lines
2.4 KiB
C#

using DG.Tweening;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class RevengeButton : MButton
{
[Header("Layout ссылки")]
[SerializeField] private TextMeshProUGUI oldPrice;
[SerializeField] private TextMeshProUGUI actualPrice;
[SerializeField] private Image saleImage;
[SerializeField] private Image background;
[SerializeField] private List<TextMeshProUGUI> texts;
[Header("Анимация")]
[SerializeField] private float switchDuration;
[SerializeField] private float enabledScale = 1.1f, disabledScale = 0.9f;
[SerializeField] private Ease ease = Ease.Linear;
private Sequence animSequence;
private bool interactable;
public override void Initialize()
{
if (PaymentSystem.Freeplay)
{
oldPrice.gameObject.SetActive(false);
actualPrice.gameObject.SetActive(false);
saleImage.gameObject.SetActive(false);
return;
}
int revengePrice = PaymentSystem.PriceRevenge;
int normalPrice = PaymentSystem.PricePve;
actualPrice.gameObject.SetActive(true);
actualPrice.text = $"{revengePrice} {PaymentSystem.ValutaName}";
bool revengeCheaper = revengePrice < normalPrice;
oldPrice.gameObject.SetActive(revengeCheaper);
oldPrice.text = $"{normalPrice} {PaymentSystem.ValutaName}";
saleImage.gameObject.SetActive(revengeCheaper);
}
public override void Select() => SetSelected(true);
public override void Deselect() => SetSelected(false);
public override void Interact()
{
if (!interactable) return;
GameManager.instance.PerformRevenge();
}
private void SetSelected(bool selected)
{
interactable = false;
if (animSequence != null)
animSequence.Kill();
Color bgColor = selected ? Color.white : Color.black;
Color textColor = selected ? Color.black : Color.white;
float scale = selected ? enabledScale : disabledScale;
animSequence.Join(background.DOColor(bgColor, switchDuration).SetEase(ease));
animSequence.Join(transform.DOScale(scale, switchDuration).SetEase(ease));
foreach (var text in texts)
animSequence.Join(text.DOColor(textColor, switchDuration).SetEase(ease));
animSequence.onComplete += () => interactable = selected;
animSequence.PlayForward();
}
}