rimworld-animation-studio/Assets/Scripts/GUI/DialogBoxes/SelectInteractionDefsDialog.cs

73 lines
2.9 KiB
C#
Raw Normal View History

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 SelectInteractionDefsDialog : DialogBox
{
2022-09-21 21:15:25 +00:00
public override void Initialize(bool addedNewTag = false)
{
2022-09-21 21:15:25 +00:00
IEnumerable<string> allTags = Tags.interactionDefTypes.Concat(CustomTags.interactionDefTypes);
string placeHolderText = "Enter new interaction def type...";
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-21 21:15:25 +00:00
string tag = allTags.ElementAt(i);
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
2022-09-21 21:15:25 +00:00
_optionToggle.Find("Text").GetComponent<Text>().text = tag;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
2022-09-21 21:15:25 +00:00
toggleComp.isOn = Workspace.animationDef.interactionDefTypes.Contains(tag);
toggleComp.onValueChanged.AddListener(delegate
{
if (toggleComp.isOn && Workspace.animationDef.interactionDefTypes.Contains(tag) == false)
{ Workspace.animationDef.interactionDefTypes.Add(tag); }
2022-09-21 21:15:25 +00:00
else if (toggleComp.isOn == false && Workspace.animationDef.interactionDefTypes.Contains(tag))
{ Workspace.animationDef.interactionDefTypes.Remove(tag); }
2022-09-19 05:35:34 +00:00
Workspace.Instance.RecordEvent("Animation InteractionDef");
});
2022-09-19 05:35:34 +00:00
2022-09-21 21:15:25 +00:00
Button deleteButton = _optionToggle.Find("DeleteButton").GetComponent<Button>();
if (deleteButton != null && CustomTags.interactionDefTypes.Contains(tag))
{
deleteButton.gameObject.SetActive(true);
deleteButton.onClick.AddListener(delegate
{
CustomTags.interactionDefTypes.Remove(tag);
ApplicationManager.Instance.SaveCustomArrays();
Initialize();
});
}
if (addedNewTag && i == allTags.Count() - 1)
2022-09-19 05:35:34 +00:00
{ toggleComp.isOn = true; }
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
2022-09-21 21:15:25 +00:00
_optionField.Find("Placeholder").GetComponent<Text>().text = placeHolderText;
InputField fieldComp = _optionField.GetComponent<InputField>();
2022-09-21 21:15:25 +00:00
fieldComp.onEndEdit.AddListener(delegate { AddCustomTag(fieldComp, ref Tags.interactionDefTypes, ref CustomTags.interactionDefTypes); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}