90 lines
2.1 KiB
C#
90 lines
2.1 KiB
C#
using PrizeSystem;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SpecialPrizeToggler : MonoBehaviour
|
|
{
|
|
Coroutine coroutine;
|
|
[SerializeField] List<Graphic> graphics;
|
|
|
|
[SerializeField] Color enabledColor;
|
|
[SerializeField] Color disabledColor;
|
|
|
|
[SerializeField] private TextMeshProUGUI PrizeText;
|
|
|
|
private void OnEnable()
|
|
{
|
|
SettingsManager.OnSettingsChanged.AddListener(Refresh);
|
|
PrizeSystemManager.PrizesChanged += Refresh;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
SettingsManager.OnSettingsChanged.RemoveListener(Refresh);
|
|
PrizeSystemManager.PrizesChanged -= Refresh;
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
Refresh(PrizeSystemManager.cachedPrizes);
|
|
}
|
|
private void Refresh(List<Prize> prizes)
|
|
{
|
|
var qrPrizes = CollectQrPrizes(prizes);
|
|
|
|
if (NeedToDisplay(qrPrizes))
|
|
{
|
|
PrizeText.text = GetMostRankedPrize(qrPrizes).PrizeText;
|
|
SetColorToGraphics(enabledColor);
|
|
|
|
}
|
|
else
|
|
{
|
|
SetColorToGraphics(disabledColor);
|
|
}
|
|
}
|
|
|
|
List<QrPrize> CollectQrPrizes(List<Prize> prizes)
|
|
{
|
|
List<QrPrize> qrPrizes = new();
|
|
foreach (Prize prize in prizes)
|
|
if (prize is QrPrize qr)
|
|
qrPrizes.Add(qr);
|
|
return qrPrizes;
|
|
}
|
|
private bool NeedToDisplay(List<QrPrize> qrPrizes)
|
|
{
|
|
if(!SettingsManager.GetBool("Prizing", false)) return false;
|
|
if(qrPrizes.Count == 0) return false;
|
|
|
|
return true;
|
|
}
|
|
private void SetColorToGraphics(Color color)
|
|
{
|
|
foreach(var g in graphics)
|
|
g.color = color;
|
|
}
|
|
|
|
public QrPrize GetMostRankedPrize(List<QrPrize> qrPrizes)
|
|
{
|
|
if (qrPrizes == null || qrPrizes.Count == 0)
|
|
return null;
|
|
|
|
QrPrize maxPrize = qrPrizes[0];
|
|
|
|
for (int i = 1; i < qrPrizes.Count; i++)
|
|
{
|
|
if (qrPrizes[i].Rank >= maxPrize.Rank)
|
|
{
|
|
maxPrize = qrPrizes[i];
|
|
}
|
|
}
|
|
|
|
return maxPrize;
|
|
}
|
|
|
|
}
|