140 lines
5.7 KiB
C#
140 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Abilities;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace UI
|
|
{
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject canvas;
|
|
[FormerlySerializedAs("hud")] [SerializeField] private InGameHUDController hudController;
|
|
[SerializeField] private GameObject chestPopUpControllerGO;
|
|
[SerializeField] private ChestPopUpController chestPopUpController;
|
|
[SerializeField] private GameObject diceGO;
|
|
[SerializeField] private DiceRoller diceRoller;
|
|
[SerializeField] private PassManager passManager;
|
|
[SerializeField] private StartingBlackDieAbility startingBlackDieAbility;
|
|
[SerializeField] private BlackDieAbility blackDieAbility;
|
|
[SerializeField] private ChestRewardSelection chestRewardSelection;
|
|
[SerializeField] private TorchAbility torchAbility;
|
|
[SerializeField] private ArmorAbility armorAbility;
|
|
[SerializeField] private Player player;
|
|
|
|
public static UIManager Instance { get; private set; }
|
|
|
|
private Dictionary<Die, Button> _dieToButtonMapping = new Dictionary<Die, Button>();
|
|
|
|
void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
chestPopUpController = chestPopUpControllerGO.GetComponent<ChestPopUpController>();
|
|
|
|
RoomRewards.ChestRewarded += HandleChestRewarded;
|
|
|
|
chestPopUpController.BlackDieSelected += chestRewardSelection.HandleBlackDiceSelected;
|
|
chestPopUpController.KeySelected += chestRewardSelection.HandleTorchSelected;
|
|
chestPopUpController.ArmorAndDiamondSelected += chestRewardSelection.HandleDiamondAndLifeSelected;
|
|
|
|
hudController.RollClicked += diceRoller.RollDice;
|
|
hudController.PassClicked += passManager.OnPassClicked;
|
|
|
|
diceRoller.Enabled += () => hudController.SetDiceRollerEnabled(true);
|
|
diceRoller.Disabled += () => hudController.SetDiceRollerEnabled(false);
|
|
|
|
startingBlackDieAbility.MarkUseUsedEvent += hudController.MarkStartingBlackDieAbilityUsed;
|
|
startingBlackDieAbility.UnmarkUseUsedEvent += hudController.UnmarkStartingBlackDieAbilityUsed;
|
|
hudController.StartingBlackDieAbilityClicked += startingBlackDieAbility.UseClicked;
|
|
|
|
blackDieAbility.MarkUseUsedEvent += hudController.MarkBlackDieAbilityUsed;
|
|
blackDieAbility.UnmarkUseUsedEvent += hudController.UnmarkStartingBlackDieAbilityUsed;
|
|
blackDieAbility.AbilityGained += hudController.SetBlackDieAbilityEnabled;
|
|
hudController.BlackDieAbilityClicked += blackDieAbility.UseClicked;
|
|
|
|
chestRewardSelection.ArmorAndDiamondNoLongerAvailable += chestPopUpController.DisableArmorAndDiamond;
|
|
chestRewardSelection.TorchNoLongerAvailable += chestPopUpController.DisableKey;
|
|
chestRewardSelection.BlackDieNoLongerAvailable += chestPopUpController.DisableBlackDie;
|
|
|
|
torchAbility.AbilityGained += hudController.SetKeyAbilityEnabled;
|
|
TorchAbility.TorchAbilityUsed += hudController.MarkKeyAbilityUsed;
|
|
hudController.KeyAbilityClicked += torchAbility.UseClicked;
|
|
|
|
player.DiamondCountUpdated += hudController.SetDiamondCount;
|
|
player.HealthUpdated += hudController.SetHealth;
|
|
|
|
armorAbility.ArmorAbilityGained += hudController.SetArmorAbilityEnabled;
|
|
armorAbility.MarkAbilityUsed += hudController.MarkArmorAbilityUsed;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
RoomRewards.ChestRewarded -= HandleChestRewarded;
|
|
|
|
chestPopUpController.BlackDieSelected -= BlackDieAbilityGained;
|
|
chestPopUpController.KeySelected -= TorchAbilityGained;
|
|
chestPopUpController.ArmorAndDiamondSelected -= HealthAndDiamondGained;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
int count = 0;
|
|
foreach (Transform dieTransform in diceGO.transform)
|
|
{
|
|
Die die = dieTransform.gameObject.GetComponent<Die>();
|
|
if (die.color == DiceColor.Black)
|
|
{
|
|
_dieToButtonMapping[die] = hudController.BlackDieButton;
|
|
}
|
|
else
|
|
{
|
|
_dieToButtonMapping[die] = hudController.WhiteDiceButtons[count];
|
|
count++;
|
|
}
|
|
}
|
|
|
|
foreach (var kvp in _dieToButtonMapping)
|
|
{
|
|
Button button = kvp.Value;
|
|
Die die = kvp.Key;
|
|
button.clicked += die.DiePressed;
|
|
die.DieRollResult += result => button.text = result.ToString();
|
|
die.DieSelectedButPairNotCompleteEvent += () => hudController.SetDieSelectedButNotComplete(button);
|
|
die.DieSelectedAndPairCompleteEvent += () => hudController.SetDieSelectedAndPairComplete(button);
|
|
die.DieReset += () => hudController.RestDie(button);
|
|
}
|
|
}
|
|
|
|
private void BlackDieAbilityGained()
|
|
{
|
|
hudController.SetBlackDieSelected(true);
|
|
}
|
|
|
|
private void TorchAbilityGained()
|
|
{
|
|
hudController.SetTorchSelected(true);
|
|
}
|
|
|
|
private void HealthAndDiamondGained()
|
|
{
|
|
hudController.SetHealthAndDiamondSelected(true);
|
|
}
|
|
|
|
private void HandleChestRewarded()
|
|
{
|
|
chestPopUpControllerGO.SetActive(true);
|
|
}
|
|
}
|
|
}
|