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;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
public Image handleImage;
|
|
|
|
|
public GameObject soundIcon;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
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
|
|
|
|
clip.BuildSimpleCurves();
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
|
|
|
|
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
2022-09-19 00:07:44 +00:00
|
|
|
|
|
|
|
|
|
timeline.InitiateUpdateOfGhostFrames();
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ghost sliders are non-interactable slider handle
|
|
|
|
|
public void UpdateGhostFrames()
|
|
|
|
|
{
|
|
|
|
|
if (maxGhosts == 0)
|
|
|
|
|
{ return; }
|
|
|
|
|
|
2022-09-19 00:07:44 +00:00
|
|
|
|
int requiredGhosts = GetGhostFramesRequired();
|
|
|
|
|
int currentGhostCount = ghostSliders.childCount;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-09-19 00:07:44 +00:00
|
|
|
|
for (int i = 0; i < Mathf.Max(requiredGhosts, currentGhostCount); i++)
|
2022-09-16 14:18:06 +00:00
|
|
|
|
{
|
2022-09-19 00:07:44 +00:00
|
|
|
|
int targetTick = (int)(i * clip.duration + keyframe.atTick);
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-09-19 00:07:44 +00:00
|
|
|
|
if (ghostSliders.childCount <= i)
|
|
|
|
|
{ Instantiate(ghostSliderPrefab, ghostSliders); }
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-09-19 00:07:44 +00:00
|
|
|
|
GameObject ghostSliderObject = ghostSliders.GetChild(i).gameObject;
|
|
|
|
|
ghostSliderObject.SetActive(i < requiredGhosts);
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-09-19 00:07:44 +00:00
|
|
|
|
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
|
|
|
|
|
ghostSlider.maxValue = Workspace.StageWindowSize;
|
|
|
|
|
ghostSlider.value = targetTick;
|
|
|
|
|
|
|
|
|
|
if (targetTick > ghostSlider.maxValue)
|
|
|
|
|
{ ghostSlider.gameObject.SetActive(false); }
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
2022-09-19 00:07:44 +00:00
|
|
|
|
{ AnimationController.Instance.stageTick = keyframe.atTick.Value; }
|
|
|
|
|
|
2022-09-21 05:40:58 +00:00
|
|
|
|
//Workspace.Instance.RecordEvent("Keyframe selected");
|
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
|
|
|
|
public override void OnDrag(PointerEventData eventData)
|
2022-09-16 22:50:15 +00:00
|
|
|
|
{
|
2022-09-26 05:50:26 +00:00
|
|
|
|
if (keyframe.atTick == 1)
|
|
|
|
|
{ value = 1; return; }
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2022-09-26 05:50:26 +00:00
|
|
|
|
if (keyframe.atTick == 1)
|
|
|
|
|
{ value = 1; return; }
|
2022-09-19 00:07:44 +00:00
|
|
|
|
|
2022-09-21 05:40:58 +00:00
|
|
|
|
Workspace.Instance.RecordEvent("Keyframe tick");
|
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-20 06:03:55 +00:00
|
|
|
|
if (keyframe.atTick.HasValue && Workspace.keyframeID == keyframeID && AnimationController.Instance.stageTick == keyframe.atTick.Value)
|
|
|
|
|
{ handleImage.color = Constants.ColorPurple; }
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
else if (Workspace.keyframeID == keyframeID)
|
2022-09-20 06:03:55 +00:00
|
|
|
|
{ handleImage.color = Constants.ColorCyan; }
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-20 06:03:55 +00:00
|
|
|
|
else if (keyframe.atTick.HasValue && AnimationController.Instance.stageTick == keyframe.atTick.Value)
|
|
|
|
|
{ handleImage.color = Constants.ColorPink; }
|
2022-09-18 06:52:54 +00:00
|
|
|
|
|
|
|
|
|
else
|
2022-09-20 06:03:55 +00:00
|
|
|
|
{ handleImage.color = Constants.ColorWhite; }
|
|
|
|
|
|
2022-09-21 05:40:58 +00:00
|
|
|
|
string soundDef = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID)?.soundEffect;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
|
|
|
|
|
if (soundDef != null && soundDef != "" && soundDef != "None")
|
|
|
|
|
{ soundIcon.SetActive(true); }
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{ soundIcon.SetActive(false); }
|
2022-09-18 00:06:33 +00:00
|
|
|
|
}
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|