using CharacterSystem; using PrizeSystem; using System; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; //Это как шкала че есть в витрине чего нет. public class VitrinaView : MonoBehaviour { private static VitrinaView instance; public static VitrinaView Instance { get { if (instance == null) { instance = FindFirstObjectByType(FindObjectsInactive.Include); if (instance != null) instance.Deactivate(); } return instance; } } [SerializeField] private List Cells; [SerializeField] private Sprite AvailableCell; [SerializeField] private Sprite AvailableEmptyCell; [SerializeField] private Sprite NotAvailableCell; [SerializeField] private Color AvailableColor; [SerializeField] private Color AvailableEmptyColor; [SerializeField] private Color NotAvailableColor; public void ActivateIfNeed() { if (GameManager.Instance.gameMode == GameMode.pvp) { Deactivate(); return; } if (CharactersController.I.TryGetCurrentPrize(out VitrinaPrize vitrinaPrize)) { gameObject.SetActive(true); // Устанавливаем номера ячеек и базовое состояние for (int i = 0; i < Cells.Count; i++) { int boxNumber = i + 1; var text = Cells[i].GetComponentInChildren(); if (text != null) { text.text = boxNumber.ToString(); // Устанавливаем номер ячейки text.color = NotAvailableColor; } Cells[i].sprite = NotAvailableCell; Cells[i].color = Color.white; } SetPrizesAsync(vitrinaPrize); return; } Deactivate(); } public async void SetPrizesAsync(VitrinaPrize vitrinaPrize) { try { int[] readyBoxes = await PrizeStandController.GetReadyBoxesAsync(); int[] boxesToGive = vitrinaPrize?.Boxes ?? new int[0]; HashSet readyBoxesSet = new HashSet(readyBoxes); HashSet boxesToGiveSet = new HashSet(boxesToGive); // Проходим по всем ячейкам (индексы 0-based, номера ячеек 1-based) for (int i = 0; i < Cells.Count; i++) { int boxNumber = i + 1; var text = Cells[i].GetComponentInChildren(); // Убеждаемся, что номер ячейки всегда отображается if (text != null && string.IsNullOrEmpty(text.text)) { text.text = boxNumber.ToString(); } if (boxesToGiveSet.Contains(boxNumber)) { // Ячейка должна быть выдана, проверяем доступность if (readyBoxesSet.Contains(boxNumber)) { Cells[i].sprite = AvailableCell; if (text != null) text.color = AvailableColor; } else { Cells[i].sprite = AvailableEmptyCell; if (text != null) text.color = AvailableEmptyColor; } } else { // Ячейка не входит в список для выдачи Cells[i].sprite = NotAvailableCell; if (text != null) { text.color = NotAvailableColor; } Cells[i].color = NotAvailableColor; } } } catch (Exception ex) { Debug.LogError($"Ошибка при установке призов: {ex.Message}"); } } public void Deactivate() { gameObject.SetActive(false); } }