mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
76 lines
2.7 KiB
C#
76 lines
2.7 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 AddBodyPart(InputField field)
|
|
{
|
|
if (field?.text == null || field.text == "")
|
|
{ return; }
|
|
|
|
if (Workspace.bodyParts.Contains(field.text))
|
|
{ field.text = ""; return; }
|
|
|
|
Workspace.interactionDefTypes.Add(field.text);
|
|
|
|
Initialize();
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
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.bodyParts.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); }
|
|
});
|
|
}
|
|
|
|
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 { AddBodyPart(fieldComp); });
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
RemoveCloneObjectsFromParent(contentWindow);
|
|
}
|
|
}
|
|
}
|