Files
YachtDice/Assets/Scripts/UI/CategoryRowView.cs
T
horooko 0f9b162061 [Refactor] Replace hardcoded categories with data-driven SO system and abstract dice
- Add abstract dice system (IDie interface, DieDefinitionSO, StandardDieSO, DieInstance)
  to support future custom dice types while keeping backward compat via int[] DiceValues
- Replace YachtCategory enum and CategoryScorer switch with CategoryDefinitionSO hierarchy:
  SumOfValueCategorySO, NOfAKindCategorySO, FullHouseCategorySO, StraightCategorySO, SumAllCategorySO
- Add CategoryCatalogSO for ordered category collections and DiceCheckUtility for shared logic
- Refactor ScoringSystem, Views, GameManager, GameController to use SO references
- Update CategoryCondition modifier to use SO reference instead of enum
- Update all editor tests to use SO-based categories and DieInstance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 11:46:50 +07:00

94 lines
2.8 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using YachtDice.Categories;
namespace YachtDice.UI
{
public class CategoryRowView : MonoBehaviour
{
[Header("UI Elements")]
[SerializeField] private TMP_Text categoryNameText;
[SerializeField] private TMP_Text previewText;
[SerializeField] private TMP_Text recordedScoreText;
[SerializeField] private Button selectButton;
[SerializeField] private Image background;
[Header("Colors")]
[SerializeField] private Color normalColor = new Color(0.95f, 0.95f, 0.95f, 1f);
[SerializeField] private Color usedColor = new Color(0.75f, 0.75f, 0.75f, 1f);
[SerializeField] private Color previewPositiveColor = new Color(0.85f, 1f, 0.85f, 1f);
[SerializeField] private Color previewZeroColor = new Color(1f, 0.88f, 0.88f, 1f);
private CategoryDefinitionSO category;
private bool isUsed;
public event Action<CategoryDefinitionSO> OnCategorySelected;
public void Initialize(CategoryDefinitionSO categoryDef)
{
category = categoryDef;
isUsed = false;
categoryNameText.text = categoryDef.DisplayName;
previewText.text = "";
recordedScoreText.text = "-";
selectButton.onClick.AddListener(HandleClick);
SetInteractable(false);
background.color = normalColor;
}
public void ShowPreview(int previewScore)
{
if (isUsed) return;
previewText.text = previewScore.ToString();
background.color = previewScore > 0 ? previewPositiveColor : previewZeroColor;
}
public void HidePreview()
{
if (isUsed) return;
previewText.text = "";
background.color = normalColor;
}
public void SetRecordedScore(int score)
{
isUsed = true;
recordedScoreText.text = score.ToString();
previewText.text = "";
SetInteractable(false);
background.color = usedColor;
}
public void SetInteractable(bool interactable)
{
if (isUsed)
{
selectButton.interactable = false;
return;
}
selectButton.interactable = interactable;
}
public void ResetRow()
{
isUsed = false;
previewText.text = "";
recordedScoreText.text = "-";
SetInteractable(false);
background.color = normalColor;
}
private void HandleClick()
{
OnCategorySelected?.Invoke(category);
}
private void OnDestroy()
{
selectButton.onClick.RemoveListener(HandleClick);
}
}
}