mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Added editable stage lengths
This commit is contained in:
parent
8523abf957
commit
d2ca61c61c
194 changed files with 820 additions and 269 deletions
|
@ -21,8 +21,8 @@ namespace RimWorldAnimationStudio
|
|||
public Dropdown stageLoopDropdown;
|
||||
public InputField cyclesNormalField;
|
||||
public InputField cyclesFastField;
|
||||
public Text stageTickText;
|
||||
public Text stageLengthText;
|
||||
public InputField animationClipTimeField;
|
||||
public InputField animationClipLengthField;
|
||||
public ActorCard actorCard;
|
||||
public Transform animationTimelines;
|
||||
|
||||
|
@ -54,33 +54,38 @@ namespace RimWorldAnimationStudio
|
|||
timeSinceLastUpdate -= 1f / 60f;
|
||||
stageTick += 1;
|
||||
|
||||
if (stageTick > Workspace.animationClipWindowSize)
|
||||
stageTimelineSlider.value = stageTick;
|
||||
animationClipTimeField.text = stageTick.ToString();
|
||||
|
||||
if (stageTick > Workspace.StageWindowSize)
|
||||
{
|
||||
if (stageLoopDropdown.value == 1)
|
||||
{ stageTick = 1; }
|
||||
|
||||
else if (stageLoopDropdown.value == 2 && Workspace.stageID < Workspace.animationDef.animationStages.Count - 1)
|
||||
else if (stageLoopDropdown.value >= 2 && Workspace.stageID < Workspace.animationDef.animationStages.Count - 1)
|
||||
{
|
||||
++cycleIndex;
|
||||
stageTick = 1;
|
||||
|
||||
if (cycleIndex > int.Parse(cyclesNormalField.text))
|
||||
if ((stageLoopDropdown.value == 2 && cycleIndex > int.Parse(cyclesNormalField.text)) ||
|
||||
(stageLoopDropdown.value == 3 && cycleIndex > int.Parse(cyclesFastField.text)))
|
||||
{
|
||||
++Workspace.stageID;
|
||||
cycleIndex = 0;
|
||||
|
||||
ResetAnimationTimeline();
|
||||
InitializeAnimationTimeline();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{ stageTick = Workspace.animationClipWindowSize; }
|
||||
{ stageTick = Workspace.StageWindowSize; }
|
||||
}
|
||||
}
|
||||
|
||||
// Update stage timeline
|
||||
stageTimelineSlider.maxValue = Workspace.animationClipWindowSize;
|
||||
stageTimelineSlider.value = stageTick;
|
||||
stageTickText.text = stageTick.ToString();
|
||||
stageLengthText.text = Workspace.animationClipWindowSize.ToString();
|
||||
animationClipTimeField.interactable = isAnimating == false;
|
||||
animationClipLengthField.interactable = isAnimating == false;
|
||||
|
||||
// Update animation
|
||||
UpdateAnimation();
|
||||
|
@ -150,10 +155,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void InitializeAnimationTimeline()
|
||||
{
|
||||
Workspace.animationClipWindowSize = Workspace.animationDef.animationStages[Workspace.stageID].animationClips.Select(x => x.duration).Max();
|
||||
|
||||
cyclesNormalField.text = Mathf.Max(Mathf.CeilToInt((float)Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicks / Workspace.animationClipWindowSize), 1).ToString();
|
||||
cyclesFastField.text = Mathf.Max(Mathf.CeilToInt((float)Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicksQuick / Workspace.animationClipWindowSize), 1).ToString();
|
||||
cyclesNormalField.text = Mathf.Max(Mathf.CeilToInt((float)Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicks / Workspace.StageWindowSize), 1).ToString();
|
||||
cyclesFastField.text = Mathf.Max(Mathf.CeilToInt((float)Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicksQuick / Workspace.StageWindowSize), 1).ToString();
|
||||
|
||||
for (int actorID = 0; actorID < Workspace.animationDef.actors.Count; actorID++)
|
||||
{
|
||||
|
@ -164,7 +167,9 @@ namespace RimWorldAnimationStudio
|
|||
animationTimeline.Initialize(actorID);
|
||||
}
|
||||
|
||||
stageTimelineSlider.maxValue = Workspace.animationClipWindowSize;
|
||||
animationClipLengthField.text = Workspace.StageWindowSize.ToString();
|
||||
animationClipTimeField.text = "1";
|
||||
stageTimelineSlider.maxValue = Workspace.StageWindowSize;
|
||||
stageTimelineSlider.value = 1;
|
||||
stageTick = 1;
|
||||
}
|
||||
|
@ -299,13 +304,21 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void RemovePawnKeyframe()
|
||||
{
|
||||
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(false);
|
||||
RemovePawnKeyframe(Workspace.actorID, Workspace.keyframeID);
|
||||
}
|
||||
|
||||
public void RemovePawnKeyframe(int actorID, int keyframeID)
|
||||
{
|
||||
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
|
||||
|
||||
if (keyframe.atTick == 1)
|
||||
{ Debug.LogWarning("Cannot delete key frame - the first key frame of an animation cannot be deleted"); return; }
|
||||
|
||||
if (keyframe != null)
|
||||
{
|
||||
animationTimelines.GetChild(Workspace.actorID).GetComponent<AnimationTimeline>().RemovePawnKeyFrame(keyframe.keyframeID);
|
||||
animationTimelines.GetChild(actorID).GetComponent<AnimationTimeline>().RemovePawnKeyFrame(keyframe.keyframeID);
|
||||
|
||||
PawnAnimationClip clip = Workspace.Instance.GetCurrentPawnAnimationClip();
|
||||
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID];
|
||||
clip.keyframes.Remove(keyframe);
|
||||
clip.BuildSimpleCurves();
|
||||
}
|
||||
|
@ -316,18 +329,78 @@ namespace RimWorldAnimationStudio
|
|||
isAnimating = !isAnimating;
|
||||
}
|
||||
|
||||
public void UpdateFromStageTimelineSlider()
|
||||
{
|
||||
if (Workspace.animationDef == null)
|
||||
{ return; }
|
||||
|
||||
if (stageTick != (int)stageTimelineSlider.value)
|
||||
{ stageTick = (int)stageTimelineSlider.value; }
|
||||
}
|
||||
|
||||
public void ToggleActorManipulationMode(int mode)
|
||||
{
|
||||
Workspace.actorManipulationMode = (ActorManipulationMode)mode;
|
||||
}
|
||||
|
||||
public void OnStageTimelineSliderChange()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
if (stageTick != (int)stageTimelineSlider.value)
|
||||
{
|
||||
stageTick = (int)stageTimelineSlider.value;
|
||||
animationClipTimeField.text = stageTick.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAnimationClipTimeFieldChange()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
int.TryParse(animationClipTimeField.text, out int newStageTick);
|
||||
stageTick = Mathf.Clamp(newStageTick, 1, Workspace.StageWindowSize);
|
||||
stageTimelineSlider.value = stageTick;
|
||||
}
|
||||
|
||||
public void OnAnimationClipLengthFieldChange()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
int.TryParse(animationClipLengthField.text, out int newstageWindowSize);
|
||||
newstageWindowSize = Mathf.Clamp(newstageWindowSize, Constants.minAnimationClipLength, Constants.maxAnimationClipLength);
|
||||
|
||||
Debug.Log("Resizing animation clip length to " + newstageWindowSize.ToString() + " ticks.");
|
||||
|
||||
for (int i = 0; i < Workspace.animationDef.animationStages[Workspace.stageID].animationClips.Count; i++)
|
||||
{
|
||||
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[i];
|
||||
List<PawnKeyframe> keyframes = clip.keyframes.Where(x => x.atTick > newstageWindowSize)?.ToList();
|
||||
|
||||
if (keyframes.NullOrEmpty())
|
||||
{ continue; }
|
||||
|
||||
foreach (PawnKeyframe keyframe in keyframes)
|
||||
{
|
||||
RemovePawnKeyframe(i, keyframe.keyframeID);
|
||||
|
||||
if (Workspace.animationDef.animationStages[Workspace.stageID].animationClips[i].keyframes.Count <= 2)
|
||||
{ break; }
|
||||
}
|
||||
}
|
||||
|
||||
animationClipLengthField.text = newstageWindowSize.ToString();
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].stageWindowSize = newstageWindowSize;
|
||||
|
||||
ResetAnimationTimeline();
|
||||
InitializeAnimationTimeline();
|
||||
}
|
||||
|
||||
public void OnCycleNormalFieldChange()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
if (int.TryParse(cyclesNormalField.text, out int cycles))
|
||||
{ Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicks = cycles * Workspace.StageWindowSize; }
|
||||
}
|
||||
|
||||
public void OnCycleFastFieldChange()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
if (int.TryParse(cyclesFastField.text, out int cycles))
|
||||
{ Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicksQuick = cycles * Workspace.StageWindowSize; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue