[Add] Dice Panel
This commit is contained in:
@@ -7,10 +7,15 @@ namespace YachtDice.UI
|
||||
{
|
||||
public class DicePanelView : MonoBehaviour
|
||||
{
|
||||
[Serializable] public struct DiceValue
|
||||
{
|
||||
public Button diceButton;
|
||||
public TextMeshProUGUI diceValueText;
|
||||
public Image diceBackground;
|
||||
}
|
||||
|
||||
[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];
|
||||
[SerializeField] private DiceValue[] diceValues = new DiceValue[5];
|
||||
|
||||
[Header("Roll")]
|
||||
[SerializeField] private Button rollButton;
|
||||
@@ -25,19 +30,19 @@ namespace YachtDice.UI
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
for (int i = 0; i < diceButtons.Length; i++)
|
||||
for (int i = 0; i < diceValues.Length; i++)
|
||||
{
|
||||
int capturedIndex = i;
|
||||
diceButtons[i].onClick.AddListener(() => OnDiceToggled?.Invoke(capturedIndex));
|
||||
diceValues[i].diceButton.onClick.AddListener(() => OnDiceToggled?.Invoke(capturedIndex));
|
||||
}
|
||||
|
||||
rollButton.onClick.AddListener(() => OnRollClicked?.Invoke());
|
||||
|
||||
for (int i = 0; i < diceValueTexts.Length; i++)
|
||||
for (int i = 0; i < diceValues.Length; i++)
|
||||
{
|
||||
diceValueTexts[i].text = "?";
|
||||
diceBackgrounds[i].color = unlockedColor;
|
||||
diceButtons[i].interactable = false;
|
||||
diceValues[i].diceValueText.text = "?";
|
||||
diceValues[i]. diceBackground.color = unlockedColor;
|
||||
diceValues[i].diceButton.interactable = false;
|
||||
}
|
||||
|
||||
SetRollButtonState(true, 0, 3);
|
||||
@@ -45,26 +50,26 @@ namespace YachtDice.UI
|
||||
|
||||
public void SetDiceValue(int index, int value)
|
||||
{
|
||||
if (index >= 0 && index < diceValueTexts.Length)
|
||||
diceValueTexts[index].text = value.ToString();
|
||||
if (index >= 0 && index < diceValues.Length)
|
||||
diceValues[index].diceValueText.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();
|
||||
for (int i = 0; i < values.Length && i < diceValues.Length; i++)
|
||||
diceValues[i].diceValueText.text = values[i].ToString();
|
||||
}
|
||||
|
||||
public void SetDiceLocked(int index, bool isLocked)
|
||||
{
|
||||
if (index >= 0 && index < diceBackgrounds.Length)
|
||||
diceBackgrounds[index].color = isLocked ? lockedColor : unlockedColor;
|
||||
if (index >= 0 && index < diceValues.Length)
|
||||
diceValues[index].diceBackground.color = isLocked ? lockedColor : unlockedColor;
|
||||
}
|
||||
|
||||
public void SetDiceInteractable(bool interactable)
|
||||
{
|
||||
for (int i = 0; i < diceButtons.Length; i++)
|
||||
diceButtons[i].interactable = interactable;
|
||||
for (int i = 0; i < diceValues.Length; i++)
|
||||
diceValues[i].diceButton.interactable = interactable;
|
||||
}
|
||||
|
||||
public void SetRollButtonState(bool interactable, int currentRoll, int maxRolls)
|
||||
@@ -79,11 +84,11 @@ namespace YachtDice.UI
|
||||
|
||||
public void ResetForNewTurn()
|
||||
{
|
||||
for (int i = 0; i < diceValueTexts.Length; i++)
|
||||
for (int i = 0; i < diceValues.Length; i++)
|
||||
{
|
||||
diceValueTexts[i].text = "?";
|
||||
diceBackgrounds[i].color = unlockedColor;
|
||||
diceButtons[i].interactable = false;
|
||||
diceValues[i].diceValueText.text = "?";
|
||||
diceValues[i].diceBackground.color = unlockedColor;
|
||||
diceValues[i].diceButton.interactable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,9 +100,9 @@ namespace YachtDice.UI
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
for (var index = 0; index < diceButtons.Length; index++)
|
||||
for (var i = 0; i < diceValues.Length; i++)
|
||||
{
|
||||
var t = diceButtons[index];
|
||||
var t = diceValues[i].diceButton;
|
||||
t.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user