using System; using System.Collections.Generic; using UnityEngine; using TMPro; using YachtDice.Scoring; namespace YachtDice.UI { public class ScoreCardView : MonoBehaviour { [Header("Category Rows (in YachtCategory enum order)")] [SerializeField] private List categoryRows = new(); [Header("Summary")] [SerializeField] private TMP_Text upperSumText; [SerializeField] private TMP_Text upperBonusText; [SerializeField] private TMP_Text totalScoreText; public event Action OnCategorySelected; private static readonly string[] CategoryNames = { "Единицы", "Двойки", "Тройки", "Четвёрки", "Пятёрки", "Шестёрки", "Тройка", "Каре", "Фулл-хаус", "Малый стрит", "Большой стрит", "Яхта", "Шанс" }; private YachtCategory[] _allCategories; private void Awake() { _allCategories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory)); for (int i = 0; i < categoryRows.Count && i < _allCategories.Length; i++) { categoryRows[i].Initialize(_allCategories[i], CategoryNames[i]); categoryRows[i].OnCategorySelected += HandleCategorySelected; } UpdateTotalDisplay(0, 0, false); } public void UpdatePreviews(Dictionary previews) { for (int i = 0; i < categoryRows.Count && i < _allCategories.Length; i++) { if (previews.TryGetValue(_allCategories[i], out int preview)) { categoryRows[i].ShowPreview(preview); categoryRows[i].SetInteractable(true); } } } public void ClearAllPreviews() { for (int i = 0; i < categoryRows.Count; i++) { categoryRows[i].HidePreview(); categoryRows[i].SetInteractable(false); } } public void SetCategoryScored(YachtCategory category, int score) { int index = (int)category; if (index >= 0 && index < categoryRows.Count) categoryRows[index].SetRecordedScore(score); } public void SetAllInteractable(bool interactable) { for (int i = 0; i < categoryRows.Count; i++) categoryRows[i].SetInteractable(interactable); } public void UpdateTotalDisplay(int totalScore, int upperSum, bool hasUpperBonus) { totalScoreText.text = totalScore.ToString(); upperSumText.text = $"{upperSum} / 63"; upperBonusText.text = hasUpperBonus ? "+35" : "---"; } public void ResetAll() { for (int i = 0; i < categoryRows.Count; i++) categoryRows[i].ResetRow(); UpdateTotalDisplay(0, 0, false); } private void HandleCategorySelected(YachtCategory category) { OnCategorySelected?.Invoke(category); } private void OnDestroy() { for (int i = 0; i < categoryRows.Count; i++) categoryRows[i].OnCategorySelected -= HandleCategorySelected; } } }