2024-04-15 17:33:06 +00:00
using System.Collections.Generic ;
using Verse ;
using RimWorld ;
using UnityEngine ;
2024-04-23 20:53:13 +00:00
using System.Windows ;
2024-04-15 17:33:06 +00:00
namespace Rimworld_Animations {
class MainTabWindow_OffsetConfigure : MainTabWindow
{
2024-04-23 21:21:47 +00:00
public override Vector2 RequestedTabSize = > new Vector2 ( 505 , 500 ) ;
2024-04-15 17:33:06 +00:00
public override void DoWindowContents ( Rect inRect ) {
Rect position = new Rect ( inRect . x , inRect . y , inRect . width , inRect . height ) ;
Listing_Standard listingStandard = new Listing_Standard ( ) ;
listingStandard . Begin ( position ) ;
2024-04-23 20:53:13 +00:00
listingStandard . Label ( "RimAnims_AnimManager" . Translate ( ) ) ;
2024-04-15 17:33:06 +00:00
listingStandard . GapLine ( ) ;
2024-04-23 20:53:13 +00:00
if ( Find . Selector . SingleSelectedThing is Pawn curPawn
& & curPawn . TryGetComp < CompExtendedAnimator > ( out CompExtendedAnimator extendedAnimator )
& & extendedAnimator . IsAnimating )
{
//Pawn info about their body, race
Vector3 offsetPosition = extendedAnimator . Offset ! = null ? ( Vector3 ) extendedAnimator . Offset : Vector3 . zero ;
int offsetRotation = extendedAnimator . Rotation ! = null ? ( int ) extendedAnimator . Rotation : 0 ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
string pawnDef = curPawn . def . defName ;
string bodyTypeDef = ( curPawn . story ? . bodyType ! = null ) ? curPawn . story . bodyType . ToString ( ) : "None" ;
string genderDef = curPawn . gender . ToString ( ) ;
string currentAnimation = extendedAnimator . CurrentAnimation ! = null ? extendedAnimator . CurrentAnimation . defName : "None" ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
listingStandard . Label ( curPawn . Name + ": " + curPawn . def . defName + ", " + bodyTypeDef + ", " + genderDef + ", Animation: " + currentAnimation ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
if ( curPawn . def . defName = = "Human" )
{
listingStandard . Label ( "RimAnims_Warning" . Translate ( ) ) ;
}
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
float posX = offsetPosition . x , posY = offsetPosition . y , posZ = offsetPosition . z ;
int rot = offsetRotation ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
float . TryParse ( listingStandard . TextEntryLabeled ( "X: " , posX . ToString ( ) ) , out posX ) ;
posX = listingStandard . Slider ( posX , - 2 , 2 ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
float . TryParse ( listingStandard . TextEntryLabeled ( "Y: " , offsetPosition . y . ToString ( ) ) , out posY ) ;
posY = listingStandard . Slider ( posY , - 2 , 2 ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
float . TryParse ( listingStandard . TextEntryLabeled ( "Z: " , posZ . ToString ( ) ) , out posZ ) ;
posZ = listingStandard . Slider ( posZ , - 2 , 2 ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
int . TryParse ( listingStandard . TextEntryLabeled ( "Rotation: " , rot . ToString ( ) ) , out rot ) ;
rot = ( int ) listingStandard . Slider ( rot , - 180 , 180 ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
listingStandard . GapLine ( ) ;
Vector3 newOffsetVector = new Vector3 ( posX , posY , posZ ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
string offset = "<li>" ;
offset + = bodyTypeDef ! = "None" ? "<bodyType>" + bodyTypeDef + "</bodyType>" : "" ;
offset + = newOffsetVector ! = Vector3 . zero ? "<offset>(" + posX + ", " + posY + ", " + posZ + ")</offset>" : "" ;
offset + = rot ! = 0 ? "<rotation>" + rot + "</rotation>" : "" ;
offset + = "</li>" ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
listingStandard . Label ( "Appropriate Offset value for " + currentAnimation + ", " + pawnDef + ", " + bodyTypeDef + ", " + genderDef + ": " ) ;
listingStandard . Label ( offset ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
if ( listingStandard . ButtonText ( "RimAnims_CopyToClipboard" . Translate ( ) ) )
{
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
GUIUtility . systemCopyBuffer = offset ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
}
2024-04-15 17:33:06 +00:00
2024-04-23 21:21:47 +00:00
listingStandard . Label ( "RimAnims_ShareSettings" . Translate ( ) ) ;
2024-04-23 20:53:13 +00:00
extendedAnimator . Offset = newOffsetVector ;
extendedAnimator . Rotation = rot ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
}
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
else
{
listingStandard . Label ( "Select a pawn currently in an animation to change their offsets" ) ;
}
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
listingStandard . End ( ) ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
}
}
}
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
/ * *
if ( curPawn . TryGetComp < CompExtendedAnimator > animator ) {
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
/ *
CompBodyAnimator compBodyAnimator = curPawn . TryGetComp < CompBodyAnimator > ( ) ;
AnimationDef def = compBodyAnimator . CurrentAnimation ;
int ActorIndex = compBodyAnimator . ActorIndex ;
float offsetX = 0 , offsetZ = 0 , rotation = 0 ;
string bodyTypeDef = ( curPawn . story ? . bodyType ! = null ) ? curPawn . story . bodyType . ToString ( ) : "" ;
2024-04-15 17:33:06 +00:00
2024-04-23 20:53:13 +00:00
if ( AnimationSettings . offsets . ContainsKey ( def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ) ) {
offsetX = AnimationSettings . offsets [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] . x ;
offsetZ = AnimationSettings . offsets [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] . y ;
} else {
AnimationSettings . offsets . Add ( def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex , new Vector2 ( 0 , 0 ) ) ;
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
if ( AnimationSettings . rotation . ContainsKey ( def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ) ) {
rotation = AnimationSettings . rotation [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] ;
}
else {
AnimationSettings . rotation . Add ( def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex , 0 ) ;
}
listingStandard . Label ( "Name: " + curPawn . Name + " Race: " + curPawn . def . defName + " Actor Index: " + curPawn . TryGetComp < CompBodyAnimator > ( ) . ActorIndex + " Body Type (if any): " + bodyTypeDef + " Animation: " + def . label + ( 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" ) ;
}
float . TryParse ( listingStandard . TextEntryLabeled ( "X Offset: " , offsetX . ToString ( ) ) , out offsetX ) ;
offsetX = listingStandard . Slider ( offsetX , - 2 , 2 ) ;
float . TryParse ( listingStandard . TextEntryLabeled ( "Z Offset: " , offsetZ . ToString ( ) ) , out offsetZ ) ;
offsetZ = listingStandard . Slider ( offsetZ , - 2 , 2 ) ;
float . TryParse ( listingStandard . TextEntryLabeled ( "Rotation: " , rotation . ToString ( ) ) , out rotation ) ;
rotation = listingStandard . Slider ( rotation , - 180 , 180 ) ;
if ( listingStandard . ButtonText ( "Reset All" ) ) {
offsetX = 0 ;
offsetZ = 0 ;
rotation = 0 ;
}
listingStandard . GapLine ( ) ;
if ( listingStandard . ButtonText ( "Shift Actors" ) ) {
if ( AnimationSettings . debugMode ) {
Log . Message ( "Shifting actors in animation..." ) ;
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
for ( int i = 0 ; i < curPawn . TryGetComp < CompBodyAnimator > ( ) . actorsInCurrentAnimation . Count ; i + + ) {
Pawn actor = curPawn . TryGetComp < CompBodyAnimator > ( ) . actorsInCurrentAnimation [ i ] ;
actor . TryGetComp < CompBodyAnimator > ( ) ? . shiftActorPositionAndRestartAnimation ( ) ;
//reset the clock time of every pawn in animation
if ( actor . jobs . curDriver is rjw . JobDriver_Sex ) {
( actor . jobs . curDriver as rjw . JobDriver_Sex ) . ticks_left = def . animationTimeTicks ;
( actor . jobs . curDriver as rjw . JobDriver_Sex ) . ticksLeftThisToil = def . animationTimeTicks ;
( actor . jobs . curDriver as rjw . JobDriver_Sex ) . duration = def . animationTimeTicks ;
}
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
if ( offsetX ! = AnimationSettings . offsets [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] . x | | offsetZ ! = AnimationSettings . offsets [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] . y ) {
AnimationSettings . offsets [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] = new Vector2 ( offsetX , offsetZ ) ;
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
if ( rotation ! = AnimationSettings . rotation [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] ) {
AnimationSettings . rotation [ def . defName + curPawn . def . defName + bodyTypeDef + ActorIndex ] = rotation ;
}
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
2024-04-15 17:33:06 +00:00
}
2024-04-23 20:53:13 +00:00
* /