using System; using System.Collections; using System.Collections.Generic; using JetBrains.Annotations; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using Utils; public class SpeechManager : Singleton { private GameObject playerPanel; private GameObject otherPanel; private TextMeshProUGUI mainText; public Queue> textBuffer = new(); public float charactersPerSecond = 90; [CanBeNull] private string fulltext; private Coroutine ccoroutine; private string speaker; public string Status = "TALKING"; private int counter = 0; void Start() { playerPanel = transform.FindChildRecursive("PLAYERPANEL").gameObject; otherPanel = transform.FindChildRecursive("OTHERPANEL").gameObject; mainText = transform.FindChildRecursive("TEXTPANEL").GetComponentInChildren(); Debug.LogWarning(mainText); gameObject.SetActive(false); } public void HandlePress() { TutorialManager.Instance.LogAction("DIA"); if (fulltext != null) { StopCoroutine(ccoroutine); mainText.text = fulltext; Status = fulltext.Length > 30 ? "DONELONG" : "DONE"; fulltext = null; } else if (textBuffer.Count > 0) { //BORKBORKBORKBORK if (GlobalStateManager.Instance.finalScene) { EndSceneManager.Instance.SetFace(); } NextText(); } else { AudioManager.Instance.PlaySound("Select"); gameObject.SetActive(false); //BORKBORKBORK if (counter++ > 0 && LevelLoader.Instance.GlobalModifier == "CUP") { CupShuffle.Instance.StartShuffle(); } //BORKBORKBORKBORK if (GlobalStateManager.Instance.finalScene) { SceneManager.LoadScene(0); } } } public void StartText(KeyValuePair[] buffer) { gameObject.SetActive(true); foreach (var kvp in buffer) { textBuffer.Enqueue(kvp); } NextText(); } private void NextText() { playerPanel = transform.FindChildRecursive("PLAYERPANEL").gameObject; otherPanel = transform.FindChildRecursive("OTHERPANEL").gameObject; mainText = transform.FindChildRecursive("TEXTPANEL").GetComponentInChildren(); var item = textBuffer.Dequeue(); speaker = item.Value; if (LevelLoader.Instance.GlobalModifier == "HORSE" && speaker == "HORSE") { Debug.LogError("HORSE"); mainText.text = item.Key; playerPanel.SetActive(false); otherPanel.SetActive(false); AudioManager.Instance.PlaySound("Horse"); playerPanel.SetActive(false); otherPanel.SetActive(true); otherPanel.transform.GetChild(0).gameObject.SetActive(false); otherPanel.transform.GetChild(1).gameObject.SetActive(true); otherPanel.transform.GetChild(2).gameObject.SetActive(false); return; } Status = "TALKING"; AudioManager.Instance.PlaySound("Select"); ccoroutine = StartCoroutine(TypeTextUncapped(item.Key)); if (speaker == "PLAYER") { playerPanel.SetActive(true); otherPanel.SetActive(false); } else if (speaker == "GUARD") { playerPanel.SetActive(false); otherPanel.SetActive(true); otherPanel.transform.GetChild(0).gameObject.SetActive(true); otherPanel.transform.GetChild(1).gameObject.SetActive(false); otherPanel.transform.GetChild(2).gameObject.SetActive(false); } else if (speaker == "HORSE") { playerPanel.SetActive(false); otherPanel.SetActive(true); otherPanel.transform.GetChild(0).gameObject.SetActive(false); otherPanel.transform.GetChild(1).gameObject.SetActive(true); otherPanel.transform.GetChild(2).gameObject.SetActive(false); } else if (speaker == "JOKER") { playerPanel.SetActive(false); otherPanel.SetActive(true); otherPanel.transform.GetChild(0).gameObject.SetActive(false); otherPanel.transform.GetChild(1).gameObject.SetActive(false); otherPanel.transform.GetChild(2).gameObject.SetActive(true); } else { playerPanel.SetActive(false); otherPanel.SetActive(false); } } IEnumerator TypeTextUncapped(string line) { fulltext = line; float timer = 0; float interval = 1 / charactersPerSecond; string textBuffer = null; char[] chars = line.ToCharArray(); int i = 0; while (i < chars.Length) { if (timer < Time.deltaTime) { AudioManager.Instance.PlaySpeechSound(speaker != "PLAYER"); textBuffer += chars[i]; mainText.text = textBuffer; timer += interval; i++; } else { timer -= Time.deltaTime; yield return null; } } Status = fulltext.Length > 30 ? "DONELONG" : "DONE"; fulltext = null; } }