diff --git a/1.1/Assemblies/Rimworld-Animations.dll b/1.1/Assemblies/Rimworld-Animations.dll index 3aa8e1c..de4b830 100644 Binary files a/1.1/Assemblies/Rimworld-Animations.dll and b/1.1/Assemblies/Rimworld-Animations.dll differ diff --git a/Source/Actors/Actor.cs b/Source/Actors/Actor.cs index d836d24..eebe5ad 100644 --- a/Source/Actors/Actor.cs +++ b/Source/Actors/Actor.cs @@ -21,9 +21,11 @@ namespace Rimworld_Animations { public Vector3 offset = new Vector2(0, 0); public Dictionary offsetsByDefName = new Dictionary(); + public Dictionary rotationByDefName = new Dictionary(); public void ExposeData() { Scribe_Collections.Look(ref offsetsByDefName, "OffsetsSetInOptions", LookMode.Value, LookMode.Value); + Scribe_Collections.Look(ref rotationByDefName, "RotationOffsetsFromOptions", LookMode.Value, LookMode.Value); } } } diff --git a/Source/Comps/CompBodyAnimator.cs b/Source/Comps/CompBodyAnimator.cs index aff1dbe..e18113f 100644 --- a/Source/Comps/CompBodyAnimator.cs +++ b/Source/Comps/CompBodyAnimator.cs @@ -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; } diff --git a/Source/MainTabWindows/MainTabWindow_OffsetConfigure.cs b/Source/MainTabWindows/MainTabWindow_OffsetConfigure.cs index f90e66e..9516e3a 100644 --- a/Source/MainTabWindows/MainTabWindow_OffsetConfigure.cs +++ b/Source/MainTabWindows/MainTabWindow_OffsetConfigure.cs @@ -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().CurrentAnimation.actors[curPawn.TryGetComp().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().ActorIndex); + + listingStandard.Label("Offset for race " + curPawn.def.defName + " in actor position " + curPawn.TryGetComp().ActorIndex + (curPawn.TryGetComp().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(); diff --git a/Source/Patches/HarmonyPatch_PawnRenderer.cs b/Source/Patches/HarmonyPatch_PawnRenderer.cs index a6865bc..8bad2f2 100644 --- a/Source/Patches/HarmonyPatch_PawnRenderer.cs +++ b/Source/Patches/HarmonyPatch_PawnRenderer.cs @@ -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; - } - } } diff --git a/Source/Patches/HarmonyPatch_Pawn_DrawTracker.cs b/Source/Patches/HarmonyPatch_Pawn_DrawTracker.cs index 45a5886..5cdcfce 100644 --- a/Source/Patches/HarmonyPatch_Pawn_DrawTracker.cs +++ b/Source/Patches/HarmonyPatch_Pawn_DrawTracker.cs @@ -18,11 +18,6 @@ namespace Rimworld_Animations { if (bodyAnim != null && bodyAnim.isAnimating) { __result = ___pawn.TryGetComp().anchor + ___pawn.TryGetComp().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;