88 lines
2.9 KiB
C#
88 lines
2.9 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 SelectBodyDefTypesDialog : DialogBox
|
|
{
|
|
private Actor actor;
|
|
|
|
public void Start()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
public void AddBodyDefType(InputField field)
|
|
{
|
|
Debug.Log("Attempting to add new body def type");
|
|
|
|
if (field?.text == null || field.text == "")
|
|
{ Debug.LogWarning("Input field is null"); return; }
|
|
|
|
if (Workspace.bodyDefTypes.Contains(field.text))
|
|
{ Debug.LogWarning("Body def type is null"); field.text = ""; return; }
|
|
|
|
Debug.Log("Added new body type def: " + field.text);
|
|
Workspace.bodyDefTypes.Add(field.text);
|
|
|
|
Initialize();
|
|
}
|
|
|
|
public void Initialize(Actor actor = null)
|
|
{
|
|
if (actor != null)
|
|
{ this.actor = actor; }
|
|
|
|
if (actor == null)
|
|
{ actor = this.actor; }
|
|
|
|
if (actor == null) return;
|
|
|
|
foreach (string bodyDefType in actor.bodyDefTypes)
|
|
{
|
|
if (Workspace.bodyDefTypes.Contains(bodyDefType) == false)
|
|
{ Workspace.bodyDefTypes.Add(bodyDefType); }
|
|
}
|
|
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
Reset();
|
|
|
|
for (int i = 0; i < Workspace.bodyDefTypes.Count; i++)
|
|
{
|
|
string bodyDefType = Workspace.bodyDefTypes[i];
|
|
|
|
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
|
|
_optionToggle.Find("Text").GetComponent<Text>().text = bodyDefType;
|
|
|
|
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
|
|
toggleComp.isOn = actor.bodyDefTypes.Contains(bodyDefType);
|
|
toggleComp.onValueChanged.AddListener(delegate {
|
|
|
|
if (toggleComp.isOn && actor.bodyDefTypes.Contains(bodyDefType) == false)
|
|
{ actor.bodyDefTypes.Add(bodyDefType); }
|
|
|
|
else if (toggleComp.isOn == false && actor.bodyDefTypes.Contains(bodyDefType))
|
|
{ actor.bodyDefTypes.Remove(bodyDefType); }
|
|
});
|
|
}
|
|
|
|
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
|
|
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new body def type...";
|
|
|
|
InputField fieldComp = _optionField.GetComponent<InputField>();
|
|
fieldComp.onEndEdit.AddListener(delegate { AddBodyDefType(fieldComp); });
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
RemoveCloneObjectsFromParent(contentWindow);
|
|
}
|
|
}
|
|
}
|