rimworld-animation-studio/Assets/Scripts/GUI/ActorCard.cs

134 lines
5.1 KiB
C#
Raw Normal View History

2022-09-14 05:25:58 +00:00
using System.Collections;
using System.Collections.Generic;
2022-09-19 00:07:44 +00:00
using System.Linq;
2022-09-14 05:25:58 +00:00
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class ActorCard : MonoBehaviour
{
public Dropdown genderDropdown;
public Dropdown bodyTypeDropdown;
public InputField bodyOffsetXField;
public InputField bodyOffsetZField;
public Toggle initiatorToggle;
2022-09-19 00:07:44 +00:00
private int actorID = -1;
private bool isDirty = false;
public void Initialize()
2022-09-14 05:25:58 +00:00
{
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
2022-09-14 05:25:58 +00:00
initiatorToggle.isOn = actor.initiator;
bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString();
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
2022-09-14 05:25:58 +00:00
}
2022-09-19 00:07:44 +00:00
public void OnBodyTypeChanged()
{
if (Workspace.animationDef == null) return;
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
2022-09-19 05:35:34 +00:00
AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>()[Workspace.actorID].bodyType = bodyType;
2022-09-19 00:07:44 +00:00
bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString();
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
}
public void OnValueChanged()
2022-09-14 05:25:58 +00:00
{
2022-09-19 00:07:44 +00:00
if (Workspace.animationDef == null || isDirty) return;
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
2022-09-19 00:07:44 +00:00
float.TryParse(bodyOffsetXField.text, out float x);
float.TryParse(bodyOffsetZField.text, out float z);
actor.bodyTypeOffset.SetOffset(bodyType, new Vector2(x, z));
actor.initiator = initiatorToggle.isOn;
2022-09-19 05:35:34 +00:00
switch (genderDropdown.value)
{
case 0: actor.requiredGender = new List<string>() { "Female" }; break;
case 2: actor.requiredGender = new List<string>() { "Male" }; break;
default: actor.requiredGender = null; break;
}
Workspace.Instance.RecordEvent("Actor body type offset data");
2022-09-14 05:25:58 +00:00
}
/*public void OpenSelectBodyPartsDialog()
{
2022-09-19 00:07:44 +00:00
if (Workspace.animationDef == null) return;
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectBodyPartsDialog)) as SelectBodyPartsDialog[];
if (dialog != null)
{ dialog[0].Initialize(actor); dialog[0].Pop(); }
}
public void OpenSelectDefNamesDialog()
{
2022-09-19 00:07:44 +00:00
if (Workspace.animationDef == null) return;
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectDefNamesDialog)) as SelectDefNamesDialog[];
if (dialog != null)
{ dialog[0].Initialize(actor); dialog[0].Pop(); }
}
public void OpenSelectBodyDefTypesDialog()
2022-09-14 05:25:58 +00:00
{
2022-09-19 00:07:44 +00:00
if (Workspace.animationDef == null) return;
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectBodyDefTypesDialog)) as SelectBodyDefTypesDialog[];
if (dialog != null)
{ dialog[0].Initialize(actor); dialog[0].Pop(); }
}*/
2022-09-19 00:07:44 +00:00
public void Update()
{
if (Workspace.animationDef == null) return;
if (actorID != Workspace.actorID)
{
isDirty = true;
2022-09-19 05:35:34 +00:00
if (Workspace.actorID >= AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>().Count())
2022-09-19 00:07:44 +00:00
{ Debug.Log("Waiting for actors to initialize..."); return; }
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
2022-09-19 05:35:34 +00:00
ActorBody actorBody = AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>()[Workspace.actorID];
2022-09-19 00:07:44 +00:00
string bodyType = actorBody.bodyType;
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
bodyTypeDropdown.value = bodyTypeDropdown.options.IndexOf(bodyTypeDropdown.options.First(x => x.text == bodyType));
bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString();
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
initiatorToggle.isOn = actor.initiator;
actorID = Workspace.actorID;
isDirty = false;
}
}
2022-09-14 05:25:58 +00:00
}
}