101 lines
3.9 KiB
C#
101 lines
3.9 KiB
C#
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using RR.Common.Controls;
|
||
|
||
namespace RR.Common.UI
|
||
{
|
||
/// <summary>
|
||
/// Модальное окно статистики администратора.
|
||
/// Отображает статистику игр и призов с возможностью сброса.
|
||
/// </summary>
|
||
public class AdminStatsWindowUIController : Modal
|
||
{
|
||
[Header("Тексты статистики")]
|
||
[SerializeField] private string gamesPlayedTextPrefix = "Игр сыграно: ";
|
||
[SerializeField] private TextMeshProUGUI gamesPlayedText;
|
||
[SerializeField] private string gamesPlayedNulTextPrefix = "Игр сыграно (обнуляемый): ";
|
||
[SerializeField] private TextMeshProUGUI gamesPlayedNulText;
|
||
[SerializeField] private string prizesGivenTextPrefix = "Призов выдано: ";
|
||
[SerializeField] private TextMeshProUGUI prizesGivenText;
|
||
[SerializeField] private string prizesGivenNulTextPrefix = "Призов выдано (обнуляемый): ";
|
||
[SerializeField] private TextMeshProUGUI prizesGivenNulText;
|
||
|
||
[Header("Кнопки")]
|
||
[SerializeField] private Button resetGamesPlayedNulButton;
|
||
[SerializeField] private Button resetPrizesGivenNulButton;
|
||
|
||
private string _gamesPlayedKey;
|
||
private string _gamesPlayedNulKey;
|
||
private string _prizesGivenKey;
|
||
private string _prizesGivenNulKey;
|
||
|
||
protected override void Awake()
|
||
{
|
||
base.Awake();
|
||
|
||
_gamesPlayedKey = PrizeSystem.key_starts;
|
||
_gamesPlayedNulKey = PrizeSystem.key_startsNul;
|
||
_prizesGivenKey = PrizeSystem.key_prizesgiven;
|
||
_prizesGivenNulKey = PrizeSystem.key_prizesgivenNul;
|
||
|
||
if (resetGamesPlayedNulButton)
|
||
resetGamesPlayedNulButton.onClick.AddListener(() => ResetPlayerPrefsStat(_gamesPlayedNulKey));
|
||
|
||
if (resetPrizesGivenNulButton)
|
||
resetPrizesGivenNulButton.onClick.AddListener(() => ResetPlayerPrefsStat(_prizesGivenNulKey));
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
if (resetGamesPlayedNulButton)
|
||
resetGamesPlayedNulButton.onClick.RemoveListener(() => ResetPlayerPrefsStat(_gamesPlayedNulKey));
|
||
|
||
if (resetPrizesGivenNulButton)
|
||
resetPrizesGivenNulButton.onClick.RemoveListener(() => ResetPlayerPrefsStat(_prizesGivenNulKey));
|
||
}
|
||
|
||
/// <summary>
|
||
/// Переопределяем Open для обновления текста при открытии.
|
||
/// </summary>
|
||
public override void Open()
|
||
{
|
||
UpdateText();
|
||
base.Open();
|
||
}
|
||
|
||
private void UpdateText()
|
||
{
|
||
if (gamesPlayedText)
|
||
{
|
||
int gamesPlayed = PlayerPrefs.GetInt(_gamesPlayedKey, 0);
|
||
gamesPlayedText.text = gamesPlayedTextPrefix + gamesPlayed;
|
||
}
|
||
|
||
if (gamesPlayedNulText)
|
||
{
|
||
int gamesPlayedNul = PlayerPrefs.GetInt(_gamesPlayedNulKey, 0);
|
||
gamesPlayedNulText.text = gamesPlayedNulTextPrefix + gamesPlayedNul;
|
||
}
|
||
|
||
if (prizesGivenText)
|
||
{
|
||
int prizesGiven = PlayerPrefs.GetInt(_prizesGivenKey, 0);
|
||
prizesGivenText.text = prizesGivenTextPrefix + prizesGiven;
|
||
}
|
||
|
||
if (prizesGivenNulText)
|
||
{
|
||
int prizesGivenNul = PlayerPrefs.GetInt(_prizesGivenNulKey, 0);
|
||
prizesGivenNulText.text = prizesGivenNulTextPrefix + prizesGivenNul;
|
||
}
|
||
}
|
||
|
||
private void ResetPlayerPrefsStat(string key)
|
||
{
|
||
PlayerPrefs.SetInt(key, 0);
|
||
UpdateText();
|
||
}
|
||
}
|
||
}
|