Finished converting to new UI.
This commit is contained in:
parent
f70f89324b
commit
105055b307
37 changed files with 24044 additions and 1227 deletions
132
PuzzleGameProject/Assets/Scripts/UI/UIManager.cs
Normal file
132
PuzzleGameProject/Assets/Scripts/UI/UIManager.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue