2022-09-20 06:03:55 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2022-09-21 21:15:25 +00:00
|
|
|
|
public override void Initialize(bool addedNewTag = false)
|
2022-09-20 06:03:55 +00:00
|
|
|
|
{
|
2022-09-24 07:17:40 +00:00
|
|
|
|
IEnumerable<string> allTags = Tags.soundDefs.Concat(CustomTags.soundDefs);
|
2022-09-21 21:15:25 +00:00
|
|
|
|
string placeHolderText = "Enter new sound def...";
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
|
|
|
|
if (Workspace.animationDef == null) return;
|
|
|
|
|
|
|
|
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
|
|
|
Reset();
|
|
|
|
|
|
2022-09-21 21:15:25 +00:00
|
|
|
|
for (int i = 0; i < allTags.Count(); i++)
|
2022-09-20 06:03:55 +00:00
|
|
|
|
{
|
2022-09-21 21:15:25 +00:00
|
|
|
|
string tag = allTags.ElementAt(i);
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
|
|
|
|
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
|
2022-09-21 21:15:25 +00:00
|
|
|
|
_optionToggle.Find("Text").GetComponent<Text>().text = tag;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
|
|
|
|
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
|
2022-10-08 02:52:27 +00:00
|
|
|
|
toggleComp.isOn = Workspace.Instance.GetCurrentOrPreviousKeyframe(Workspace.actorID)?.soundEffect == tag;
|
2022-09-21 21:15:25 +00:00
|
|
|
|
toggleComp.onValueChanged.AddListener(delegate
|
|
|
|
|
{
|
2022-10-08 02:52:27 +00:00
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetCurrentOrPreviousKeyframe(Workspace.actorID);
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
|
|
|
|
if (keyframe != null)
|
2022-09-21 21:15:25 +00:00
|
|
|
|
{ keyframe.soundEffect = tag; }
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
2022-09-21 05:40:58 +00:00
|
|
|
|
Workspace.Instance.RecordEvent("Keyframe sound effect");
|
2022-09-20 06:03:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2022-10-12 05:22:29 +00:00
|
|
|
|
if (CustomTags.soundDefs.Contains(tag))
|
|
|
|
|
{
|
|
|
|
|
Button deleteButton = _optionToggle.Find("DeleteButton").GetComponent<Button>();
|
|
|
|
|
deleteButton.gameObject.SetActive(true);
|
|
|
|
|
deleteButton.onClick.AddListener(delegate { RemoveCustomTag(ref CustomTags.soundDefs, tag); });
|
|
|
|
|
}
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
2022-09-21 21:15:25 +00:00
|
|
|
|
if (addedNewTag && i == allTags.Count() - 1)
|
2022-09-20 06:03:55 +00:00
|
|
|
|
{ toggleComp.isOn = true; }
|
2022-10-12 05:22:29 +00:00
|
|
|
|
|
|
|
|
|
toggleComp.group = contentWindow.GetComponent<ToggleGroup>();
|
2022-09-20 06:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
|
2022-09-21 21:15:25 +00:00
|
|
|
|
_optionField.Find("Placeholder").GetComponent<Text>().text = placeHolderText;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
|
|
|
|
InputField fieldComp = _optionField.GetComponent<InputField>();
|
2022-09-21 21:15:25 +00:00
|
|
|
|
fieldComp.onEndEdit.AddListener(delegate { AddCustomTag(fieldComp, ref Tags.soundDefs, ref CustomTags.soundDefs); });
|
2022-09-20 06:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
|
|
|
RemoveCloneObjectsFromParent(contentWindow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|