using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using DefaultNamespace; using JetBrains.Annotations; using Newtonsoft.Json.Linq; using NUnit.Framework; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; using Utils; public class DialogManager : Singleton { private GuardManager currentGuard; public JObject dialogTree; [CanBeNull] private JObject currentItem; public GameObject QuestionOptionPrefab; public GameObject QuestionInfillPrefab; public GameObject AskButton; public Transform QuestionOptionArea; public Transform QuestionInfillArea; private Stack FullQuestionPrefixes = new Stack(); private string FullQuestion; private int recursiveDepth = 0; public int MaxRecursiveDepth = 1; private Stack<(string key, JObject parent, GameObject infil)> questionStack = new(); // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { QuestionOptionArea = transform.FindChildRecursive("ADDQOPTIONSHERE"); QuestionInfillArea = transform.FindChildRecursive("ADDQINFILSHERE"); gameObject.SetActive(false); } // Update is called once per frame void Update() { } //start from right click [ContextMenu("Debug Questioning")] private void DebugSpeech() { StartDialog(LevelLoader.Instance.Guards[0]); } //public interface to start interaction public void StartDialog(GuardManager guardId) { gameObject.SetActive(true); AskButton.SetActive(false); QuestionOptionArea = transform.FindChildRecursive("ADDQOPTIONSHERE"); if (!GlobalStateManager.Instance.finalScene) { dialogTree = LevelLoader.Instance.SpeechTree; } currentGuard = guardId; currentItem = dialogTree; PopulateQuestionOptions(); } private void PopulateQuestionOptions() { //clear options foreach (Transform child in QuestionOptionArea) { Destroy(child.gameObject); } if (currentItem == null) { return; } foreach (var kvp in currentItem) { Debug.Log(kvp.ToString()); //special keywords if (kvp.Key == "DOORS") { foreach (var man in LevelLoader.Instance.Doors) { PopulateSingleQuestionOption(new KeyValuePair(man.GetUnknownDescription(), kvp.Value)); } } else if (kvp.Key.StartsWith("GUARDS")) { foreach (var man in LevelLoader.Instance.Guards) { string postfix = ""; if (man == currentGuard) { if (kvp.Key.EndsWith("YOU")) { postfix = " (you)"; } else { //this lowkey breaks most puzzes cause double negative makes all tell truth continue; } } PopulateSingleQuestionOption(new KeyValuePair(man.GetUnknownDescription() + postfix, kvp.Value)); } } else if (kvp.Key == "QUESTION") { recursiveDepth++; FullQuestionPrefixes.Push((kvp.Value as JValue).ToString()); currentItem = dialogTree; PopulateQuestionOptions(); } else if (!kvp.Key.StartsWith("NOREC_") || recursiveDepth < MaxRecursiveDepth) { PopulateSingleQuestionOption(kvp); } } } private void PopulateSingleQuestionOption(KeyValuePair kvp) { var option = Instantiate(QuestionOptionPrefab, QuestionOptionArea); option.GetComponentInChildren().text = kvp.Key.Replace("NOREC_", ""); option.GetComponent