Files
YachtDice/Assets/Scripts/UI/DicePanelView.cs
T
horooko bee20fd1f8 [Refactor] Add folder-based namespaces to all C# scripts
Wrap all 39 scripts and 6 test files in namespaces matching their folder
structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace
using directives where types are referenced across modules. Set rootNamespace
in both .asmdef files (YachtDice, YachtDice.Tests).

Namespace mapping:
- YachtDice.Dice — Dice, DiceRoller
- YachtDice.Economy — CurrencyBank
- YachtDice.Game — GameManager, DiceManager, DebugGameInput
- YachtDice.Inventory — InventoryController/Model/SlotView/View
- YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target
- YachtDice.Persistence — SaveData, SaveSystem
- YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory
- YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View
- YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView
- YachtDice.Editor — ModifierAssetCreator
- YachtDice.Tests — all test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:06:57 +07:00

106 lines
3.0 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace YachtDice.UI
{
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();
}
}
}