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
|
@ -34,14 +34,22 @@ namespace RimWorldAnimationStudio
|
|||
private int lastStageTick = 1;
|
||||
private float timeSinceLastUpdate = 0;
|
||||
private int cycleIndex = 0;
|
||||
private bool isDirty = true;
|
||||
private bool isTimelineDirty = true;
|
||||
|
||||
public void MakeDirty()
|
||||
{ isDirty = true; }
|
||||
|
||||
public void MakeTimelineDirty()
|
||||
{ isTimelineDirty = true; }
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// No animation, exit
|
||||
if (Workspace.animationDef == null) { return; }
|
||||
|
||||
// Dirty animation, reset
|
||||
if (Workspace.animationDef != null && Workspace.isDirty)
|
||||
if (Workspace.animationDef != null && isDirty)
|
||||
{ Initialize(); return; }
|
||||
|
||||
// Update tick if animating
|
||||
|
@ -65,14 +73,11 @@ namespace RimWorldAnimationStudio
|
|||
++cycleIndex;
|
||||
stageTick = 1;
|
||||
|
||||
if ((stageLoopDropdown.value == 2 && cycleIndex > int.Parse(cyclesNormalField.text)) ||
|
||||
(stageLoopDropdown.value == 3 && cycleIndex > int.Parse(cyclesFastField.text)))
|
||||
if ((stageLoopDropdown.value == 2 && cycleIndex >= int.Parse(cyclesNormalField.text)) ||
|
||||
(stageLoopDropdown.value == 3 && cycleIndex >= int.Parse(cyclesFastField.text)))
|
||||
{
|
||||
++Workspace.stageID;
|
||||
cycleIndex = 0;
|
||||
|
||||
//ResetAnimationTimeline();
|
||||
//InitializeAnimationTimeline();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +104,7 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void UpdateAnimation()
|
||||
{
|
||||
if (Workspace.Instance.AnimationTimelinesNeedUpdate())
|
||||
if (AnimationTimelinesNeedUpdate())
|
||||
{
|
||||
ResetAnimationTimeline();
|
||||
InitializeAnimationTimeline();
|
||||
|
@ -109,6 +114,12 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
for (int actorID = 0; actorID < actorBodies.Count; actorID++)
|
||||
{
|
||||
if (Workspace.stageID >= Workspace.animationDef?.animationStages.Count)
|
||||
{ Debug.Log("Waiting for animation stage data to initialize..."); return; }
|
||||
|
||||
if (actorID >= Workspace.animationDef?.animationStages[Workspace.stageID]?.animationClips.Count)
|
||||
{ Debug.Log("Waiting for animation clip data to initialize..."); return; }
|
||||
|
||||
PawnAnimationClip clip = Workspace.animationDef?.animationStages[Workspace.stageID]?.animationClips[actorID];
|
||||
|
||||
if (clip == null)
|
||||
|
@ -162,7 +173,7 @@ namespace RimWorldAnimationStudio
|
|||
InitializeAnimationTimeline();
|
||||
StageCardManager.Instance.Initialize();
|
||||
|
||||
Workspace.isDirty = false;
|
||||
isDirty = false;
|
||||
}
|
||||
|
||||
public void InitializeAnimationTimeline()
|
||||
|
@ -184,6 +195,8 @@ namespace RimWorldAnimationStudio
|
|||
stageTimelineSlider.maxValue = Workspace.StageWindowSize;
|
||||
stageTimelineSlider.value = 1;
|
||||
stageTick = 1;
|
||||
|
||||
isTimelineDirty = false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
|
@ -209,7 +222,9 @@ namespace RimWorldAnimationStudio
|
|||
public bool AddAnimationStage()
|
||||
{
|
||||
AnimationStage stage = new AnimationStage();
|
||||
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
|
||||
return stage.MakeNew();
|
||||
}
|
||||
|
||||
|
@ -221,6 +236,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
Workspace.animationDef.animationStages.Insert(Workspace.stageID + 1, stage);
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -233,6 +250,8 @@ namespace RimWorldAnimationStudio
|
|||
Workspace.animationDef.animationStages[startIndex] = Workspace.animationDef.animationStages[startIndex + delta];
|
||||
Workspace.animationDef.animationStages[startIndex + delta] = stage;
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -247,15 +266,17 @@ namespace RimWorldAnimationStudio
|
|||
Workspace.animationDef.animationStages.RemoveAt(Workspace.stageID);
|
||||
Workspace.stageID = Workspace.stageID >= Workspace.animationDef.animationStages.Count ? Workspace.stageID = Workspace.animationDef.animationStages.Count - 1 : Workspace.stageID;
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddActor()
|
||||
{
|
||||
Actor actor = new Actor();
|
||||
actor.MakeNew();
|
||||
|
||||
if (actor.MakeNew())
|
||||
{ Initialize(); }
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void RemoveActor()
|
||||
|
@ -272,7 +293,7 @@ namespace RimWorldAnimationStudio
|
|||
Workspace.animationDef.actors.RemoveAt(Workspace.actorID);
|
||||
Workspace.actorID = Workspace.actorID >= Workspace.animationDef.actors.Count ? Workspace.actorID = Workspace.animationDef.actors.Count - 1 : Workspace.actorID;
|
||||
|
||||
Initialize();
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void AddPawnKeyframe()
|
||||
|
@ -311,11 +332,15 @@ namespace RimWorldAnimationStudio
|
|||
clip.BuildSimpleCurves();
|
||||
|
||||
animationTimelines.GetComponentsInChildren<AnimationTimeline>()[Workspace.actorID].AddPawnKeyFrame(keyframe.keyframeID);
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void RemovePawnKeyframe()
|
||||
{
|
||||
RemovePawnKeyframe(Workspace.actorID, Workspace.keyframeID);
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void RemovePawnKeyframe(int actorID, int keyframeID)
|
||||
|
@ -333,6 +358,8 @@ namespace RimWorldAnimationStudio
|
|||
clip.keyframes.Remove(keyframe);
|
||||
clip.BuildSimpleCurves();
|
||||
}
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void ToggleAnimation()
|
||||
|
@ -363,6 +390,8 @@ namespace RimWorldAnimationStudio
|
|||
int.TryParse(animationClipTimeField.text, out int newStageTick);
|
||||
stageTick = Mathf.Clamp(newStageTick, 1, Workspace.StageWindowSize);
|
||||
stageTimelineSlider.value = stageTick;
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void OnAnimationClipLengthFieldChange()
|
||||
|
@ -394,8 +423,7 @@ namespace RimWorldAnimationStudio
|
|||
animationClipLengthField.text = newstageWindowSize.ToString();
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].stageWindowSize = newstageWindowSize;
|
||||
|
||||
//ResetAnimationTimeline();
|
||||
//InitializeAnimationTimeline();
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void OnCycleNormalFieldChange()
|
||||
|
@ -404,6 +432,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
if (int.TryParse(cyclesNormalField.text, out int cycles))
|
||||
{ Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicks = cycles * Workspace.StageWindowSize; }
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
public void OnCycleFastFieldChange()
|
||||
|
@ -412,6 +442,44 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
if (int.TryParse(cyclesFastField.text, out int cycles))
|
||||
{ Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicksQuick = cycles * Workspace.StageWindowSize; }
|
||||
|
||||
Workspace.Instance.MakeDirty();
|
||||
}
|
||||
|
||||
private int lastactorCount = 0;
|
||||
private int lastStageID = 0;
|
||||
private int lastStageCount = 0;
|
||||
private int lastStageWindowSize = 0;
|
||||
|
||||
public bool AnimationTimelinesNeedUpdate()
|
||||
{
|
||||
if (Workspace.animationDef == null) return false;
|
||||
|
||||
bool update = isTimelineDirty;
|
||||
|
||||
if (lastStageID != Workspace.stageID)
|
||||
{ update = true; }
|
||||
|
||||
if (lastStageCount != Workspace.animationDef.animationStages.Count)
|
||||
{ update = true; }
|
||||
|
||||
if (lastactorCount != Workspace.animationDef.actors.Count)
|
||||
{ update = true; }
|
||||
|
||||
if (lastStageWindowSize != Workspace.StageWindowSize)
|
||||
{ update = true; }
|
||||
|
||||
if (update)
|
||||
{
|
||||
lastStageID = Workspace.stageID;
|
||||
lastStageCount = Workspace.animationDef.animationStages.Count;
|
||||
lastactorCount = Workspace.animationDef.actors.Count;
|
||||
lastStageWindowSize = Workspace.StageWindowSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,15 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void LoadAnimation(AnimationDef animationDef)
|
||||
{
|
||||
animationDef.RunPostLoadOperations();
|
||||
Debug.Log("Loaded AnimationDef: " + animationDef.defName);
|
||||
|
||||
|
||||
Workspace.animationDef = animationDef;
|
||||
animationDef.Initialize();
|
||||
Workspace.isDirty = true;
|
||||
|
||||
Workspace.Instance.ClearHistory();
|
||||
Workspace.Instance.MakeDirty();
|
||||
AnimationController.Instance.MakeDirty();
|
||||
|
||||
var animationDefCards = Resources.FindObjectsOfTypeAll(typeof(AnimationDefCard)) as AnimationDefCard[];
|
||||
|
||||
|
@ -78,16 +82,8 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
Debug.Log("Saving AnimationDef: " + Workspace.animationDef.defName);
|
||||
|
||||
AnimationDef animationDef = Workspace.animationDef;
|
||||
|
||||
foreach (AnimationStage stage in animationDef.animationStages)
|
||||
{
|
||||
foreach (PawnAnimationClip clip in stage.animationClips)
|
||||
{
|
||||
clip.keyframes = clip.keyframes.OrderBy(x => x.atTick).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
AnimationDef animationDef = Workspace.animationDef.Copy();
|
||||
animationDef.RunPreSaveOperations();
|
||||
|
||||
Defs defs = new Defs();
|
||||
defs.animationDefs.Add(animationDef);
|
||||
|
@ -104,7 +100,7 @@ namespace RimWorldAnimationStudio
|
|||
// Add one stage, add one actor, add one clip, add one frame
|
||||
|
||||
Workspace.animationDef = new AnimationDef();
|
||||
Workspace.isDirty = true;
|
||||
Workspace.Instance.MakeDirty();
|
||||
|
||||
var animationDefCards = Resources.FindObjectsOfTypeAll(typeof(AnimationDefCard)) as GameObject[];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue