Fixed bug where highlighted room would not unhighlight and refactored room highlighting to be habdled by rooms.
This commit is contained in:
parent
bcfd42147b
commit
6a309804ad
2 changed files with 38 additions and 37 deletions
|
|
@ -3,11 +3,12 @@ using System.Collections;
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
enum KeyType
|
||||
internal enum KeyType
|
||||
{
|
||||
Number,
|
||||
MatchinDice
|
||||
MatchingDice
|
||||
}
|
||||
|
||||
public class Room : MonoBehaviour
|
||||
|
|
@ -23,10 +24,20 @@ public class Room : MonoBehaviour
|
|||
private bool _isClickable = true;
|
||||
private Color _roomNumberOriginalColor;
|
||||
|
||||
private void OnEnable() {
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
GameManager.DiceSelected += HandleDiceSelected;
|
||||
GameManager.DiceUnselected += HandDiceUnselected;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
GameManager.StateChanged -= HandleStateChange;
|
||||
GameManager.DiceSelected -= HandleDiceSelected;
|
||||
GameManager.DiceUnselected -= HandDiceUnselected;
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start() {
|
||||
GameManager.StateChanged += HandleStateChange;
|
||||
|
||||
if (isEntrance) {
|
||||
SetPropertiesOfEntrance();
|
||||
}
|
||||
|
|
@ -38,16 +49,12 @@ public class Room : MonoBehaviour
|
|||
{
|
||||
numberText.SetText(number.ToString());
|
||||
}
|
||||
else if (keyType == KeyType.MatchinDice)
|
||||
else if (keyType == KeyType.MatchingDice)
|
||||
{
|
||||
numberText.SetText("=");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
|
||||
}
|
||||
|
||||
public void SetRoomExplored() {
|
||||
_isExplored = true;
|
||||
UnhighlightRoomAsOption();
|
||||
|
|
@ -55,12 +62,12 @@ public class Room : MonoBehaviour
|
|||
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||
}
|
||||
|
||||
public void HighlightRoomAsOption()
|
||||
private void HighlightRoomAsOption()
|
||||
{
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().color = Color.blue;
|
||||
}
|
||||
|
||||
public void UnhighlightRoomAsOption()
|
||||
private void UnhighlightRoomAsOption()
|
||||
{
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().color = _roomNumberOriginalColor;
|
||||
}
|
||||
|
|
@ -82,7 +89,7 @@ public class Room : MonoBehaviour
|
|||
}
|
||||
|
||||
// Check if the room is valid to be explored. If so trigger the event.
|
||||
public bool IsValidRoomToExplore() {
|
||||
private bool IsValidRoomToExplore() {
|
||||
if (_isExplored) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -118,7 +125,7 @@ public class Room : MonoBehaviour
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
case KeyType.MatchinDice:
|
||||
case KeyType.MatchingDice:
|
||||
if (pair.DoResultsMatch())
|
||||
{
|
||||
return true;
|
||||
|
|
@ -131,6 +138,7 @@ public class Room : MonoBehaviour
|
|||
}
|
||||
|
||||
private void HandleStateChange(GameState state) {
|
||||
UnhighlightRoomAsOption();
|
||||
switch (state)
|
||||
{
|
||||
case GameState.PickDiceOne:
|
||||
|
|
@ -144,4 +152,15 @@ public class Room : MonoBehaviour
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleDiceSelected(DicePair pair) {
|
||||
if (TryUnlock(pair) && IsValidRoomToExplore())
|
||||
{
|
||||
HighlightRoomAsOption();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandDiceUnselected() {
|
||||
UnhighlightRoomAsOption();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue