94 lines
2.8 KiB
C#
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 CategoryDefinition _category;
|
|
private bool _isUsed;
|
|
|
|
public event Action<CategoryDefinition> OnCategorySelected;
|
|
|
|
public void Initialize(CategoryDefinition 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);
|
|
}
|
|
}
|
|
}
|