2024-04-17 23:57:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using RimWorld;
|
|
|
|
|
using rjw;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Verse;
|
|
|
|
|
using Verse.AI;
|
|
|
|
|
using Verse.Sound;
|
|
|
|
|
|
|
|
|
|
namespace Rimworld_Animations {
|
|
|
|
|
public class CompExtendedAnimator : ThingComp
|
|
|
|
|
{
|
2024-04-18 22:32:31 +00:00
|
|
|
|
|
|
|
|
|
// CompExtendedAnimator
|
|
|
|
|
// Helps manage AnimationQueue, AbsolutePosition
|
2024-04-19 00:40:06 +00:00
|
|
|
|
//ticks of current animation
|
|
|
|
|
private int animationTicks;
|
|
|
|
|
|
2024-04-18 22:32:31 +00:00
|
|
|
|
private List<AnimationDef> animationQueue;
|
|
|
|
|
private BaseExtendedAnimatorAnchor anchor;
|
|
|
|
|
private bool isAnimating = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsAnimating
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return isAnimating;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAnchored
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return anchor != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector3 getAnchor()
|
|
|
|
|
{
|
|
|
|
|
return anchor.getDrawPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void CompTick()
|
|
|
|
|
{
|
|
|
|
|
if (isAnimating)
|
|
|
|
|
{
|
|
|
|
|
animationTicks++;
|
|
|
|
|
|
|
|
|
|
//if animationticks is equal to cur. anim duration,
|
|
|
|
|
if (animationTicks >= animationQueue[0].durationTicks)
|
|
|
|
|
{
|
|
|
|
|
//dequeue; returns false if more animations
|
|
|
|
|
if (!PopAnimationQueue())
|
|
|
|
|
{
|
|
|
|
|
//play next if more anims still
|
|
|
|
|
PlayNextAnimation();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StopAnimating();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.CompTick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//returns false if still more animations
|
|
|
|
|
public bool PopAnimationQueue()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!animationQueue.Empty())
|
|
|
|
|
{
|
|
|
|
|
//pop queue
|
|
|
|
|
animationQueue.RemoveAt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return animationQueue.Empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayNextAnimation()
|
|
|
|
|
{
|
|
|
|
|
if (!animationQueue.Empty())
|
|
|
|
|
{
|
|
|
|
|
isAnimating = true;
|
|
|
|
|
animationTicks = 0;
|
|
|
|
|
pawn.Drawer.renderer.SetAnimation(animationQueue[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopAnimating()
|
|
|
|
|
{
|
|
|
|
|
isAnimating = false;
|
|
|
|
|
animationQueue = null;
|
|
|
|
|
anchor = null;
|
|
|
|
|
pawn.Drawer.renderer.SetAnimation(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayGroupAnimation(List<AnimationDef> groupAnimation)
|
|
|
|
|
{
|
|
|
|
|
animationQueue = groupAnimation;
|
|
|
|
|
PlayNextAnimation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayGroupAnimation(List<AnimationDef> groupAnimation, BaseExtendedAnimatorAnchor anchor)
|
|
|
|
|
{
|
|
|
|
|
this.anchor = anchor;
|
2024-04-19 00:40:06 +00:00
|
|
|
|
PlayGroupAnimation(groupAnimation);
|
2024-04-18 22:32:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PostExposeData()
|
|
|
|
|
{
|
|
|
|
|
base.PostExposeData();
|
|
|
|
|
Scribe_Values.Look<bool>(ref this.isAnimating, "animations_isAnimating", false);
|
2024-04-19 00:40:06 +00:00
|
|
|
|
Scribe_Values.Look<int>(ref this.animationTicks, "animations_ticks", 0);
|
2024-04-18 22:32:31 +00:00
|
|
|
|
Scribe_Collections.Look<AnimationDef>(ref animationQueue, "animations_queue");
|
|
|
|
|
Scribe_Deep.Look<BaseExtendedAnimatorAnchor>(ref this.anchor, "animations_anchor");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 00:23:31 +00:00
|
|
|
|
public override List<PawnRenderNode> CompRenderNodes()
|
2024-04-19 00:40:06 +00:00
|
|
|
|
{
|
2024-04-21 00:23:31 +00:00
|
|
|
|
//only if pawn is animating for performance
|
|
|
|
|
if (IsAnimating)
|
|
|
|
|
{
|
|
|
|
|
List<PawnRenderNode> animRenderNodes = new List<PawnRenderNode>();
|
|
|
|
|
|
|
|
|
|
// for all animationpropdefs,
|
|
|
|
|
foreach (AnimationPropDef animationProp in DefDatabase<AnimationPropDef>.AllDefsListForReading)
|
|
|
|
|
{
|
|
|
|
|
//if animation makes use of prop,
|
|
|
|
|
if (AnimationMakesUseOfProp(animationProp))
|
|
|
|
|
{
|
|
|
|
|
//create new render node
|
|
|
|
|
PawnRenderNode animRenderNode = new PawnRenderNode(pawn, animationProp.animPropProperties, pawn.Drawer.renderer.renderTree);
|
|
|
|
|
animRenderNodes.Add(animRenderNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return list of rendernodes that should animate
|
|
|
|
|
return animRenderNodes;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-19 00:40:06 +00:00
|
|
|
|
|
2024-04-21 00:23:31 +00:00
|
|
|
|
public bool AnimationMakesUseOfProp(AnimationPropDef animationProp)
|
|
|
|
|
{
|
|
|
|
|
// never true if not animating; anim props shouldn't be attached
|
|
|
|
|
if (!IsAnimating) return false;
|
|
|
|
|
|
|
|
|
|
//for all queued animations,
|
|
|
|
|
foreach (AnimationDef animation in animationQueue)
|
|
|
|
|
{
|
|
|
|
|
// for each prop tag in the currently playing animation,
|
|
|
|
|
foreach (PawnRenderNodeTagDef propTag in animation.animationParts.Keys)
|
|
|
|
|
{
|
|
|
|
|
// if that proptag is the same as the one for animationProp,
|
|
|
|
|
if (propTag == animationProp.animPropProperties.tagDef)
|
|
|
|
|
{
|
|
|
|
|
//that prop is being used in the animation
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2024-04-19 00:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 22:32:31 +00:00
|
|
|
|
private Pawn pawn => base.parent as Pawn;
|
2024-04-17 23:57:18 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|