[Fix] Code visual
This commit is contained in:
@@ -6,109 +6,108 @@ using YachtDice.Scoring;
|
||||
|
||||
namespace YachtDice.UI
|
||||
{
|
||||
|
||||
public sealed class ScoreCardView : MonoBehaviour
|
||||
{
|
||||
[Header("Category Rows (in YachtCategory enum order)")]
|
||||
[SerializeField] private List<CategoryRowView> categoryRows = new();
|
||||
|
||||
[Header("Summary")]
|
||||
[SerializeField] private TMP_Text upperSumText;
|
||||
[SerializeField] private TMP_Text upperBonusText;
|
||||
[SerializeField] private TMP_Text totalScoreText;
|
||||
|
||||
public event Action<YachtCategory> OnCategorySelected;
|
||||
|
||||
private static readonly string[] CategoryNames =
|
||||
public class ScoreCardView : MonoBehaviour
|
||||
{
|
||||
"Единицы",
|
||||
"Двойки",
|
||||
"Тройки",
|
||||
"Четвёрки",
|
||||
"Пятёрки",
|
||||
"Шестёрки",
|
||||
"Тройка",
|
||||
"Каре",
|
||||
"Фулл-хаус",
|
||||
"Малый стрит",
|
||||
"Большой стрит",
|
||||
"Яхта",
|
||||
"Шанс"
|
||||
};
|
||||
[Header("Category Rows (in YachtCategory enum order)")]
|
||||
[SerializeField] private List<CategoryRowView> categoryRows = new();
|
||||
|
||||
private YachtCategory[] allCategories;
|
||||
[Header("Summary")]
|
||||
[SerializeField] private TMP_Text upperSumText;
|
||||
[SerializeField] private TMP_Text upperBonusText;
|
||||
[SerializeField] private TMP_Text totalScoreText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
allCategories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
|
||||
public event Action<YachtCategory> OnCategorySelected;
|
||||
|
||||
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
|
||||
private static readonly string[] CategoryNames =
|
||||
{
|
||||
categoryRows[i].Initialize(allCategories[i], CategoryNames[i]);
|
||||
categoryRows[i].OnCategorySelected += HandleCategorySelected;
|
||||
"Единицы",
|
||||
"Двойки",
|
||||
"Тройки",
|
||||
"Четвёрки",
|
||||
"Пятёрки",
|
||||
"Шестёрки",
|
||||
"Тройка",
|
||||
"Каре",
|
||||
"Фулл-хаус",
|
||||
"Малый стрит",
|
||||
"Большой стрит",
|
||||
"Яхта",
|
||||
"Шанс"
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
UpdateTotalDisplay(0, 0, false);
|
||||
}
|
||||
|
||||
public void UpdatePreviews(Dictionary<YachtCategory, int> previews)
|
||||
{
|
||||
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
|
||||
public void UpdatePreviews(Dictionary<YachtCategory, int> previews)
|
||||
{
|
||||
if (previews.TryGetValue(allCategories[i], out int preview))
|
||||
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
|
||||
{
|
||||
categoryRows[i].ShowPreview(preview);
|
||||
categoryRows[i].SetInteractable(true);
|
||||
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++)
|
||||
public void ClearAllPreviews()
|
||||
{
|
||||
categoryRows[i].HidePreview();
|
||||
categoryRows[i].SetInteractable(false);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user