265 lines
7.8 KiB
C#
265 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace UI
|
|
{
|
|
enum DieState
|
|
{
|
|
Normal,
|
|
OnlyDieSelected,
|
|
SelectedOfPair,
|
|
Used
|
|
|
|
}
|
|
|
|
public class InGameHUDController : MonoBehaviour
|
|
{
|
|
private const string PASS_TEXT = "Pass";
|
|
private const string ROLL_TEXT = "Roll";
|
|
|
|
public event Action StartingBlackDieAbilityClicked;
|
|
public event Action BlackDieAbilityClicked;
|
|
public event Action KeyAbilityClicked;
|
|
|
|
public event Action RollClicked;
|
|
public event Action PassClicked;
|
|
|
|
public List<Button> WhiteDiceButtons = new List<Button>();
|
|
public Button BlackDieButton;
|
|
|
|
private Toggle _healthDiamondSelected;
|
|
private Toggle _torchSelected;
|
|
private Toggle _blackDieSelected;
|
|
private Button _rollOrPassButton;
|
|
private bool _rollMode = true;
|
|
|
|
private List<Toggle> _startingBlackDieAbilityUses = new List<Toggle>();
|
|
private int _startingBlackDieAbilityUsesUsed = 0;
|
|
|
|
private List<Toggle> _blackDieAbilityUses = new List<Toggle>();
|
|
private int _blackDieAbilityUsesUsed = 0;
|
|
|
|
private List<Toggle> _keyAbilityUses = new List<Toggle>();
|
|
private int _keyAbilityUsesUsed = 0;
|
|
|
|
private List<Toggle> _armorUses = new List<Toggle>();
|
|
private int _armorUsesUsed = 0;
|
|
|
|
|
|
public void OnEnable()
|
|
{
|
|
VisualElement root = GetComponent<UIDocument>().rootVisualElement;
|
|
|
|
GroupBox healthAndDiamondGroupBox = root.Q<GroupBox>("HeartAndDiamondUses");
|
|
GroupBox keyGroupBox = root.Q<GroupBox>("KeyUses");
|
|
GroupBox blackDieGroupBox = root.Q<GroupBox>("BlackDieUses");
|
|
GroupBox startingBlackDieGroupBox = root.Q<GroupBox>("StartingBlackDieUses");
|
|
startingBlackDieGroupBox.AddManipulator(new Clickable(evt => HandleStartingBlackDieAbilityClicked()));
|
|
GroupBox diceGroupBox = root.Q<GroupBox>("Dice");
|
|
|
|
foreach (Button diceButton in diceGroupBox.Children())
|
|
{
|
|
if (diceButton.name == "BlackDie")
|
|
{
|
|
BlackDieButton = diceButton;
|
|
}
|
|
else
|
|
{
|
|
WhiteDiceButtons.Add(diceButton);
|
|
}
|
|
}
|
|
|
|
foreach (Toggle use in startingBlackDieGroupBox.Children())
|
|
{
|
|
use.RegisterCallback<ClickEvent>(evt =>
|
|
{
|
|
use.value = !use.value; // User clicking check does not check or uncheck toggle.
|
|
HandleStartingBlackDieAbilityClicked();
|
|
});
|
|
_startingBlackDieAbilityUses.Add(use);
|
|
}
|
|
|
|
foreach (Toggle use in blackDieGroupBox.Children())
|
|
{
|
|
_blackDieAbilityUses.Add(use);
|
|
use.RegisterCallback<ClickEvent>(evt =>
|
|
{
|
|
use.value = !use.value; // User clicking check does not check or uncheck toggle.
|
|
BlackDieAbilityClicked?.Invoke();
|
|
});
|
|
}
|
|
|
|
foreach (Toggle use in keyGroupBox.Children())
|
|
{
|
|
_keyAbilityUses.Add(use);
|
|
use.RegisterCallback<ClickEvent>(evt =>
|
|
{
|
|
use.value = !use.value; // User clicking check does not check or uncheck toggle.
|
|
KeyAbilityClicked?.Invoke();
|
|
});
|
|
}
|
|
|
|
foreach (Toggle use in healthAndDiamondGroupBox.Children())
|
|
{
|
|
_armorUses.Add(use);
|
|
use.RegisterCallback<ClickEvent>(evt =>
|
|
{
|
|
use.value = !use.value; // User clicking check does not check or uncheck toggle.
|
|
});
|
|
}
|
|
|
|
_rollOrPassButton = root.Q<Button>("RollPass");
|
|
_rollOrPassButton.clicked += HandleRollOrPassClicked;
|
|
}
|
|
|
|
public void SetBlackDieAbilityEnabled()
|
|
{
|
|
foreach (Toggle use in _blackDieAbilityUses)
|
|
{
|
|
use.SetEnabled(true);
|
|
}
|
|
}
|
|
|
|
public void SetKeyAbilityEnabled()
|
|
{
|
|
foreach (Toggle use in _keyAbilityUses)
|
|
{
|
|
use.SetEnabled(true);
|
|
}
|
|
}
|
|
|
|
public void SetArmorAbilityEnabled()
|
|
{
|
|
foreach (Toggle use in _armorUses)
|
|
{
|
|
use.SetEnabled(true);
|
|
}
|
|
}
|
|
|
|
public void MarkKeyAbilityUsed()
|
|
{
|
|
_keyAbilityUses[_keyAbilityUsesUsed].value = true;
|
|
_keyAbilityUsesUsed++;
|
|
}
|
|
|
|
public void MarkBlackDieAbilityUsed()
|
|
{
|
|
_blackDieAbilityUses[_blackDieAbilityUsesUsed].value = true;
|
|
_blackDieAbilityUsesUsed++;
|
|
}
|
|
|
|
public void UnmarkBlackDieAbilityUsed()
|
|
{
|
|
_blackDieAbilityUses[_blackDieAbilityUsesUsed].value = false;
|
|
_blackDieAbilityUsesUsed--;
|
|
}
|
|
|
|
public void MarkStartingBlackDieAbilityUsed()
|
|
{
|
|
_startingBlackDieAbilityUses[_startingBlackDieAbilityUsesUsed].value = true;
|
|
_startingBlackDieAbilityUsesUsed++;
|
|
}
|
|
|
|
public void UnmarkStartingBlackDieAbilityUsed()
|
|
{
|
|
_startingBlackDieAbilityUses[_startingBlackDieAbilityUsesUsed].value = false;
|
|
_startingBlackDieAbilityUsesUsed--;
|
|
}
|
|
|
|
public void SwitchToDiceRoller()
|
|
{
|
|
_rollMode = true;
|
|
_rollOrPassButton.text = ROLL_TEXT;
|
|
}
|
|
|
|
public void SwitchToPass()
|
|
{
|
|
_rollMode = false;
|
|
_rollOrPassButton.text = PASS_TEXT;
|
|
}
|
|
|
|
public void SetDiceRollerEnabled(bool enabled)
|
|
{
|
|
if (enabled)
|
|
{
|
|
SwitchToDiceRoller();
|
|
}
|
|
else
|
|
{
|
|
SwitchToPass();
|
|
}
|
|
}
|
|
|
|
public void SetDieSelectedButNotComplete(Button button)
|
|
{
|
|
SetDiceButtonState(DieState.OnlyDieSelected, button);
|
|
}
|
|
|
|
public void SetDieSelectedAndPairComplete(Button button)
|
|
{
|
|
SetDiceButtonState(DieState.SelectedOfPair, button);
|
|
}
|
|
|
|
public void RestDie(Button button)
|
|
{
|
|
SetDiceButtonState(DieState.Normal, button);
|
|
}
|
|
|
|
public void SetHealthAndDiamondSelected(bool state)
|
|
{
|
|
_healthDiamondSelected.value = state;
|
|
}
|
|
|
|
public void SetTorchSelected(bool state)
|
|
{
|
|
_torchSelected.value = state;
|
|
}
|
|
|
|
public void SetBlackDieSelected(bool state)
|
|
{
|
|
_blackDieSelected.value = state;
|
|
}
|
|
|
|
private void HandleRollOrPassClicked()
|
|
{
|
|
if (_rollMode)
|
|
{
|
|
SwitchToPass();
|
|
RollClicked?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
SwitchToDiceRoller();
|
|
PassClicked?.Invoke();
|
|
}
|
|
}
|
|
|
|
private void HandleStartingBlackDieAbilityClicked()
|
|
{
|
|
StartingBlackDieAbilityClicked?.Invoke();
|
|
}
|
|
|
|
private void SetDiceButtonState(DieState state, Button die)
|
|
{
|
|
die.RemoveFromClassList("selected-of-pair");
|
|
die.RemoveFromClassList("selected");
|
|
die.SetEnabled(true);
|
|
|
|
switch (state)
|
|
{
|
|
case DieState.Used:
|
|
die.SetEnabled(false);
|
|
break;
|
|
case DieState.OnlyDieSelected:
|
|
die.AddToClassList("selected");
|
|
break;
|
|
case DieState.SelectedOfPair:
|
|
die.AddToClassList("selected-of-pair");
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|