137 lines
4.1 KiB
C#
137 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Utils;
|
|
|
|
public class StatusManager : Singleton<StatusManager>
|
|
{
|
|
public Transform doorPanel;
|
|
public Transform doorPanelThoughts;
|
|
public GameObject doorPrefab;
|
|
public Transform guardPanel;
|
|
public Transform guardPanelThoughts;
|
|
public GameObject guardPrefab;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void PopulatePanels()
|
|
{
|
|
bool isHide = LevelLoader.Instance.GlobalModifier == "HIDE";
|
|
PopulatePanel(doorPanel, doorPrefab, LevelLoader.Instance.Doors.Cast<IDescribable>().ToList().Shuffle(),false, isHide);
|
|
PopulatePanel(guardPanel, doorPrefab, LevelLoader.Instance.Guards.Cast<IDescribable>().ToList().Shuffle(), false, isHide);
|
|
|
|
PopulatePanel(doorPanelThoughts, doorPrefab, LevelLoader.Instance.Doors.Cast<IDescribable>().ToList(),true, false);
|
|
PopulatePanel(guardPanelThoughts, doorPrefab, LevelLoader.Instance.Guards.Cast<IDescribable>().ToList(), true, false);
|
|
}
|
|
|
|
private Color[] colors = new Color[] { Color.white, Color.green, Color.red };
|
|
private Dictionary<GameObject, int> cycles = new Dictionary<GameObject, int>();
|
|
|
|
private void PopulatePanel(Transform panel, GameObject template, List<IDescribable> items, bool interactableType, bool hide)
|
|
{
|
|
foreach (Transform child in panel)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
foreach (IDescribable item in items)
|
|
{
|
|
var obj = Instantiate(template, panel);
|
|
|
|
|
|
var titleMesh = obj.transform.FindChildRecursive("TITLE").GetComponent<TextMeshProUGUI>();
|
|
var descMesh = obj.transform.FindChildRecursive("DESC").GetComponent<TextMeshProUGUI>();
|
|
|
|
if (!interactableType)
|
|
{
|
|
if (hide)
|
|
{
|
|
titleMesh.text = "???";
|
|
descMesh.text = "???";
|
|
}
|
|
else
|
|
{
|
|
titleMesh.text = item.GetName();
|
|
descMesh.text = item.GetDescription();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
titleMesh.text = item.GetDescribeName();
|
|
descMesh.text = "Click to set prediction";
|
|
cycles[obj] = 0;
|
|
|
|
obj.GetComponentInChildren<Button>().onClick.AddListener(() =>
|
|
{
|
|
obj.GetComponent<Image>().color = colors[++cycles[obj]%3];
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private Dictionary<RectTransform, bool> panelStates = new();
|
|
private float slideDuration = 0.3f;
|
|
|
|
public void TogglePanel(RectTransform panel)
|
|
{
|
|
TutorialManager.Instance.LogAction("SIDE");
|
|
|
|
if (!panelStates.ContainsKey(panel))
|
|
panelStates[panel] = false; // Initially closed
|
|
|
|
bool isOpen = panelStates[panel];
|
|
|
|
|
|
|
|
bool leftAligned = panel.anchorMin.x == 0f;
|
|
|
|
AudioManager.Instance.PlaySound(isOpen ? "WordRemove" : "WordAdd");
|
|
|
|
StartCoroutine(
|
|
SlidePanel(panel, !isOpen, panel.rect.width * (leftAligned ? 1 : -1))
|
|
);
|
|
|
|
panelStates[panel] = !isOpen;
|
|
}
|
|
|
|
private IEnumerator SlidePanel(RectTransform rect, bool open, float dist)
|
|
{
|
|
Vector2 start = rect.anchoredPosition;
|
|
|
|
Vector2 target = open
|
|
? start + Vector2.right * dist
|
|
: start + Vector2.left * dist;
|
|
|
|
float elapsed = 0f;
|
|
|
|
while (elapsed < slideDuration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
|
|
float t = Mathf.SmoothStep(
|
|
0f,
|
|
1f,
|
|
elapsed / slideDuration
|
|
);
|
|
|
|
rect.anchoredPosition = Vector2.Lerp(start, target, t);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
rect.anchoredPosition = target;
|
|
}
|
|
}
|