Implemented starting blackd dice ability.
This commit is contained in:
parent
fdeab50984
commit
91582767ad
6 changed files with 645 additions and 87 deletions
|
|
@ -1,84 +1,25 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using Abilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Abilities
|
||||
public class BlackDieAbility: StartingBlackDieAbility
|
||||
{
|
||||
public class BlackDieAbility : MonoBehaviour
|
||||
protected override void OnEnable()
|
||||
{
|
||||
public static event Action AbilitySelected;
|
||||
|
||||
[SerializeField] private GameObject abilityUseOne;
|
||||
[SerializeField] private GameObject abilityUseTwo;
|
||||
[SerializeField] private GameObject abilityUseThree;
|
||||
private int _uses = 3;
|
||||
|
||||
private GameObject[] _usesUsed;
|
||||
private bool _canClick;
|
||||
base.OnEnable();
|
||||
ChestRewardSelection.BlackDiceAbilitySelected += HandleBlackDieAbilityGained;
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChanged;
|
||||
ChestRewardSelection.BlackDiceAbilitySelected += HandleBlackDieAbilityGained;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
GameManager.StateChanged -= HandleStateChanged;
|
||||
ChestRewardSelection.BlackDiceAbilitySelected -= HandleBlackDieAbilityGained;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (!_canClick) return;
|
||||
|
||||
if (_uses > 0)
|
||||
{
|
||||
_usesUsed[_uses - 1] = abilityUseObject;
|
||||
MarkUseUsed(abilityUseObject);
|
||||
AbilitySelected?.Invoke();
|
||||
_uses -= 1;
|
||||
}
|
||||
|
||||
_canClick = false;
|
||||
}
|
||||
|
||||
private void MarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
|
||||
}
|
||||
|
||||
private void UnmarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = string.Empty;
|
||||
}
|
||||
|
||||
public void AbilitySelectedButNotUsed() {
|
||||
UnmarkUseUsed(_usesUsed[_uses - 1]);
|
||||
_uses += 1;
|
||||
}
|
||||
|
||||
private void HandleStateChanged(GameState state) {
|
||||
switch (state)
|
||||
{
|
||||
case GameState.PickDiceOne:
|
||||
case GameState.PickDiceTwo:
|
||||
_canClick = true;
|
||||
break;
|
||||
default:
|
||||
_canClick = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleBlackDieAbilityGained()
|
||||
{
|
||||
abilityUseOne.GetComponent<Button>().interactable = true;
|
||||
abilityUseTwo.GetComponent<Button>().interactable = true;
|
||||
abilityUseThree.GetComponent<Button>().interactable = true;
|
||||
}
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
ChestRewardSelection.BlackDiceAbilitySelected -= HandleBlackDieAbilityGained;
|
||||
}
|
||||
|
||||
private void HandleBlackDieAbilityGained()
|
||||
{
|
||||
abilityUseOne.GetComponent<Button>().interactable = true;
|
||||
abilityUseTwo.GetComponent<Button>().interactable = true;
|
||||
abilityUseThree.GetComponent<Button>().interactable = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 79af16baa8fbe4744817b63d2b6f2007
|
||||
guid: 04241db9fdb62a147acac6895a47db06
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Abilities
|
||||
{
|
||||
public class StartingBlackDieAbility : MonoBehaviour
|
||||
{
|
||||
public static event Action AbilitySelected;
|
||||
|
||||
[SerializeField] protected GameObject abilityUseOne;
|
||||
[SerializeField] protected GameObject abilityUseTwo;
|
||||
[SerializeField] protected GameObject abilityUseThree;
|
||||
private int _uses = 3;
|
||||
|
||||
private GameObject[] _usesUsed;
|
||||
private bool _canClick;
|
||||
|
||||
protected virtual void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChanged;
|
||||
}
|
||||
|
||||
protected virtual void OnDisable() {
|
||||
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) {
|
||||
if (!_canClick) return;
|
||||
|
||||
if (_uses > 0)
|
||||
{
|
||||
_usesUsed[_uses - 1] = abilityUseObject;
|
||||
MarkUseUsed(abilityUseObject);
|
||||
AbilitySelected?.Invoke();
|
||||
_uses -= 1;
|
||||
}
|
||||
|
||||
_canClick = false;
|
||||
}
|
||||
|
||||
private void MarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
|
||||
}
|
||||
|
||||
private void UnmarkUseUsed(GameObject useObject) {
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = string.Empty;
|
||||
}
|
||||
|
||||
public void AbilitySelectedButNotUsed() {
|
||||
UnmarkUseUsed(_usesUsed[_uses - 1]);
|
||||
_uses += 1;
|
||||
}
|
||||
|
||||
private void HandleStateChanged(GameState state) {
|
||||
switch (state)
|
||||
{
|
||||
case GameState.PickDiceOne:
|
||||
case GameState.PickDiceTwo:
|
||||
_canClick = true;
|
||||
break;
|
||||
default:
|
||||
_canClick = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 79af16baa8fbe4744817b63d2b6f2007
|
||||
|
|
@ -25,12 +25,12 @@ public class Die : MonoBehaviour
|
|||
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
BlackDieAbility.AbilitySelected += HandleOnBlackDieAbilitySelected;
|
||||
StartingBlackDieAbility.AbilitySelected += HandleOnBlackDieAbilitySelected;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
GameManager.StateChanged -= HandleStateChange;
|
||||
BlackDieAbility.AbilitySelected -= HandleOnBlackDieAbilitySelected;
|
||||
StartingBlackDieAbility.AbilitySelected -= HandleOnBlackDieAbilitySelected;
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
|
|
@ -50,6 +50,7 @@ public class Die : MonoBehaviour
|
|||
|
||||
public void ResetDie() {
|
||||
_selected = false;
|
||||
_blackDieAbilityUsed = false;
|
||||
gameObject.GetComponent<Image>().color = originalColor;
|
||||
gameObject.GetComponent<Outline>().enabled = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue