mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	rotation, quick reset, better handling of offset values
This commit is contained in:
		
							parent
							
								
									2e18be1953
								
							
						
					
					
						commit
						f22f5ac33e
					
				
					 6 changed files with 66 additions and 26 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -21,9 +21,11 @@ namespace Rimworld_Animations {
 | 
			
		|||
        public Vector3 offset = new Vector2(0, 0);
 | 
			
		||||
 | 
			
		||||
        public Dictionary<string, Vector2> offsetsByDefName = new Dictionary<string, Vector2>();
 | 
			
		||||
        public Dictionary<string, float> rotationByDefName = new Dictionary<string, float>();
 | 
			
		||||
 | 
			
		||||
        public void ExposeData() {
 | 
			
		||||
            Scribe_Collections.Look(ref offsetsByDefName, "OffsetsSetInOptions", LookMode.Value, LookMode.Value);
 | 
			
		||||
            Scribe_Collections.Look(ref rotationByDefName, "RotationOffsetsFromOptions", LookMode.Value, LookMode.Value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,6 +52,12 @@ namespace Rimworld_Animations {
 | 
			
		|||
        private AnimationStage stage => anim.animationStages[curStage];
 | 
			
		||||
        private PawnAnimationClip clip => (PawnAnimationClip)stage.animationClips[actor];
 | 
			
		||||
 | 
			
		||||
        public bool Mirror {
 | 
			
		||||
            get {
 | 
			
		||||
                return mirror;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void setAnchor(IntVec3 pos)
 | 
			
		||||
        {
 | 
			
		||||
            anchor = pos.ToVector3Shifted();
 | 
			
		||||
| 
						 | 
				
			
			@ -172,6 +178,9 @@ namespace Rimworld_Animations {
 | 
			
		|||
            bodyFacing = this.bodyFacing;
 | 
			
		||||
            headFacing = this.headFacing;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void tickGraphics(PawnGraphicSet graphics) {
 | 
			
		||||
| 
						 | 
				
			
			@ -251,21 +260,39 @@ namespace Rimworld_Animations {
 | 
			
		|||
        public void calculateDrawValues() {
 | 
			
		||||
 | 
			
		||||
            deltaPos = new Vector3(clip.BodyOffsetX.Evaluate(clipPercent) * (mirror ? -1 : 1), clip.layer.AltitudeFor(), clip.BodyOffsetZ.Evaluate(clipPercent));
 | 
			
		||||
 | 
			
		||||
            if (CurrentAnimation?.actors[ActorIndex]?.offsetsByDefName != null && CurrentAnimation.actors[ActorIndex].offsetsByDefName.ContainsKey(pawn.def.defName)) {
 | 
			
		||||
                deltaPos.x += CurrentAnimation.actors[ActorIndex].offsetsByDefName[pawn.def.defName].x * (mirror ? -1 : 1);
 | 
			
		||||
                deltaPos.z += CurrentAnimation.actors[ActorIndex].offsetsByDefName[pawn.def.defName].y;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            bodyAngle = (clip.BodyAngle.Evaluate(clipPercent) + (quiver || shiver ? ((Rand.Value * AnimationSettings.shiverIntensity) - (AnimationSettings.shiverIntensity / 2f)) : 0f)) * (mirror ? -1 : 1);
 | 
			
		||||
            headAngle = clip.HeadAngle.Evaluate(clipPercent) * (mirror ? -1 : 1);
 | 
			
		||||
 | 
			
		||||
            if (controlGenitalAngle) {
 | 
			
		||||
                genitalAngle = clip.GenitalAngle.Evaluate(clipPercent) * (mirror ? -1 : 1);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (CurrentAnimation?.actors[ActorIndex]?.rotationByDefName != null && CurrentAnimation.actors[ActorIndex].rotationByDefName.ContainsKey(pawn.def.defName)) {
 | 
			
		||||
                float offsetRotation = CurrentAnimation.actors[ActorIndex].rotationByDefName[pawn.def.defName] * (Mirror ? -1 : 1);
 | 
			
		||||
                genitalAngle += offsetRotation;
 | 
			
		||||
                bodyAngle += offsetRotation;
 | 
			
		||||
                headAngle += offsetRotation;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //don't go past 360 or less than 0
 | 
			
		||||
            if (bodyAngle < 0) bodyAngle = 360 - ((-1f*bodyAngle) % 360);
 | 
			
		||||
            if (bodyAngle > 360) bodyAngle %= 360;
 | 
			
		||||
 | 
			
		||||
            headAngle = clip.HeadAngle.Evaluate(clipPercent) * (mirror ? -1 : 1);
 | 
			
		||||
            
 | 
			
		||||
            if (headAngle < 0) headAngle = 360 - ((-1f * headAngle) % 360);
 | 
			
		||||
            if (headAngle > 360) headAngle %= 360;
 | 
			
		||||
 | 
			
		||||
            if (controlGenitalAngle) {
 | 
			
		||||
                genitalAngle = clip.GenitalAngle.Evaluate(clipPercent) * (mirror ? -1 : 1);
 | 
			
		||||
                if (genitalAngle < 0) genitalAngle = 360 - ((-1f * genitalAngle) % 360);
 | 
			
		||||
                if (genitalAngle > 360) genitalAngle %= 360;
 | 
			
		||||
            }
 | 
			
		||||
            if (genitalAngle < 0) genitalAngle = 360 - ((-1f * genitalAngle) % 360);
 | 
			
		||||
            if (genitalAngle > 360) genitalAngle %= 360;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            bodyFacing = mirror ? new Rot4((int)clip.BodyFacing.Evaluate(clipPercent)).Opposite : new Rot4((int)clip.BodyFacing.Evaluate(clipPercent));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -286,11 +313,6 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
            Vector3 headPos = anchor + deltaPos + Quaternion.AngleAxis(bodyAngle, Vector3.up) * (pawn.Drawer.renderer.BaseHeadOffsetAt(headFacing) + headBob);
 | 
			
		||||
 | 
			
		||||
            if (CurrentAnimation?.actors[ActorIndex]?.offsetsByDefName != null && CurrentAnimation.actors[ActorIndex].offsetsByDefName.ContainsKey(pawn.def.defName)) {
 | 
			
		||||
                headPos.x += CurrentAnimation.actors[ActorIndex].offsetsByDefName[pawn.def.defName].x;
 | 
			
		||||
                headPos.z += CurrentAnimation.actors[ActorIndex].offsetsByDefName[pawn.def.defName].y;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return headPos;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ namespace Rimworld_Animations {
 | 
			
		|||
    class MainTabWindow_OffsetConfigure : MainTabWindow
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        public override Vector2 RequestedTabSize => new Vector2(505, 300);
 | 
			
		||||
        public override Vector2 RequestedTabSize => new Vector2(505, 340);
 | 
			
		||||
        public override void DoWindowContents(Rect inRect) {
 | 
			
		||||
 | 
			
		||||
            Rect position = new Rect(inRect.x, inRect.y, inRect.width, inRect.height);
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +20,10 @@ namespace Rimworld_Animations {
 | 
			
		|||
            Listing_Standard listingStandard = new Listing_Standard();
 | 
			
		||||
            listingStandard.Begin(position);
 | 
			
		||||
 | 
			
		||||
            listingStandard.Label("Offset Controller");
 | 
			
		||||
            listingStandard.Label("Offset Manager");
 | 
			
		||||
 | 
			
		||||
            listingStandard.GapLine();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            if (Find.Selector.SingleSelectedThing is Pawn) {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +33,7 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
                    Actor curActor = curPawn.TryGetComp<CompBodyAnimator>().CurrentAnimation.actors[curPawn.TryGetComp<CompBodyAnimator>().ActorIndex];
 | 
			
		||||
 | 
			
		||||
                    float offsetX = 0, offsetZ = 0;
 | 
			
		||||
                    float offsetX = 0, offsetZ = 0, rotation = 0;
 | 
			
		||||
 | 
			
		||||
                    if (curActor.offsetsByDefName.ContainsKey(curPawn.def.defName)) {
 | 
			
		||||
                        offsetX = curActor.offsetsByDefName[curPawn.def.defName].x;
 | 
			
		||||
| 
						 | 
				
			
			@ -39,9 +42,15 @@ namespace Rimworld_Animations {
 | 
			
		|||
                        curActor.offsetsByDefName.Add(curPawn.def.defName, new Vector2(0, 0));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    listingStandard.GapLine();
 | 
			
		||||
                    if (curActor.rotationByDefName.ContainsKey(curPawn.def.defName)) {
 | 
			
		||||
                        rotation = curActor.rotationByDefName[curPawn.def.defName];
 | 
			
		||||
                    }
 | 
			
		||||
                    else {
 | 
			
		||||
                        curActor.rotationByDefName.Add(curPawn.def.defName, 180);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    listingStandard.Label("Offset for race " + curPawn.def.defName + " in actor position " + curPawn.TryGetComp<CompBodyAnimator>().ActorIndex);
 | 
			
		||||
 | 
			
		||||
                    listingStandard.Label("Offset for race " + curPawn.def.defName + " in actor position " + curPawn.TryGetComp<CompBodyAnimator>().ActorIndex + (curPawn.TryGetComp<CompBodyAnimator>().Mirror ? " mirrored" : ""));
 | 
			
		||||
 | 
			
		||||
                    if(curPawn.def.defName == "Human") {
 | 
			
		||||
                        listingStandard.Label("Warning--You generally don't want to change human offsets, only alien offsets");
 | 
			
		||||
| 
						 | 
				
			
			@ -54,13 +63,30 @@ namespace Rimworld_Animations {
 | 
			
		|||
                    listingStandard.Label("Z Offset: " + offsetZ);
 | 
			
		||||
                    offsetZ = listingStandard.Slider(offsetZ, -10, 10);
 | 
			
		||||
 | 
			
		||||
                    listingStandard.Label("Rotation: " + rotation);
 | 
			
		||||
                    rotation = listingStandard.Slider(rotation, -180, 180);
 | 
			
		||||
 | 
			
		||||
                    if(listingStandard.ButtonText("Reset All")) {
 | 
			
		||||
                        offsetX = 0;
 | 
			
		||||
                        offsetZ = 0;
 | 
			
		||||
                        rotation = 0;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (offsetX != curActor.offsetsByDefName[curPawn.def.defName].x || offsetZ != curActor.offsetsByDefName[curPawn.def.defName].y) {
 | 
			
		||||
                        curActor.offsetsByDefName[curPawn.def.defName] = new Vector2(offsetX, offsetZ);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if(rotation != curActor.rotationByDefName[curPawn.def.defName]) {
 | 
			
		||||
                        curActor.rotationByDefName[curPawn.def.defName] = rotation;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                listingStandard.Label("Select a pawn currently in an animation to change their offsets");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            listingStandard.End();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,11 +44,6 @@ namespace Rimworld_Animations {
 | 
			
		|||
				bodyAnim.tickGraphics(graphics);
 | 
			
		||||
				bodyAnim.animatePawn(ref rootLoc, ref angle, ref bodyFacing, ref headFacing);
 | 
			
		||||
 | 
			
		||||
				if(bodyAnim.CurrentAnimation?.actors[bodyAnim.ActorIndex]?.offsetsByDefName != null && bodyAnim.CurrentAnimation.actors[bodyAnim.ActorIndex].offsetsByDefName.ContainsKey(pawn.def.defName)) {
 | 
			
		||||
					rootLoc.x += bodyAnim.CurrentAnimation.actors[bodyAnim.ActorIndex].offsetsByDefName[pawn.def.defName].x;
 | 
			
		||||
					rootLoc.z += bodyAnim.CurrentAnimation.actors[bodyAnim.ActorIndex].offsetsByDefName[pawn.def.defName].y;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,11 +18,6 @@ namespace Rimworld_Animations {
 | 
			
		|||
            if (bodyAnim != null && bodyAnim.isAnimating) {
 | 
			
		||||
                __result = ___pawn.TryGetComp<CompBodyAnimator>().anchor + ___pawn.TryGetComp<CompBodyAnimator>().deltaPos;
 | 
			
		||||
 | 
			
		||||
                if (bodyAnim.CurrentAnimation?.actors[bodyAnim.ActorIndex]?.offsetsByDefName != null && bodyAnim.CurrentAnimation.actors[bodyAnim.ActorIndex].offsetsByDefName.ContainsKey(___pawn.def.defName)) {
 | 
			
		||||
                    __result.x += bodyAnim.CurrentAnimation.actors[bodyAnim.ActorIndex].offsetsByDefName[___pawn.def.defName].x;
 | 
			
		||||
                    __result.z += bodyAnim.CurrentAnimation.actors[bodyAnim.ActorIndex].offsetsByDefName[___pawn.def.defName].y;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue