mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Code refactor
This commit is contained in:
parent
cd4711a8e5
commit
757badf4f6
517 changed files with 2534 additions and 2221 deletions
51
Assets/Scripts/GUI/Cards/ActorAddonCard.cs
Normal file
51
Assets/Scripts/GUI/Cards/ActorAddonCard.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
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 ActorAddonCard : MonoBehaviour
|
||||
{
|
||||
public string addonName;
|
||||
public InputField xOffsetField;
|
||||
public InputField zOffsetField;
|
||||
public InputField rotationField;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
xOffsetField.onEndEdit.AddListener(delegate { OnFieldValueChanged(); });
|
||||
zOffsetField.onEndEdit.AddListener(delegate { OnFieldValueChanged(); });
|
||||
rotationField.onEndEdit.AddListener(delegate { OnFieldValueChanged(); });
|
||||
|
||||
AnimationController.Instance.animationClipTimeField.onValueChanged.AddListener(delegate { OnKeyframeValueChanged(); });
|
||||
}
|
||||
|
||||
public void OnFieldValueChanged()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
PawnAnimationClip clip = Workspace.GetCurrentPawnAnimationClip();
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
keyframe.GetAddonKeyframe(addonName).PosX = float.Parse(xOffsetField.text);
|
||||
keyframe.GetAddonKeyframe(addonName).PosZ = float.Parse(zOffsetField.text);
|
||||
keyframe.GetAddonKeyframe(addonName).Rotation = float.Parse(rotationField.text);
|
||||
|
||||
clip.BuildSimpleCurves();
|
||||
Workspace.RecordEvent("Actor addon position / orientation");
|
||||
}
|
||||
|
||||
public void OnKeyframeValueChanged()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
PawnAnimationClip clip = Workspace.GetCurrentPawnAnimationClip();
|
||||
|
||||
xOffsetField.SetTextWithoutNotify(clip.GetActorAddon(addonName).PosX.Evaluate((float)Workspace.StageTick / Workspace.StageWindowSize).ToString());
|
||||
zOffsetField.SetTextWithoutNotify(clip.GetActorAddon(addonName).PosZ.Evaluate((float)Workspace.StageTick / Workspace.StageWindowSize).ToString());
|
||||
rotationField.SetTextWithoutNotify(clip.GetActorAddon(addonName).Rotation.Evaluate((float)Workspace.StageTick / Workspace.StageWindowSize).ToString());
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Cards/ActorAddonCard.cs.meta
Normal file
11
Assets/Scripts/GUI/Cards/ActorAddonCard.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a63bb35c73985c46b65383f08d4afd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
124
Assets/Scripts/GUI/Cards/ActorCard.cs
Normal file
124
Assets/Scripts/GUI/Cards/ActorCard.cs
Normal file
|
@ -0,0 +1,124 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ActorCard : MonoBehaviour
|
||||
{
|
||||
public Toggle initiatorToggle;
|
||||
public Dropdown selectActorLayerDropdown;
|
||||
public Dropdown bodyTypeDropdown;
|
||||
public InputField bodyOffsetXField;
|
||||
public InputField bodyOffsetZField;
|
||||
public Dropdown raceDropdown;
|
||||
public InputField raceOffsetXField;
|
||||
public InputField raceOffsetZField;
|
||||
|
||||
private Actor actor { get { return Workspace.GetCurrentActor(); } }
|
||||
private PawnAnimationClip clip { get { return Workspace.GetCurrentPawnAnimationClip(); } }
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
UpdateRaceDropdown();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// General events
|
||||
EventsManager.onAnimationDefChanged.AddListener(delegate { UpdateGUI(); });
|
||||
EventsManager.onActorIDChanged.AddListener(delegate { UpdateGUI(); });
|
||||
EventsManager.onDefNamesChanged.AddListener(delegate { UpdateRaceDropdown(); });
|
||||
|
||||
// Local events
|
||||
initiatorToggle.onValueChanged.AddListener(delegate {
|
||||
actor.initiator = initiatorToggle.isOn;
|
||||
Workspace.RecordEvent("Change in actor sex initiator status ");
|
||||
});
|
||||
|
||||
selectActorLayerDropdown.onValueChanged.AddListener(delegate {
|
||||
clip.Layer = selectActorLayerDropdown.options[selectActorLayerDropdown.value].text;
|
||||
Workspace.RecordEvent("Change in actor render layer");
|
||||
});
|
||||
|
||||
bodyTypeDropdown.onValueChanged.AddListener(delegate { OnDropdownChanged(); });
|
||||
bodyOffsetXField.onEndEdit.AddListener(delegate { OnInputFieldChanged(); });
|
||||
bodyOffsetZField.onEndEdit.AddListener(delegate { OnInputFieldChanged(); });
|
||||
|
||||
raceDropdown.onValueChanged.AddListener(delegate { OnDropdownChanged(); });
|
||||
raceOffsetXField.onEndEdit.AddListener(delegate { OnInputFieldChanged(); });
|
||||
raceOffsetZField.onEndEdit.AddListener(delegate { OnInputFieldChanged(); });
|
||||
|
||||
// Initialize
|
||||
UpdateGUI();
|
||||
}
|
||||
|
||||
public void OnInputFieldChanged()
|
||||
{
|
||||
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
|
||||
bodyType = string.IsNullOrEmpty(bodyType) ? "Male" : bodyType;
|
||||
|
||||
float.TryParse(bodyOffsetXField.text, out float x);
|
||||
float.TryParse(bodyOffsetZField.text, out float z);
|
||||
actor.BodyTypeOffset.SetOffset(bodyType, new Vector2(x, z));
|
||||
|
||||
float.TryParse(raceOffsetXField.text, out x);
|
||||
float.TryParse(raceOffsetZField.text, out z);
|
||||
actor.SetPawnRaceOffset(new Vector2(x, z));
|
||||
|
||||
Workspace.RecordEvent("Actor offset");
|
||||
}
|
||||
|
||||
public void OnDropdownChanged()
|
||||
{
|
||||
actor.bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
|
||||
|
||||
if (raceDropdown.options[raceDropdown.value].text != actor.GetPawnRaceDef().defName)
|
||||
{ Workspace.selectedBodyPart = null; }
|
||||
|
||||
actor.SetPawnRaceDef(raceDropdown.options[raceDropdown.value].text);
|
||||
|
||||
Workspace.RecordEvent("Actor body type/race change");
|
||||
|
||||
UpdateGUI();
|
||||
}
|
||||
|
||||
public void UpdateRaceDropdown()
|
||||
{
|
||||
raceDropdown.ClearOptions();
|
||||
int index = raceDropdown.value;
|
||||
|
||||
IEnumerable<string> optionsList = DefaultTags.defNames.Concat(CustomTags.defNames);
|
||||
foreach (string defName in optionsList)
|
||||
{ raceDropdown.options.Add(new Dropdown.OptionData(defName)); }
|
||||
|
||||
raceDropdown.value = Mathf.Clamp(index, 0, raceDropdown.options.Count - 1);
|
||||
}
|
||||
|
||||
public void UpdateGUI()
|
||||
{
|
||||
initiatorToggle.isOn = actor.Initiator;
|
||||
|
||||
string layer = clip.Layer;
|
||||
selectActorLayerDropdown.SetValueWithoutNotify(selectActorLayerDropdown.options.FindIndex(x => x.text == layer));
|
||||
|
||||
string bodyType = actor.bodyType;
|
||||
bodyTypeDropdown.SetValueWithoutNotify(bodyTypeDropdown.options.FindIndex(x => x.text == bodyType));
|
||||
|
||||
bodyOffsetXField.SetTextWithoutNotify(string.Format("{0:0.000}", actor.BodyTypeOffset.GetOffset(bodyType).x.ToString()));
|
||||
bodyOffsetZField.SetTextWithoutNotify(string.Format("{0:0.000}", actor.BodyTypeOffset.GetOffset(bodyType).z.ToString()));
|
||||
|
||||
bodyTypeDropdown.interactable = actor.GetPawnRaceDef().isHumanoid;
|
||||
bodyOffsetXField.interactable = actor.GetPawnRaceDef().isHumanoid;
|
||||
bodyOffsetZField.interactable = actor.GetPawnRaceDef().isHumanoid;
|
||||
|
||||
string race = actor.GetPawnRaceDef().defName;
|
||||
raceDropdown.SetValueWithoutNotify(raceDropdown.options.FindIndex(x => x.text == race));
|
||||
|
||||
raceOffsetXField.SetTextWithoutNotify(string.Format("{0:0.000}", actor.GetPawnRaceOffset().x.ToString()));
|
||||
raceOffsetZField.SetTextWithoutNotify(string.Format("{0:0.000}", actor.GetPawnRaceOffset().z.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Cards/ActorCard.cs.meta
Normal file
11
Assets/Scripts/GUI/Cards/ActorCard.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9731614c7527b624492dd33f9b006fcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
108
Assets/Scripts/GUI/Cards/ActorKeyframeCard.cs
Normal file
108
Assets/Scripts/GUI/Cards/ActorKeyframeCard.cs
Normal file
|
@ -0,0 +1,108 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ActorKeyframeCard : Singleton<ActorKeyframeCard>
|
||||
{
|
||||
public InputField positionXField;
|
||||
public InputField positionZField;
|
||||
public InputField rotationField;
|
||||
public InputField headBobField;
|
||||
public InputField headRotationField;
|
||||
public InputField appendageRotationField;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Workspace.animationDef == null)
|
||||
{ return; }
|
||||
|
||||
positionXField.interactable = AnimationController.Instance.isAnimating == false;
|
||||
positionZField.interactable = AnimationController.Instance.isAnimating == false;
|
||||
rotationField.interactable = AnimationController.Instance.isAnimating == false;
|
||||
headBobField.interactable = AnimationController.Instance.isAnimating == false;
|
||||
headRotationField.interactable = AnimationController.Instance.isAnimating == false;
|
||||
appendageRotationField.interactable = AnimationController.Instance.isAnimating == false;
|
||||
}
|
||||
|
||||
public void OnValueChanged()
|
||||
{
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
keyframe.BodyOffsetX = float.Parse(positionXField.text);
|
||||
keyframe.BodyOffsetZ = float.Parse(positionZField.text);
|
||||
keyframe.BodyAngle = float.Parse(rotationField.text);
|
||||
keyframe.HeadBob = float.Parse(headBobField.text);
|
||||
keyframe.HeadAngle = float.Parse(headRotationField.text);
|
||||
keyframe.GenitalAngle = float.Parse(appendageRotationField.text);
|
||||
|
||||
Workspace.animationDef.Actors[Workspace.ActorID].ControlGenitalAngle = keyframe.GenitalAngle != 0;
|
||||
Workspace.GetPawnAnimationClip(Workspace.ActorID).BuildSimpleCurves();
|
||||
Workspace.RecordEvent("Actor position / orientation");
|
||||
}
|
||||
|
||||
public void AdjustActor(Vector2 deltaOffset)
|
||||
{
|
||||
float deltaAngle = -deltaOffset.x * 33.3333f + deltaOffset.y * 33.3333f;
|
||||
int facing = deltaOffset.x < 0 ? 3 : deltaOffset.y < 0 ? 2 : deltaOffset.x > 0 ? 1 : 0;
|
||||
|
||||
switch (Workspace.actorManipulationMode)
|
||||
{
|
||||
case ActorManipulationMode.Pan: MoveActor(deltaOffset); break;
|
||||
case ActorManipulationMode.Rotate: RotateActor(deltaAngle); break;
|
||||
case ActorManipulationMode.Face: FaceActor(facing); break;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveActor(Vector2 deltaOffset)
|
||||
{
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
if (Workspace.selectedBodyPart == null)
|
||||
{
|
||||
keyframe.BodyOffsetX += deltaOffset.x;
|
||||
keyframe.BodyOffsetZ += deltaOffset.y;
|
||||
}
|
||||
|
||||
else if (Workspace.selectedBodyPart.isHead)
|
||||
{ keyframe.HeadBob += deltaOffset.y; }
|
||||
|
||||
Workspace.GetCurrentPawnAnimationClip().BuildSimpleCurves();
|
||||
Workspace.RecordEvent("Actor position / orientation");
|
||||
}
|
||||
|
||||
public void RotateActor(float deltaAngle)
|
||||
{
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
if (Workspace.selectedBodyPart == null)
|
||||
{ keyframe.BodyAngle += deltaAngle; }
|
||||
|
||||
else if (Workspace.selectedBodyPart.isHead)
|
||||
{ keyframe.HeadAngle += deltaAngle; }
|
||||
|
||||
else
|
||||
{ keyframe.GenitalAngle -= deltaAngle; }
|
||||
|
||||
Workspace.GetCurrentPawnAnimationClip().BuildSimpleCurves();
|
||||
Workspace.RecordEvent("Actor position / orientation");
|
||||
}
|
||||
|
||||
public void FaceActor(int facing)
|
||||
{
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
if (Workspace.selectedBodyPart == null)
|
||||
{ keyframe.BodyFacing = facing; }
|
||||
|
||||
else if (Workspace.selectedBodyPart.isHead)
|
||||
{ keyframe.HeadFacing = facing; }
|
||||
|
||||
Workspace.GetCurrentPawnAnimationClip().BuildSimpleCurves();
|
||||
Workspace.RecordEvent("Actor position / orientation");
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Cards/ActorKeyframeCard.cs.meta
Normal file
11
Assets/Scripts/GUI/Cards/ActorKeyframeCard.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 58ad3d066d9103541806d07bc98823d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/GUI/Cards/AnimationDefCard.cs
Normal file
39
Assets/Scripts/GUI/Cards/AnimationDefCard.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
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 AnimationDefCard : MonoBehaviour
|
||||
{
|
||||
public InputField defNameField;
|
||||
public InputField labelField;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
EventsManager.onAnimationDefChanged.AddListener(delegate { UpdateInputFields(); });
|
||||
|
||||
defNameField.onEndEdit.AddListener(delegate {
|
||||
Workspace.animationDef.DefName = defNameField.text;
|
||||
Workspace.MakeHistoricRecord("AnimationDef update");
|
||||
});
|
||||
|
||||
labelField.onEndEdit.AddListener(delegate {
|
||||
Workspace.animationDef.Label = labelField.text;
|
||||
Workspace.MakeHistoricRecord("AnimationDef update");
|
||||
});
|
||||
|
||||
UpdateInputFields();
|
||||
}
|
||||
|
||||
public void UpdateInputFields()
|
||||
{
|
||||
defNameField.SetTextWithoutNotify(Workspace.animationDef.DefName);
|
||||
labelField.SetTextWithoutNotify(Workspace.animationDef.Label);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Cards/AnimationDefCard.cs.meta
Normal file
11
Assets/Scripts/GUI/Cards/AnimationDefCard.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1d8f33927e6b4d44914a445362b802d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/Scripts/GUI/Cards/StageCard.cs
Normal file
63
Assets/Scripts/GUI/Cards/StageCard.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class StageCard : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
public Text stageName;
|
||||
public InputField stageNameField;
|
||||
public Image banner;
|
||||
|
||||
public void OnNameChange()
|
||||
{
|
||||
stageName.text = stageNameField.text;
|
||||
stageNameField.gameObject.SetActive(false);
|
||||
|
||||
Workspace.GetCurrentAnimationStage().StageName = stageName.text;
|
||||
Workspace.RecordEvent("Stage renamed");
|
||||
}
|
||||
|
||||
public void OnMoveStage(int delta)
|
||||
{
|
||||
int siblingCount = transform.parent.childCount;
|
||||
int index = Mathf.Clamp(transform.GetSiblingIndex() + delta, 0, siblingCount - 1);
|
||||
|
||||
transform.SetSiblingIndex(index);
|
||||
}
|
||||
|
||||
public void Initialize(string stageName)
|
||||
{
|
||||
this.stageName.text = stageName;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Workspace.StageID == transform.GetSiblingIndex())
|
||||
{ banner.gameObject.SetActive(true); }
|
||||
|
||||
else
|
||||
{
|
||||
banner.gameObject.SetActive(false);
|
||||
stageNameField.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.clickCount >= 2)
|
||||
{
|
||||
stageNameField.text = stageName.text;
|
||||
stageNameField.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (Workspace.StageID != transform.GetSiblingIndex())
|
||||
{ Workspace.RecordEvent("Stage selected"); }
|
||||
|
||||
Workspace.StageID = transform.GetSiblingIndex();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Cards/StageCard.cs.meta
Normal file
11
Assets/Scripts/GUI/Cards/StageCard.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20b2be62d5fdc4b4992cede005ec2aee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue