mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Multi-drag and stretching for keyframes
This commit is contained in:
parent
f449a9b4e2
commit
ab5a2a4c02
151 changed files with 195 additions and 85 deletions
|
@ -13,7 +13,7 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
[Header("Animation settings")]
|
||||
public bool isAnimating = false;
|
||||
public int stageTick = 1;
|
||||
public int stageTick = Constants.minTick;
|
||||
|
||||
[Header("Object references")]
|
||||
public Slider stageTimelineSlider;
|
||||
|
@ -25,7 +25,7 @@ namespace RimWorldAnimationStudio
|
|||
public ActorCard actorCard;
|
||||
public Transform animationTimelines;
|
||||
public Transform actorBodies;
|
||||
public Toggle stretchkeyframesToggle;
|
||||
public Toggle stretchKeyframesToggle;
|
||||
public InputField playBackSpeedField;
|
||||
public Button playToggleButton;
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace RimWorldAnimationStudio
|
|||
public GameObject animationTimelinePrefab;
|
||||
|
||||
// Private timing variables
|
||||
private int lastStageTick = 1;
|
||||
private int lastStageTick = Constants.minTick;
|
||||
private float timeSinceLastUpdate = 0;
|
||||
private int cycleIndex = 0;
|
||||
private bool isDirty = true;
|
||||
|
@ -57,7 +57,7 @@ namespace RimWorldAnimationStudio
|
|||
{ Initialize(); }
|
||||
|
||||
// Update tick if animating
|
||||
stageTick = Mathf.Clamp(stageTick, 1, Workspace.StageWindowSize);
|
||||
stageTick = Mathf.Clamp(stageTick, Constants.minTick, Workspace.StageWindowSize);
|
||||
|
||||
if (isAnimating)
|
||||
{
|
||||
|
@ -72,12 +72,12 @@ namespace RimWorldAnimationStudio
|
|||
if (stageTick > Workspace.StageWindowSize)
|
||||
{
|
||||
if (stageLoopDropdown.value == 1)
|
||||
{ stageTick = 1; }
|
||||
{ stageTick = Constants.minTick; }
|
||||
|
||||
else if (stageLoopDropdown.value >= 2)
|
||||
{
|
||||
++cycleIndex;
|
||||
stageTick = 1;
|
||||
stageTick = Constants.minTick;
|
||||
|
||||
if ((stageLoopDropdown.value == 2 && cycleIndex >= int.Parse(cyclesNormalField.text)) ||
|
||||
(stageLoopDropdown.value == 3 && cycleIndex >= int.Parse(cyclesFastField.text)))
|
||||
|
@ -148,7 +148,7 @@ namespace RimWorldAnimationStudio
|
|||
bool requiresGenitals = actor.requiredGenitals.Any(x => x == "Penis") || Workspace.animationDef.actors[actorID].isFucking;
|
||||
|
||||
float clipPercent = (float)(stageTick % clip.duration) / clip.duration;
|
||||
if (stageTick == clip.duration) clipPercent = 1f;
|
||||
if (stageTick > Constants.minTick && stageTick == clip.duration) clipPercent = 1f;
|
||||
|
||||
if (Workspace.animationDef.animationStages[Workspace.stageID].isLooping == false)
|
||||
{ clipPercent = (float)stageTick / clip.duration; }
|
||||
|
@ -401,7 +401,7 @@ namespace RimWorldAnimationStudio
|
|||
if (tickToPasteAt < 1) continue;
|
||||
if (tickToPasteAt > Workspace.StageWindowSize)
|
||||
{
|
||||
if (stretchkeyframesToggle.isOn)
|
||||
if (stretchKeyframesToggle.isOn)
|
||||
{ ResizeStageWindowSize(tickToPasteAt); }
|
||||
|
||||
else continue;
|
||||
|
@ -487,7 +487,7 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
if (keyframe == null || clip == null) return;
|
||||
|
||||
if (keyframe.atTick == 1 && force == false)
|
||||
if (keyframe.atTick == Constants.minTick && force == false)
|
||||
{ Debug.LogWarning("Cannot delete key frame - the first key frame of an animation clip cannot be deleted"); return; }
|
||||
|
||||
if (clip.keyframes.Count <= 2 && force == false)
|
||||
|
@ -527,7 +527,7 @@ namespace RimWorldAnimationStudio
|
|||
if (Workspace.animationDef == null) return;
|
||||
|
||||
int.TryParse(animationClipTimeField.text, out int newStageTick);
|
||||
stageTick = Mathf.Clamp(newStageTick, 1, Workspace.StageWindowSize);
|
||||
stageTick = Mathf.Clamp(newStageTick, Constants.minTick, Workspace.StageWindowSize);
|
||||
stageTimelineSlider.value = stageTick;
|
||||
}
|
||||
|
||||
|
@ -540,8 +540,11 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
Debug.Log("Resizing animation clip length to " + newStageWindowSize.ToString() + " ticks.");
|
||||
|
||||
if (stretchkeyframesToggle.isOn)
|
||||
{ StretchKeyframes(newStageWindowSize); }
|
||||
if (stretchKeyframesToggle.isOn)
|
||||
{
|
||||
List<PawnKeyframe> keyframes = Workspace.animationDef.animationStages[Workspace.stageID].animationClips.SelectMany(x => x.keyframes)?.ToList();
|
||||
StretchKeyframes(keyframes, Workspace.StageWindowSize, newStageWindowSize);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
@ -566,7 +569,7 @@ namespace RimWorldAnimationStudio
|
|||
ResizeStageWindowSize(newStageWindowSize);
|
||||
}
|
||||
|
||||
public void StretchKeyframes(int newStageWindowSize)
|
||||
/*public void StretchKeyframes(int newStageWindowSize)
|
||||
{
|
||||
float scale = (float)newStageWindowSize / Workspace.StageWindowSize;
|
||||
|
||||
|
@ -580,6 +583,39 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
clip.BuildSimpleCurves();
|
||||
}
|
||||
}*/
|
||||
|
||||
public void StretchKeyframes(List<PawnKeyframe> keyframesToStretch, int v1, int v2)
|
||||
{
|
||||
int v0 = keyframesToStretch.Min(x => x.atTick.Value);
|
||||
|
||||
if (v1 == v0)
|
||||
{ OffsetKeyframes(keyframesToStretch, v1, v2); return; }
|
||||
|
||||
float scaleFactor = (float)(v2 - v0) / (v1 - v0);
|
||||
|
||||
foreach (PawnKeyframe keyframe in keyframesToStretch)
|
||||
{
|
||||
keyframe.atTick = Mathf.RoundToInt(scaleFactor * (keyframe.atTick.Value - v0) + v0);
|
||||
}
|
||||
|
||||
foreach(PawnAnimationClip clip in Workspace.animationDef.animationStages[Workspace.stageID].animationClips)
|
||||
{ clip.BuildSimpleCurves(); }
|
||||
}
|
||||
|
||||
public void OffsetKeyframes(List<PawnKeyframe> keyframesToOffset, int v1, int v2)
|
||||
{
|
||||
float offset = v2 - v1;
|
||||
|
||||
foreach (PawnKeyframe keyframe in keyframesToOffset)
|
||||
{
|
||||
keyframe.atTick = Mathf.RoundToInt(keyframe.atTick.Value + offset);
|
||||
Debug.Log(keyframe.atTick);
|
||||
Workspace.Instance.GetAnimationClipThatOwnsKeyframe(keyframe.keyframeID, out int clipID).BuildSimpleCurves();
|
||||
}
|
||||
|
||||
foreach (PawnAnimationClip clip in Workspace.animationDef.animationStages[Workspace.stageID].animationClips)
|
||||
{ clip.BuildSimpleCurves(); }
|
||||
}
|
||||
|
||||
public void ResizeStageWindowSize(int newStageWindowSize)
|
||||
|
|
|
@ -341,19 +341,19 @@ namespace RimWorldAnimationStudio
|
|||
public void ToPreviousTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick - 1, 1, Workspace.StageWindowSize);
|
||||
AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick - 1, Constants.minTick, Workspace.StageWindowSize);
|
||||
}
|
||||
|
||||
public void ToNextTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick + 1, 1, Workspace.StageWindowSize);
|
||||
AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick + 1, Constants.minTick, Workspace.StageWindowSize);
|
||||
}
|
||||
|
||||
public void ToFirstTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.stageTick = 1;
|
||||
AnimationController.Instance.stageTick = Constants.minTick;
|
||||
}
|
||||
|
||||
public void ToLastTick()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue