d06ad78645
View layer: CategoryRowView (reusable x13 row with preview/recorded score display), ScoreCardView (full scorecard panel with Russian category names, upper bonus tracking), DicePanelView (5 dice buttons with lock toggle + roll counter), GameInfoView (turn display + game over overlay). Controller layer: GameController bridges Model and View — subscribes to model events in Awake() to catch GameManager.Start(), routes UI clicks to game logic, computes preview scores for all unfilled categories after each roll, handles upper section bonus (63+ = +35). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
102 lines
2.9 KiB
C#
102 lines
2.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public sealed class DicePanelView : MonoBehaviour
|
|
{
|
|
[Header("Dice Display")]
|
|
[SerializeField] private Button[] diceButtons = new Button[5];
|
|
[SerializeField] private TMP_Text[] diceValueTexts = new TMP_Text[5];
|
|
[SerializeField] private Image[] diceBackgrounds = new Image[5];
|
|
|
|
[Header("Roll")]
|
|
[SerializeField] private Button rollButton;
|
|
[SerializeField] private TMP_Text rollButtonText;
|
|
|
|
[Header("Colors")]
|
|
[SerializeField] private Color unlockedColor = Color.white;
|
|
[SerializeField] private Color lockedColor = new Color(1f, 0.85f, 0.4f, 1f);
|
|
|
|
public event Action<int> OnDiceToggled;
|
|
public event Action OnRollClicked;
|
|
|
|
private void Awake()
|
|
{
|
|
for (int i = 0; i < diceButtons.Length; i++)
|
|
{
|
|
int capturedIndex = i;
|
|
diceButtons[i].onClick.AddListener(() => OnDiceToggled?.Invoke(capturedIndex));
|
|
}
|
|
|
|
rollButton.onClick.AddListener(() => OnRollClicked?.Invoke());
|
|
|
|
for (int i = 0; i < diceValueTexts.Length; i++)
|
|
{
|
|
diceValueTexts[i].text = "?";
|
|
diceBackgrounds[i].color = unlockedColor;
|
|
diceButtons[i].interactable = false;
|
|
}
|
|
|
|
SetRollButtonState(true, 0, 3);
|
|
}
|
|
|
|
public void SetDieValue(int index, int value)
|
|
{
|
|
if (index >= 0 && index < diceValueTexts.Length)
|
|
diceValueTexts[index].text = value.ToString();
|
|
}
|
|
|
|
public void SetAllDiceValues(int[] values)
|
|
{
|
|
for (int i = 0; i < values.Length && i < diceValueTexts.Length; i++)
|
|
diceValueTexts[i].text = values[i].ToString();
|
|
}
|
|
|
|
public void SetDieLocked(int index, bool isLocked)
|
|
{
|
|
if (index >= 0 && index < diceBackgrounds.Length)
|
|
diceBackgrounds[index].color = isLocked ? lockedColor : unlockedColor;
|
|
}
|
|
|
|
public void SetDiceInteractable(bool interactable)
|
|
{
|
|
for (int i = 0; i < diceButtons.Length; i++)
|
|
diceButtons[i].interactable = interactable;
|
|
}
|
|
|
|
public void SetRollButtonState(bool interactable, int currentRoll, int maxRolls)
|
|
{
|
|
rollButton.interactable = interactable;
|
|
|
|
if (currentRoll >= maxRolls)
|
|
rollButtonText.text = "Выберите категорию";
|
|
else
|
|
rollButtonText.text = $"Бросок {currentRoll + 1}/{maxRolls}";
|
|
}
|
|
|
|
public void ResetForNewTurn()
|
|
{
|
|
for (int i = 0; i < diceValueTexts.Length; i++)
|
|
{
|
|
diceValueTexts[i].text = "?";
|
|
diceBackgrounds[i].color = unlockedColor;
|
|
diceButtons[i].interactable = false;
|
|
}
|
|
}
|
|
|
|
public void ResetForNewGame()
|
|
{
|
|
ResetForNewTurn();
|
|
SetRollButtonState(true, 0, 3);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
for (int i = 0; i < diceButtons.Length; i++)
|
|
diceButtons[i].onClick.RemoveAllListeners();
|
|
|
|
rollButton.onClick.RemoveAllListeners();
|
|
}
|
|
}
|