using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; namespace RimWorldAnimationStudio { public class SelectSoundDefDialog : DialogBox { public override void Initialize(bool addedNewTag = false) { IEnumerable allTags = Tags.soundDefs.Concat(CustomTags.soundDefs); string placeHolderText = "Enter new sound def..."; if (Workspace.animationDef == null) return; Transform contentWindow = transform.FindDeepChild("Content"); Reset(); for (int i = 0; i < allTags.Count(); i++) { string tag = allTags.ElementAt(i); Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform; _optionToggle.Find("Text").GetComponent().text = tag; Toggle toggleComp = _optionToggle.GetComponent(); toggleComp.isOn = Workspace.Instance.GetCurrentPawnKeyframe()?.soundEffect == tag; toggleComp.onValueChanged.AddListener(delegate { PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(); if (keyframe != null) { keyframe.soundEffect = tag; } Workspace.Instance.RecordEvent("Keyframe sound effect"); }); toggleComp.group = contentWindow.GetComponent(); if (addedNewTag && i == allTags.Count() - 1) { toggleComp.isOn = true; } } Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform; _optionField.Find("Placeholder").GetComponent().text = placeHolderText; InputField fieldComp = _optionField.GetComponent(); fieldComp.onEndEdit.AddListener(delegate { AddCustomTag(fieldComp, ref Tags.soundDefs, ref CustomTags.soundDefs); }); } public void Reset() { Transform contentWindow = transform.FindDeepChild("Content"); RemoveCloneObjectsFromParent(contentWindow); } } }