mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Ghost frames fix plus undo redo system
This commit is contained in:
parent
591b176924
commit
b0a965e0b2
163 changed files with 948 additions and 214 deletions
|
@ -1,5 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
@ -13,6 +14,9 @@ namespace RimWorldAnimationStudio
|
|||
public InputField bodyOffsetZField;
|
||||
public Toggle initiatorToggle;
|
||||
|
||||
private int actorID = -1;
|
||||
private bool isDirty = false;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
||||
|
@ -24,15 +28,30 @@ namespace RimWorldAnimationStudio
|
|||
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
|
||||
}
|
||||
|
||||
public void UpdateAnimationDef()
|
||||
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;
|
||||
Debug.Log(bodyType);
|
||||
AnimationController.Instance.transform.GetChild(Workspace.actorID).GetComponent<ActorBody>().bodyType = bodyType;
|
||||
|
||||
|
||||
AnimationController.Instance.GetComponentsInChildren<ActorBody>()[Workspace.actorID].bodyType = bodyType;
|
||||
|
||||
bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString();
|
||||
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
|
||||
}
|
||||
|
||||
public void UpdateAnimationDef()
|
||||
{
|
||||
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;
|
||||
|
||||
float.TryParse(bodyOffsetXField.text, out float x);
|
||||
float.TryParse(bodyOffsetZField.text, out float z);
|
||||
actor.bodyTypeOffset.SetOffset(bodyType, new Vector2(x, z));
|
||||
|
@ -42,6 +61,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void OpenSelectBodyPartsDialog()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
||||
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectBodyPartsDialog)) as SelectBodyPartsDialog[];
|
||||
|
||||
|
@ -51,6 +72,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void OpenSelectDefNamesDialog()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
||||
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectDefNamesDialog)) as SelectDefNamesDialog[];
|
||||
|
||||
|
@ -60,11 +83,42 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void OpenSelectBodyDefTypesDialog()
|
||||
{
|
||||
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(); }
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
if (actorID != Workspace.actorID)
|
||||
{
|
||||
isDirty = true;
|
||||
|
||||
if (Workspace.actorID >= AnimationController.Instance.GetComponentsInChildren<ActorBody>().Count())
|
||||
{ Debug.Log("Waiting for actors to initialize..."); return; }
|
||||
|
||||
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
||||
ActorBody actorBody = AnimationController.Instance.GetComponentsInChildren<ActorBody>()[Workspace.actorID];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,5 +63,10 @@ namespace RimWorldAnimationStudio
|
|||
else
|
||||
{ GetComponent<Image>().color = Constants.ColorGrey; }
|
||||
}
|
||||
|
||||
public void InitiateUpdateOfGhostFrames()
|
||||
{
|
||||
BroadcastMessage("UpdateGhostFrames");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace RimWorldAnimationStudio
|
|||
Transform contentWindow = transform.FindDeepChild("Content");
|
||||
Reset();
|
||||
|
||||
for (int i = 0; i < Workspace.bodyParts.Count; i++)
|
||||
for (int i = 0; i < Workspace.interactionDefTypes.Count; i++)
|
||||
{
|
||||
string interactionDefType = Workspace.interactionDefTypes[i];
|
||||
|
||||
|
|
|
@ -43,12 +43,11 @@ namespace RimWorldAnimationStudio
|
|||
public void OnValueChanged()
|
||||
{
|
||||
keyframe.atTick = (int)value;
|
||||
|
||||
UpdateGhostFrames();
|
||||
|
||||
clip.BuildSimpleCurves();
|
||||
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
|
||||
timeline.InitiateUpdateOfGhostFrames();
|
||||
}
|
||||
|
||||
// Ghost sliders are non-interactable slider handle
|
||||
|
@ -57,27 +56,25 @@ namespace RimWorldAnimationStudio
|
|||
if (maxGhosts == 0)
|
||||
{ return; }
|
||||
|
||||
int nGhosts = GetGhostFramesRequired();
|
||||
int requiredGhosts = GetGhostFramesRequired();
|
||||
int currentGhostCount = ghostSliders.childCount;
|
||||
|
||||
for (int i = 0; i < Mathf.Max(nGhosts, ghostSliders.childCount); i++)
|
||||
for (int i = 0; i < Mathf.Max(requiredGhosts, currentGhostCount); i++)
|
||||
{
|
||||
if ((i - 1) * clip.duration + keyframe.atTick <= Workspace.StageWindowSize)
|
||||
{
|
||||
if (ghostSliders.childCount <= i)
|
||||
{ Instantiate(ghostSliderPrefab, ghostSliders); }
|
||||
int targetTick = (int)(i * clip.duration + keyframe.atTick);
|
||||
|
||||
GameObject ghostSliderObject = ghostSliders.GetChild(i).gameObject;
|
||||
ghostSliderObject.SetActive(true);
|
||||
if (ghostSliders.childCount <= i)
|
||||
{ Instantiate(ghostSliderPrefab, ghostSliders); }
|
||||
|
||||
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
|
||||
ghostSlider.value = (int)((i + 1) * clip.duration + keyframe.atTick);
|
||||
GameObject ghostSliderObject = ghostSliders.GetChild(i).gameObject;
|
||||
ghostSliderObject.SetActive(i < requiredGhosts);
|
||||
|
||||
float mult = 1f - Mathf.Pow((float)i / maxGhosts, 2);
|
||||
ghostSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0, 0.5f, 0.5f, 0.5f * mult);
|
||||
}
|
||||
|
||||
if (i >= nGhosts)
|
||||
{ transform.GetChild(i).gameObject.SetActive(false); }
|
||||
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
|
||||
ghostSlider.maxValue = Workspace.StageWindowSize;
|
||||
ghostSlider.value = targetTick;
|
||||
|
||||
if (targetTick > ghostSlider.maxValue)
|
||||
{ ghostSlider.gameObject.SetActive(false); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,9 +95,9 @@ namespace RimWorldAnimationStudio
|
|||
Workspace.keyframeID = keyframeID;
|
||||
|
||||
if (eventData.clickCount >= 2)
|
||||
{
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
}
|
||||
{ AnimationController.Instance.stageTick = keyframe.atTick.Value; }
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
|
@ -126,6 +123,8 @@ namespace RimWorldAnimationStudio
|
|||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
interactable = false;
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
|
|
|
@ -16,6 +16,10 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
stageName.text = stageNameField.text;
|
||||
stageNameField.gameObject.SetActive(false);
|
||||
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].stageName = stageName.text;
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void OnMoveStage(int delta)
|
||||
|
@ -60,8 +64,7 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
Workspace.stageID = transform.GetSiblingIndex();
|
||||
|
||||
//AnimationController.Instance.ResetAnimationTimeline();
|
||||
//AnimationController.Instance.InitializeAnimationTimeline();
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue