Danro/Assets/Scripts/UI/AdminStatsWindowUIController.cs
Danil Iarosh 009152ac5b
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Added ValueSelectorRow option to int settings
- Добавил новый тип отображения настроек с целочисленным значением
- У этого типа можно настраивать шаг, выглядит приятнее
2026-02-06 16:14:39 +03:00

101 lines
3.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()
{
base.Open();
UpdateText();
}
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();
}
}
}