using System; using System.Collections.Generic; using JetBrains.Annotations; using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; using Utils; public class DialogManager : Singleton { private int currentGuard = 0; private JObject dialogTree; [CanBeNull] private JObject currentItem; public GameObject QuestionOptionPrefab; public GameObject QuestionInfillPrefab; public GameObject AskButton; private Transform QuestionOptionArea; private Transform QuestionInfillArea; private string FullQuestion; 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"); } // Update is called once per frame void Update() { } [ContextMenu("Debug Something")] private void DebugSpeech() { StartDialog(0); } public void StartDialog(int guardId) { 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") { currentItem = dialogTree; PopulateQuestionOptions(); } else { PopulateSingleQuestionOption(kvp); } } } private void PopulateSingleQuestionOption(KeyValuePair kvp) { var option = Instantiate(QuestionOptionPrefab, QuestionOptionArea); option.GetComponentInChildren().text = kvp.Key; option.GetComponent