using System; using System.Collections.Generic; using DefaultNamespace; using JetBrains.Annotations; using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; using Utils; public class DialogManager : Singleton { private GuardManager currentGuard; private JObject dialogTree; [CanBeNull] private JObject currentItem; public GameObject QuestionOptionPrefab; public GameObject QuestionInfillPrefab; public GameObject AskButton; private Transform QuestionOptionArea; private 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); 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) { //special keywords if (kvp.Key == "DOORS") { for (int i = 0; i < LevelLoader.Instance.Doors.Count; i++) { PopulateSingleQuestionOption(new KeyValuePair("door " + (i+1), kvp.Value)); } } else if (kvp.Key == "GUARDS") { for (int i = 0; i < LevelLoader.Instance.Guards.Count; i++) { PopulateSingleQuestionOption(new KeyValuePair("guard " + (i+1), 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