mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
81 lines
3 KiB
C#
81 lines
3 KiB
C#
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
|
|
{
|
|
public void Start()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
public void AddInteractionDef(InputField field)
|
|
{
|
|
if (field?.text == null || field.text == "")
|
|
{ return; }
|
|
|
|
if (Workspace.interactionDefTypes.Contains(field.text))
|
|
{ field.text = ""; return; }
|
|
|
|
Workspace.interactionDefTypes.Add(field.text);
|
|
|
|
Initialize(true);
|
|
}
|
|
|
|
public void Initialize(bool addedNewTag = false)
|
|
{
|
|
if (Workspace.animationDef == null) return;
|
|
|
|
foreach (string interactionDefType in Workspace.animationDef.interactionDefTypes)
|
|
{
|
|
if (Workspace.interactionDefTypes.Contains(interactionDefType) == false)
|
|
{ Workspace.interactionDefTypes.Add(interactionDefType); }
|
|
}
|
|
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
Reset();
|
|
|
|
for (int i = 0; i < Workspace.interactionDefTypes.Count; i++)
|
|
{
|
|
string interactionDefType = Workspace.interactionDefTypes[i];
|
|
|
|
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
|
|
_optionToggle.Find("Text").GetComponent<Text>().text = interactionDefType;
|
|
|
|
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
|
|
toggleComp.isOn = Workspace.animationDef.interactionDefTypes.Contains(interactionDefType);
|
|
toggleComp.onValueChanged.AddListener(delegate {
|
|
|
|
if (toggleComp.isOn && Workspace.animationDef.interactionDefTypes.Contains(interactionDefType) == false)
|
|
{ Workspace.animationDef.interactionDefTypes.Add(interactionDefType); }
|
|
|
|
else if (toggleComp.isOn == false && Workspace.animationDef.interactionDefTypes.Contains(interactionDefType))
|
|
{ Workspace.animationDef.interactionDefTypes.Remove(interactionDefType); }
|
|
|
|
Workspace.Instance.MakeDirty();
|
|
});
|
|
|
|
if (addedNewTag && i == Workspace.sexTypes.Count - 1)
|
|
{ toggleComp.isOn = true; }
|
|
}
|
|
|
|
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
|
|
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new interaction def type...";
|
|
|
|
InputField fieldComp = _optionField.GetComponent<InputField>();
|
|
fieldComp.onEndEdit.AddListener(delegate { AddInteractionDef(fieldComp); });
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
RemoveCloneObjectsFromParent(contentWindow);
|
|
}
|
|
}
|
|
}
|