126 lines
3.7 KiB
C#
126 lines
3.7 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
|
|
namespace PrizeSystem
|
|
{
|
|
public class QrPrizeInput : AbstractPrizeConfigurator
|
|
{
|
|
|
|
[SerializeField] private Image rankImage;
|
|
[SerializeField] private TextMeshProUGUI rankLabel;
|
|
|
|
[SerializeField] private QrTextInput textInput;
|
|
[SerializeField] private Color AccentColor;
|
|
[SerializeField] private AudioClip clickClip;
|
|
[SerializeField] private float SwipeInterval = 0.3f;
|
|
|
|
private int rank = 1;
|
|
private SelectedOption currentOption = SelectedOption.Rank;
|
|
private float LastSwipe = 0;
|
|
private bool CanSwipe => Time.time - LastSwipe > SwipeInterval;
|
|
|
|
private void OnEnable()
|
|
{
|
|
currentOption = SelectedOption.Rank;
|
|
textInput.Light(Color.black);
|
|
rankImage.color = AccentColor;
|
|
|
|
DisplayRank();
|
|
}
|
|
|
|
|
|
public override void Configure(Prize prize)
|
|
{
|
|
if (prize is QrPrize qr)
|
|
{
|
|
rank = qr.Rank;
|
|
textInput.SetText(qr.PrizeText);
|
|
DisplayRank();
|
|
}
|
|
}
|
|
|
|
|
|
public override void ChangeOption(int direction)
|
|
{
|
|
//Ñìåíà îïöèè
|
|
if (currentOption == SelectedOption.Rank) currentOption = SelectedOption.Text;
|
|
else if ((currentOption == SelectedOption.Text)) currentOption = SelectedOption.Rank;
|
|
|
|
TryPlayClick();
|
|
|
|
if (currentOption == SelectedOption.Rank)
|
|
{
|
|
textInput.DisableAllSlots();
|
|
textInput.Light(Color.black);
|
|
rankImage.color = AccentColor;
|
|
|
|
}
|
|
else if (currentOption == SelectedOption.Text)
|
|
{
|
|
textInput.Light(AccentColor);
|
|
textInput.EnableFirstSlot();
|
|
rankImage.color = Color.black;
|
|
}
|
|
}
|
|
public override void Swipe(int direction)
|
|
{
|
|
|
|
if (currentOption == SelectedOption.Rank)
|
|
{
|
|
if(direction == 0)
|
|
{
|
|
LastSwipe = 0;
|
|
return;
|
|
}
|
|
SwipeRank(direction);
|
|
}
|
|
|
|
else if (currentOption == SelectedOption.Text)
|
|
{
|
|
int leftDirection = 0;
|
|
if (In.GetButton(ButtonPinMapping.left1)) leftDirection -= 1;
|
|
if (In.GetButton(ButtonPinMapping.right1)) leftDirection += 1;
|
|
|
|
int rightDirection = 0;
|
|
if (In.GetButtonDown(ButtonPinMapping.left2)) rightDirection -= 1;
|
|
if (In.GetButtonDown(ButtonPinMapping.right2)) rightDirection += 1;
|
|
|
|
//ÒÅÏÅÐÜ ÍÀÄÎ ÂÎÒ ÝÒÈ ÈÍÏÓÒÛ ÏÐÎÊÈÍÓÒÜ ÄÀËÜØÅ
|
|
textInput.SwitchLetter(leftDirection);
|
|
textInput.SwitchSlot(rightDirection);
|
|
}
|
|
}
|
|
|
|
public override Prize GetPrize() => PrizeUtils.CreatePrize(rank, textInput.GetText());
|
|
|
|
public override void Tick() { }
|
|
private void DisplayRank()
|
|
{
|
|
rankLabel.text = rank.ToString();
|
|
}
|
|
|
|
private void SwipeRank(int direction)
|
|
{
|
|
if(!CanSwipe) return;
|
|
|
|
int resultRank = rank + direction;
|
|
if (resultRank >= 1 && resultRank <= GameManager.instance.botsAmount)
|
|
{
|
|
rank = resultRank;
|
|
TryPlayClick();
|
|
DisplayRank();
|
|
LastSwipe = Time.time;
|
|
}
|
|
}
|
|
|
|
private void TryPlayClick()
|
|
{
|
|
if (clickClip != null)
|
|
SoundManager.instance.playClip(clickClip);
|
|
}
|
|
|
|
enum SelectedOption { Rank, Text }
|
|
}
|
|
}
|