Finished converting to new UI.
This commit is contained in:
parent
f70f89324b
commit
105055b307
37 changed files with 24044 additions and 1227 deletions
|
|
@ -1,9 +1,11 @@
|
|||
using System;
|
||||
using Abilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BlackDieAbility: StartingBlackDieAbility
|
||||
{
|
||||
public event Action AbilityGained;
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
|
@ -18,8 +20,6 @@ public class BlackDieAbility: StartingBlackDieAbility
|
|||
|
||||
private void HandleBlackDieAbilityGained()
|
||||
{
|
||||
abilityUseOne.GetComponent<Button>().interactable = true;
|
||||
abilityUseTwo.GetComponent<Button>().interactable = true;
|
||||
abilityUseThree.GetComponent<Button>().interactable = true;
|
||||
AbilityGained?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,41 +7,39 @@ public class ChestRewardSelection : MonoBehaviour
|
|||
public static event Action DiamondAndLifeSelected;
|
||||
public static event Action TorchAbilitySelected;
|
||||
public static event Action BlackDiceAbilitySelected;
|
||||
|
||||
[SerializeField] private Button diamondAndLifeButton;
|
||||
[SerializeField] private Button torchButton;
|
||||
[SerializeField] private Button blackDiceButton;
|
||||
|
||||
public event Action ArmorAndDiamondNoLongerAvailable;
|
||||
public event Action TorchNoLongerAvailable;
|
||||
public event Action BlackDieNoLongerAvailable;
|
||||
public event Action DisplayChestReward;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
RoomRewards.ChestRewarded += HandChestRewarded;
|
||||
diamondAndLifeButton.onClick.AddListener(HandleDiamondAndLifeSelected);
|
||||
torchButton.onClick.AddListener(HandleTorchSelected);
|
||||
blackDiceButton.onClick.AddListener(HandleBlackDiceSelected);
|
||||
}
|
||||
|
||||
private void HandChestRewarded()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
DisplayChestReward?.Invoke();
|
||||
}
|
||||
|
||||
private void HandleDiamondAndLifeSelected()
|
||||
public void HandleDiamondAndLifeSelected()
|
||||
{
|
||||
diamondAndLifeButton.interactable = false;
|
||||
ArmorAndDiamondNoLongerAvailable?.Invoke();
|
||||
DiamondAndLifeSelected?.Invoke();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void HandleTorchSelected()
|
||||
public void HandleTorchSelected()
|
||||
{
|
||||
torchButton.interactable = false;
|
||||
TorchNoLongerAvailable?.Invoke();
|
||||
TorchAbilitySelected?.Invoke();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void HandleBlackDiceSelected()
|
||||
public void HandleBlackDiceSelected()
|
||||
{
|
||||
blackDiceButton.interactable = false;
|
||||
BlackDieNoLongerAvailable?.Invoke();
|
||||
BlackDiceAbilitySelected?.Invoke();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ namespace Abilities
|
|||
public class StartingBlackDieAbility : MonoBehaviour
|
||||
{
|
||||
public static event Action AbilitySelected;
|
||||
public event Action UnmarkUseUsedEvent;
|
||||
public event Action MarkUseUsedEvent;
|
||||
|
||||
[SerializeField] protected GameObject abilityUseOne;
|
||||
[SerializeField] protected GameObject abilityUseTwo;
|
||||
[SerializeField] protected GameObject abilityUseThree;
|
||||
private int _uses = 3;
|
||||
|
||||
private GameObject[] _usesUsed;
|
||||
|
|
@ -25,37 +24,29 @@ namespace Abilities
|
|||
GameManager.StateChanged -= HandleStateChanged;
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
_usesUsed = new GameObject[_uses];
|
||||
abilityUseOne.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseOne));
|
||||
abilityUseTwo.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseTwo));
|
||||
abilityUseThree.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseThree));
|
||||
}
|
||||
|
||||
private void UseClicked(GameObject abilityUseObject) {
|
||||
public void UseClicked() {
|
||||
if (!_canClick) return;
|
||||
|
||||
if (_uses > 0)
|
||||
{
|
||||
_usesUsed[_uses - 1] = abilityUseObject;
|
||||
MarkUseUsed(abilityUseObject);
|
||||
AbilitySelected?.Invoke();
|
||||
MarkUseUsed();
|
||||
_uses -= 1;
|
||||
}
|
||||
|
||||
_canClick = false;
|
||||
}
|
||||
|
||||
private void MarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
|
||||
private void MarkUseUsed() {
|
||||
MarkUseUsedEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void UnmarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = string.Empty;
|
||||
private void UnmarkUseUsed() {
|
||||
UnmarkUseUsedEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void AbilitySelectedButNotUsed() {
|
||||
UnmarkUseUsed(_usesUsed[_uses - 1]);
|
||||
UnmarkUseUsedEvent?.Invoke();
|
||||
_uses += 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,11 @@ using UnityEngine.UI;
|
|||
|
||||
public class TorchAbility : MonoBehaviour
|
||||
{
|
||||
public static
|
||||
event Action TorchAbilityUsed;
|
||||
[SerializeField] private GameObject abilityUseOne;
|
||||
[SerializeField] private GameObject abilityUseTwo;
|
||||
public static event Action TorchAbilityUsed;
|
||||
|
||||
public event Action AbilityGained;
|
||||
|
||||
private int _uses = 2;
|
||||
private GameObject[] _usesUsed;
|
||||
private bool _canClick;
|
||||
|
||||
private void OnEnable()
|
||||
|
|
@ -26,21 +24,12 @@ public class TorchAbility : MonoBehaviour
|
|||
ChestRewardSelection.TorchAbilitySelected -= HandleGainedTorchAbility;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_usesUsed = new GameObject[_uses];
|
||||
abilityUseOne.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseOne));
|
||||
abilityUseTwo.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseTwo));
|
||||
}
|
||||
|
||||
private void UseClicked(GameObject abilityUseObject)
|
||||
public void UseClicked()
|
||||
{
|
||||
if (!_canClick) return;
|
||||
|
||||
if (_uses > 0)
|
||||
{
|
||||
_usesUsed[_uses - 1] = abilityUseObject;
|
||||
MarkUsed(abilityUseObject);
|
||||
TorchAbilityUsed?.Invoke();
|
||||
_uses -= 1;
|
||||
}
|
||||
|
|
@ -48,11 +37,6 @@ public class TorchAbility : MonoBehaviour
|
|||
_canClick = false;
|
||||
}
|
||||
|
||||
private void MarkUsed(GameObject useObject)
|
||||
{
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
|
||||
}
|
||||
|
||||
private void HandleStateChanged(GameState state)
|
||||
{
|
||||
_canClick = true;
|
||||
|
|
@ -60,7 +44,6 @@ public class TorchAbility : MonoBehaviour
|
|||
|
||||
private void HandleGainedTorchAbility()
|
||||
{
|
||||
abilityUseOne.GetComponent<Button>().interactable = true;
|
||||
abilityUseTwo.GetComponent<Button>().interactable = true;
|
||||
AbilityGained?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using UnityEngine;
|
|||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UI;
|
||||
using static TagsAndLayers;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
|
|
@ -14,27 +15,22 @@ public class DiceRoller: MonoBehaviour
|
|||
private List<int> _rolledWhiteDice = new List<int>();
|
||||
private List<int> _rolledBlackDice = new List<int>();
|
||||
private System.Random _randomGen = new System.Random();
|
||||
[SerializeField] private Button rollDiceButton;
|
||||
|
||||
public GameObject dice;
|
||||
public event EventHandler diceRolled;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rollDiceButton.onClick.AddListener(RollDice);
|
||||
}
|
||||
public static event EventHandler diceRolled;
|
||||
public event Action Enabled;
|
||||
public event Action Disabled;
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
rollDiceButton.interactable = true;
|
||||
Enabled?.Invoke();
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
rollDiceButton.interactable = false;
|
||||
Disabled.Invoke();
|
||||
}
|
||||
|
||||
private void RollDice() {
|
||||
public void RollDice() {
|
||||
_rolledWhiteDice.Clear();
|
||||
_rolledBlackDice.Clear();
|
||||
for (int i = 0; i < NUMBER_OF_WHITE_DICE; i++)
|
||||
|
|
|
|||
|
|
@ -15,13 +15,15 @@ public class Die : MonoBehaviour
|
|||
{
|
||||
public DiceColor color;
|
||||
private int _result = 0;
|
||||
[SerializeField] private Button dieButton; // assign in the editor
|
||||
private Color originalColor;
|
||||
private bool _isClickable = false;
|
||||
private bool _selected = false;
|
||||
private bool _blackDieAbilityUsed = false;
|
||||
public event Action<Die> DieSelected;
|
||||
public event Action<Die> DieUnselected;
|
||||
public event Action<int> DieRollResult;
|
||||
public event Action DieReset;
|
||||
public event Action DieSelectedButPairNotCompleteEvent;
|
||||
public event Action DieSelectedAndPairCompleteEvent;
|
||||
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
|
|
@ -33,14 +35,9 @@ public class Die : MonoBehaviour
|
|||
StartingBlackDieAbility.AbilitySelected -= HandleOnBlackDieAbilitySelected;
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
dieButton.onClick.AddListener(DiePressed);
|
||||
originalColor = gameObject.GetComponent<Image>().color;
|
||||
}
|
||||
|
||||
public void SetResult(int result) {
|
||||
_result = result;
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = _result.ToString();
|
||||
DieRollResult?.Invoke(_result);
|
||||
}
|
||||
|
||||
public int GetResult()
|
||||
|
|
@ -51,8 +48,7 @@ public class Die : MonoBehaviour
|
|||
public void ResetDie() {
|
||||
_selected = false;
|
||||
_blackDieAbilityUsed = false;
|
||||
gameObject.GetComponent<Image>().color = originalColor;
|
||||
gameObject.GetComponent<Outline>().enabled = false;
|
||||
DieReset?.Invoke();
|
||||
}
|
||||
|
||||
public void DieBeingUsed(bool isPairComplete)
|
||||
|
|
@ -69,7 +65,7 @@ public class Die : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private void DiePressed()
|
||||
public void DiePressed()
|
||||
{
|
||||
if (!_isClickable || (color == DiceColor.Black && !_blackDieAbilityUsed)) return;
|
||||
|
||||
|
|
@ -86,14 +82,12 @@ public class Die : MonoBehaviour
|
|||
private void DieSelectedButPairNotComplete()
|
||||
{
|
||||
_selected = true;
|
||||
gameObject.GetComponent<Outline>().enabled = true;
|
||||
DieSelectedButPairNotCompleteEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void DieSelectedAndPairComplete() {
|
||||
_selected = true;
|
||||
gameObject.GetComponent<Outline>().enabled = false;
|
||||
gameObject.GetComponent<Image>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<Image>().color, ColorHelper.OkayGreen, 0.5f);
|
||||
DieSelectedAndPairCompleteEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class GameManager : MonoBehaviour
|
|||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
diceRoller.diceRolled += DiceRolled;
|
||||
DiceRoller.diceRolled += DiceRolled;
|
||||
passManager.PassRequested += PassRequested;
|
||||
rooms = GameObject.FindWithTag("RoomsParent");
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
|
|
|
|||
|
|
@ -6,30 +6,24 @@ using Button = UnityEngine.UI.Button;
|
|||
|
||||
public class PassManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button passButton;
|
||||
|
||||
public event EventHandler PassRequested;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
public event Action PassAvailable;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
passButton.onClick.AddListener(OnPassClicked);
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
}
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
if (state == GameState.RollDice)
|
||||
{
|
||||
passButton.interactable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
passButton.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPassClicked()
|
||||
public void OnPassClicked()
|
||||
{
|
||||
PassRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
if (state != GameState.RollDice)
|
||||
{
|
||||
PassAvailable?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
8
PuzzleGameProject/Assets/Scripts/UI.meta
Normal file
8
PuzzleGameProject/Assets/Scripts/UI.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 25e8b75e785fc25488c9115e532a1666
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
PuzzleGameProject/Assets/Scripts/UI/ChestPopUpController.cs
Normal file
46
PuzzleGameProject/Assets/Scripts/UI/ChestPopUpController.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ChestPopUpController : MonoBehaviour
|
||||
{
|
||||
public event Action BlackDieSelected;
|
||||
public event Action KeySelected;
|
||||
public event Action ArmorAndDiamondSelected;
|
||||
|
||||
private Button _blackDie;
|
||||
private Button _key;
|
||||
private Button _armorAndDiamond;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
VisualElement root = GetComponent<UIDocument>().rootVisualElement;
|
||||
|
||||
_blackDie = root.Q<Button>("BlackDie");
|
||||
_blackDie.clicked += () => BlackDieSelected?.Invoke();
|
||||
|
||||
_key = root.Q<Button>("Key");
|
||||
_key.clicked += () => KeySelected?.Invoke();
|
||||
|
||||
_armorAndDiamond = root.Q<Button>("ArmorAndDiamond");
|
||||
_armorAndDiamond.clicked += () => ArmorAndDiamondSelected?.Invoke();
|
||||
}
|
||||
|
||||
public void DisableBlackDie()
|
||||
{
|
||||
_blackDie.SetEnabled(false);
|
||||
}
|
||||
|
||||
public void DisableKey()
|
||||
{
|
||||
_key.SetEnabled(false);
|
||||
}
|
||||
|
||||
public void DisableArmorAndDiamond()
|
||||
{
|
||||
_armorAndDiamond.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f775e83b4c2599d468f1a1ce830ccff8
|
||||
265
PuzzleGameProject/Assets/Scripts/UI/InGameHUDController.cs
Normal file
265
PuzzleGameProject/Assets/Scripts/UI/InGameHUDController.cs
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b8775a362b77bc4bb1bcae768aa15a3
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject canvas;
|
||||
[SerializeField] private GameObject chestRewardSelectionUI;
|
||||
private void OnEnable()
|
||||
{
|
||||
RoomRewards.ChestRewarded += HandleChestRewarded;
|
||||
}
|
||||
|
||||
private void HandleChestRewarded()
|
||||
{
|
||||
chestRewardSelectionUI.SetActive(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue