Добавить таймеры и шкалы прогресса, расширить призовую систему и контроль остатков, восстановить настройки и обновить таблицу призов главного меню.
165 lines
4.9 KiB
C#
165 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace PrizeSystem
|
|
{
|
|
public class TakeOrRiskPanel : MonoBehaviour, IControlable
|
|
{
|
|
public event Action<Prize> PrizeSelected;
|
|
public event Action ContinueSelected;
|
|
|
|
[Header("Ссылки на панели")]
|
|
[SerializeField] private Image CurrentPrizeFrame;
|
|
[SerializeField] private Image NextPrizeFrame;
|
|
[SerializeField] private PrizeView CurrentPrizeView;
|
|
[SerializeField] private PrizeView NextPrizeView;
|
|
|
|
[Header("Цветовая анимация")]
|
|
[SerializeField] private Color DisabledColor;
|
|
[SerializeField] private float HsvSpeed = 0.3f;
|
|
|
|
[SerializeField] private AudioClip StartAcceptingClip;
|
|
|
|
private readonly List<Prize> _prizes = new();
|
|
private int _prizeIndex;
|
|
private bool _continueAvailable;
|
|
private bool _continueSelected;
|
|
private bool _waitForActionRelease;
|
|
private TextMeshProUGUI _title;
|
|
|
|
public bool ControlsEnabled { get; set; }
|
|
|
|
private void Awake()
|
|
{
|
|
Transform titleTransform = transform.Find("Title");
|
|
|
|
if (titleTransform != null)
|
|
_title = titleTransform.GetComponent<TextMeshProUGUI>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!ControlsEnabled)
|
|
return;
|
|
|
|
DisplayGraphics();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
ControlsEnabled = false;
|
|
ClearPrizes();
|
|
}
|
|
|
|
public void Open(IReadOnlyList<Prize> prizes, bool continueAvailable, Prize nextPrize)
|
|
{
|
|
_prizes.Clear();
|
|
|
|
if (prizes != null)
|
|
{
|
|
foreach (Prize prize in prizes)
|
|
{
|
|
if (prize != null && prize is not EmptyPrize)
|
|
_prizes.Add(prize);
|
|
}
|
|
}
|
|
|
|
if (_prizes.Count == 0)
|
|
return;
|
|
|
|
_prizeIndex = 0;
|
|
_continueAvailable = continueAvailable;
|
|
_continueSelected = false;
|
|
_waitForActionRelease = true;
|
|
|
|
if (_title != null)
|
|
{
|
|
_title.text = _continueAvailable
|
|
? "ЗАБРАТЬ ПРИЗ ИЛИ ИГРАТЬ ДАЛЬШЕ?"
|
|
: _prizes.Count > 1
|
|
? "ВЫБЕРИТЕ ПРИЗ"
|
|
: "ЗАБРАТЬ ПРИЗ";
|
|
}
|
|
|
|
NextPrizeFrame.gameObject.SetActive(_continueAvailable);
|
|
CurrentPrizeView.SetPrize(_prizes[_prizeIndex]);
|
|
|
|
if (_continueAvailable && nextPrize != null)
|
|
NextPrizeView.SetPrize(nextPrize);
|
|
else
|
|
NextPrizeView.Clear();
|
|
|
|
gameObject.SetActive(true);
|
|
ControlsEnabled = true;
|
|
ControlsPerformer.Instance.SetControlable(this);
|
|
|
|
if (StartAcceptingClip != null)
|
|
SoundManager.instance.PlaySfx(StartAcceptingClip);
|
|
|
|
DisplayGraphics();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
ControlsEnabled = false;
|
|
ControlsPerformer.Instance.SetControlable(null);
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void UpdateControls()
|
|
{
|
|
if (_waitForActionRelease)
|
|
{
|
|
if (In.GetAction(JoystickSide.Both, InteractMode.Continious))
|
|
return;
|
|
|
|
_waitForActionRelease = false;
|
|
}
|
|
|
|
Vector2Int direction = In.GetAxis(JoystickSide.Both, InteractMode.Discrete);
|
|
|
|
if (_continueAvailable && direction.x != 0)
|
|
{
|
|
_continueSelected = direction.x > 0;
|
|
DisplayGraphics();
|
|
}
|
|
|
|
if (!_continueSelected && direction.y != 0 && _prizes.Count > 1)
|
|
{
|
|
_prizeIndex = (_prizeIndex - direction.y + _prizes.Count) % _prizes.Count;
|
|
CurrentPrizeView.SetPrize(_prizes[_prizeIndex]);
|
|
}
|
|
|
|
if (!In.GetAction(JoystickSide.Both, InteractMode.Discrete))
|
|
return;
|
|
|
|
bool continueSelected = _continueSelected;
|
|
Prize selectedPrize = _prizes[_prizeIndex];
|
|
Close();
|
|
|
|
if (continueSelected)
|
|
ContinueSelected?.Invoke();
|
|
else
|
|
PrizeSelected?.Invoke(selectedPrize);
|
|
}
|
|
|
|
private void ClearPrizes()
|
|
{
|
|
CurrentPrizeView.Clear();
|
|
NextPrizeView.Clear();
|
|
_prizes.Clear();
|
|
}
|
|
|
|
private void DisplayGraphics()
|
|
{
|
|
float hue = (Time.unscaledTime * HsvSpeed) % 1f;
|
|
Color animatedColor = Color.HSVToRGB(hue, 1f, 1f);
|
|
CurrentPrizeFrame.color = _continueSelected ? DisabledColor : animatedColor;
|
|
NextPrizeFrame.color = _continueSelected ? animatedColor : DisabledColor;
|
|
}
|
|
}
|
|
}
|