132 lines
4.1 KiB
C#
132 lines
4.1 KiB
C#
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PveWinPanel : MonoBehaviour, IControlable
|
|
{
|
|
[SerializeField] private RectTransform panel;
|
|
[SerializeField] private float startPanelX, shownPanelX, hiddenPanelX;
|
|
[SerializeField] private Transform description;
|
|
[SerializeField] private Image background;
|
|
[SerializeField] private Color backgroundEnabledColor, backgroundDisabledColor;
|
|
|
|
[SerializeField] private TextMeshProUGUI moves;
|
|
[SerializeField] private TextMeshProUGUI time;
|
|
|
|
[SerializeField] private AnimationCurve elasticCurve;
|
|
private Sequence _animation;
|
|
|
|
[SerializeField] private PveLossButton continueButton;
|
|
|
|
public bool ControlsEnabled { get; set; }
|
|
|
|
|
|
|
|
public void Open()
|
|
{
|
|
ResultPanelTimeout timeout = GetComponent<ResultPanelTimeout>();
|
|
timeout?.Cancel();
|
|
if (_animation != null)
|
|
{
|
|
_animation.Kill();
|
|
}
|
|
|
|
Initialize();
|
|
_animation = GetOpenSequence();
|
|
_animation.onComplete += () =>
|
|
{
|
|
ControlsEnabled = true;
|
|
timeout?.StartCountdown();
|
|
};
|
|
_animation.PlayForward();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
GetComponent<ResultPanelTimeout>()?.Cancel();
|
|
ControlsEnabled = false;
|
|
ControlsPerformer.Instance.SetControlable(null);
|
|
if (_animation != null)
|
|
{
|
|
_animation.Kill();
|
|
}
|
|
|
|
_animation = GetCloseSequence();
|
|
_animation.onComplete += () =>
|
|
{
|
|
gameObject.SetActive(false);
|
|
GameManager.Instance.ContinueAfterPveWin();
|
|
};
|
|
_animation.PlayForward();
|
|
}
|
|
|
|
private Sequence GetCloseSequence()
|
|
{
|
|
Sequence seq = DOTween.Sequence();
|
|
seq.Append(continueButton.transform.DOScale(0, 0.4f).SetEase(Ease.InBack));
|
|
seq.Append(panel.DOAnchorPosX(hiddenPanelX, 1f).SetEase(Ease.InBack));
|
|
seq.Join(background.DOColor(backgroundDisabledColor, 2).SetEase(Ease.InCubic));
|
|
return seq;
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
ControlsEnabled = false;
|
|
|
|
panel.anchoredPosition = new Vector2(startPanelX, panel.anchoredPosition.y);
|
|
description.localScale = Vector3.zero;
|
|
|
|
moves.transform.localScale = Vector3.zero;
|
|
time.transform.localScale = Vector3.zero;
|
|
continueButton.transform.localScale = Vector3.zero;
|
|
|
|
moves.text = $"ходы: {TurnTracker.Moves}";
|
|
time.text = $"время: {TurnTracker.Timer:F2} сек.";
|
|
background.color = backgroundDisabledColor;
|
|
|
|
ControlsPerformer.Instance.SetControlable(this);
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
private Sequence GetOpenSequence()
|
|
{
|
|
Sequence seq = DOTween.Sequence();
|
|
|
|
//приезд панели
|
|
seq.Append(panel.DOAnchorPosX(shownPanelX, 1f).SetEase(Ease.OutBack));
|
|
//фон
|
|
seq.Join(background.DOColor(backgroundEnabledColor, 1).SetEase(Ease.OutCubic));
|
|
|
|
//текст описания
|
|
seq.Append(description.DOScale(1, 0.5f).SetEase(elasticCurve));
|
|
seq.AppendInterval(0.2f);
|
|
|
|
//вращение описания
|
|
float rotationDuration = 0.2f;
|
|
seq.Append(description.DOLocalRotate(new Vector3(0, 0, 2), rotationDuration));
|
|
seq.Append(description.DOLocalRotate(new Vector3(0, 0, -2), rotationDuration));
|
|
seq.Append(description.DOLocalRotate(new Vector3(0, 0, 0), rotationDuration / 2));
|
|
|
|
//появление надписей
|
|
seq.Append(time.transform.DOScale(1, 0.5f).SetEase(Ease.OutBack));
|
|
seq.Join(moves.transform.DOScale(1, 0.5f).SetEase(Ease.OutBack));
|
|
seq.Append(continueButton.transform.DOScale(1, 0.5f).SetEase(Ease.OutBack));
|
|
seq.AppendCallback(continueButton.Select);
|
|
|
|
return seq;
|
|
}
|
|
|
|
public void UpdateControls()
|
|
{
|
|
if(ControlsEnabled == false) return;
|
|
|
|
if(In.GetAction(JoystickSide.Both, InteractMode.Discrete))
|
|
{
|
|
print("Кнопка нажата");
|
|
Close();
|
|
}
|
|
}
|
|
}
|