2022-09-16 14:18:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
using UnityEngine.EventSystems;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace RimWorldAnimationStudio
|
|
|
|
|
{
|
2022-09-16 22:50:15 +00:00
|
|
|
|
public class KeyframeSlider : Slider, IPointerClickHandler, IBeginDragHandler, IEndDragHandler
|
2022-09-16 14:18:06 +00:00
|
|
|
|
{
|
|
|
|
|
public AnimationTimeline timeline;
|
|
|
|
|
public Transform ghostSliders;
|
|
|
|
|
public Slider ghostSliderPrefab;
|
|
|
|
|
public int maxGhosts = 4;
|
|
|
|
|
|
|
|
|
|
public int actorID;
|
|
|
|
|
public int keyframeID;
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
private PawnAnimationClip clip;
|
|
|
|
|
private PawnKeyframe keyframe;
|
|
|
|
|
|
2022-09-16 14:18:06 +00:00
|
|
|
|
public void Initialize(AnimationTimeline timeline, int actorID, int keyframeID)
|
|
|
|
|
{
|
|
|
|
|
this.timeline = timeline;
|
2022-09-18 00:06:33 +00:00
|
|
|
|
this.clip = Workspace.Instance.GetPawnAnimationClip(actorID);
|
|
|
|
|
this.keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
|
|
|
|
this.actorID = actorID;
|
|
|
|
|
this.keyframeID = keyframeID;
|
|
|
|
|
|
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
|
2022-09-18 05:01:12 +00:00
|
|
|
|
maxValue = Workspace.StageWindowSize;
|
2022-09-18 00:06:33 +00:00
|
|
|
|
value = keyframe.atTick.Value;
|
|
|
|
|
|
2022-09-16 14:18:06 +00:00
|
|
|
|
OnValueChanged();
|
|
|
|
|
|
|
|
|
|
onValueChanged.AddListener(delegate (float value) { OnValueChanged(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnValueChanged()
|
|
|
|
|
{
|
2022-09-18 00:06:33 +00:00
|
|
|
|
keyframe.atTick = (int)value;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
|
|
|
|
UpdateGhostFrames();
|
|
|
|
|
|
|
|
|
|
clip.BuildSimpleCurves();
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
|
|
|
|
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ghost sliders are non-interactable slider handle
|
|
|
|
|
public void UpdateGhostFrames()
|
|
|
|
|
{
|
|
|
|
|
if (maxGhosts == 0)
|
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
|
|
int nGhosts = GetGhostFramesRequired();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Mathf.Max(nGhosts, ghostSliders.childCount); i++)
|
|
|
|
|
{
|
2022-09-18 05:01:12 +00:00
|
|
|
|
if ((i - 1) * clip.duration + keyframe.atTick <= Workspace.StageWindowSize)
|
2022-09-16 14:18:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (ghostSliders.childCount <= i)
|
|
|
|
|
{ Instantiate(ghostSliderPrefab, ghostSliders); }
|
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
GameObject ghostSliderObject = ghostSliders.GetChild(i).gameObject;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
ghostSliderObject.SetActive(true);
|
|
|
|
|
|
|
|
|
|
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
|
2022-09-18 00:06:33 +00:00
|
|
|
|
ghostSlider.value = (int)((i + 1) * clip.duration + keyframe.atTick);
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
|
|
|
|
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); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetGhostFramesRequired()
|
|
|
|
|
{
|
|
|
|
|
if (Workspace.animationDef.animationStages[Workspace.stageID].isLooping == false)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
if (clip.duration <= 1)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
2022-09-18 05:01:12 +00:00
|
|
|
|
return Math.Min(Mathf.CeilToInt((float)Workspace.StageWindowSize / clip.duration), maxGhosts);
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
|
{
|
2022-09-18 06:52:54 +00:00
|
|
|
|
Workspace.actorID = actorID;
|
|
|
|
|
Workspace.keyframeID = keyframeID;
|
|
|
|
|
|
|
|
|
|
if (eventData.clickCount >= 2)
|
|
|
|
|
{
|
|
|
|
|
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
|
|
|
|
}
|
2022-09-18 00:06:33 +00:00
|
|
|
|
}
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
|
|
|
{
|
2022-09-18 06:52:54 +00:00
|
|
|
|
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
|
|
|
|
Workspace.actorID = actorID;
|
|
|
|
|
Workspace.keyframeID = keyframeID;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
if (keyframe.atTick == 1)
|
|
|
|
|
{ return; }
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
interactable = true;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
public override void OnDrag(PointerEventData eventData)
|
2022-09-16 22:50:15 +00:00
|
|
|
|
{
|
2022-09-18 00:06:33 +00:00
|
|
|
|
base.OnDrag(eventData);
|
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
|
|
|
|
Workspace.actorID = actorID;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
interactable = false;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
protected override void Update()
|
2022-09-18 00:06:33 +00:00
|
|
|
|
{
|
2022-09-18 06:52:54 +00:00
|
|
|
|
base.Update();
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
if (Workspace.keyframeID == keyframeID && AnimationController.Instance.stageTick == keyframe.atTick.Value)
|
|
|
|
|
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorPurple; }
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
else if (Workspace.keyframeID == keyframeID)
|
|
|
|
|
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorCyan; }
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
else if (AnimationController.Instance.stageTick == keyframe.atTick.Value)
|
|
|
|
|
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorPink; }
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorWhite; }
|
2022-09-18 00:06:33 +00:00
|
|
|
|
}
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|