[Fix] Code visual
This commit is contained in:
@@ -5,101 +5,100 @@ 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()
|
||||
public class DicePanelView : MonoBehaviour
|
||||
{
|
||||
for (int i = 0; i < diceButtons.Length; i++)
|
||||
[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()
|
||||
{
|
||||
int capturedIndex = i;
|
||||
diceButtons[i].onClick.AddListener(() => OnDiceToggled?.Invoke(capturedIndex));
|
||||
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);
|
||||
}
|
||||
|
||||
rollButton.onClick.AddListener(() => OnRollClicked?.Invoke());
|
||||
|
||||
for (int i = 0; i < diceValueTexts.Length; i++)
|
||||
public void SetDieValue(int index, int value)
|
||||
{
|
||||
diceValueTexts[i].text = "?";
|
||||
diceBackgrounds[i].color = unlockedColor;
|
||||
diceButtons[i].interactable = false;
|
||||
if (index >= 0 && index < diceValueTexts.Length)
|
||||
diceValueTexts[index].text = value.ToString();
|
||||
}
|
||||
|
||||
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++)
|
||||
public void SetAllDiceValues(int[] values)
|
||||
{
|
||||
diceValueTexts[i].text = "?";
|
||||
diceBackgrounds[i].color = unlockedColor;
|
||||
diceButtons[i].interactable = false;
|
||||
for (int i = 0; i < values.Length && i < diceValueTexts.Length; i++)
|
||||
diceValueTexts[i].text = values[i].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetForNewGame()
|
||||
{
|
||||
ResetForNewTurn();
|
||||
SetRollButtonState(true, 0, 3);
|
||||
}
|
||||
public void SetDieLocked(int index, bool isLocked)
|
||||
{
|
||||
if (index >= 0 && index < diceBackgrounds.Length)
|
||||
diceBackgrounds[index].color = isLocked ? lockedColor : unlockedColor;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
for (int i = 0; i < diceButtons.Length; i++)
|
||||
diceButtons[i].onClick.RemoveAllListeners();
|
||||
public void SetDiceInteractable(bool interactable)
|
||||
{
|
||||
for (int i = 0; i < diceButtons.Length; i++)
|
||||
diceButtons[i].interactable = interactable;
|
||||
}
|
||||
|
||||
rollButton.onClick.RemoveAllListeners();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user