85 lines
2.9 KiB
C#
85 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 SelectBodyPartsDialog : DialogBox
|
|
{
|
|
public void OnEnable()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
public void AddBodyPart(InputField field)
|
|
{
|
|
Debug.Log("Attempting to add new body part");
|
|
|
|
if (field?.text == null || field.text == "")
|
|
{ Debug.LogWarning("Input field is null"); return; }
|
|
|
|
if (Workspace.bodyParts.Contains(field.text))
|
|
{ Debug.LogWarning("Body part is null"); field.text = ""; return; }
|
|
|
|
Debug.Log("Add new body part: " + field.text);
|
|
Workspace.bodyParts.Add(field.text);
|
|
|
|
Initialize(true);
|
|
}
|
|
|
|
public void Initialize(bool addedNewTag = false)
|
|
{
|
|
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
|
|
|
foreach (string bodyPart in actor.requiredGenitals)
|
|
{
|
|
if (Workspace.bodyParts.Contains(bodyPart) == false)
|
|
{ Workspace.bodyParts.Add(bodyPart); }
|
|
}
|
|
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
Reset();
|
|
|
|
for (int i = 0; i < Workspace.bodyParts.Count; i++)
|
|
{
|
|
string bodyPart = Workspace.bodyParts[i];
|
|
|
|
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
|
|
_optionToggle.Find("Text").GetComponent<Text>().text = bodyPart;
|
|
|
|
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
|
|
toggleComp.isOn = actor.requiredGenitals.Contains(bodyPart);
|
|
toggleComp.onValueChanged.AddListener(delegate {
|
|
|
|
if (toggleComp.isOn && actor.requiredGenitals.Contains(bodyPart) == false)
|
|
{ actor.requiredGenitals.Add(bodyPart); }
|
|
|
|
else if (toggleComp.isOn == false && actor.requiredGenitals.Contains(bodyPart))
|
|
{ actor.requiredGenitals.Remove(bodyPart); }
|
|
|
|
Workspace.Instance.RecordEvent("Actor required body part");
|
|
});
|
|
|
|
if (addedNewTag && i == Workspace.sexTypes.Count - 1)
|
|
{ toggleComp.isOn = true; }
|
|
}
|
|
|
|
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
|
|
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new body part name...";
|
|
|
|
InputField fieldComp = _optionField.GetComponent<InputField>();
|
|
fieldComp.onEndEdit.AddListener(delegate { AddBodyPart(fieldComp); });
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
RemoveCloneObjectsFromParent(contentWindow);
|
|
}
|
|
}
|
|
}
|