2020-05-30 06:10:31 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using Verse ;
using RimWorld ;
using UnityEngine ;
namespace Rimworld_Animations {
class MainTabWindow_OffsetConfigure : MainTabWindow
{
2020-05-30 21:10:22 +00:00
public override Vector2 RequestedTabSize = > new Vector2 ( 505 , 340 ) ;
2020-05-30 06:10:31 +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 ) ;
2020-05-30 21:10:22 +00:00
listingStandard . Label ( "Offset Manager" ) ;
listingStandard . GapLine ( ) ;
2020-05-30 06:10:31 +00:00
if ( Find . Selector . SingleSelectedThing is Pawn ) {
Pawn curPawn = Find . Selector . SingleSelectedThing as Pawn ;
if ( curPawn . TryGetComp < CompBodyAnimator > ( ) . isAnimating ) {
Actor curActor = curPawn . TryGetComp < CompBodyAnimator > ( ) . CurrentAnimation . actors [ curPawn . TryGetComp < CompBodyAnimator > ( ) . ActorIndex ] ;
2020-05-30 21:10:22 +00:00
float offsetX = 0 , offsetZ = 0 , rotation = 0 ;
2020-05-30 06:10:31 +00:00
if ( curActor . offsetsByDefName . ContainsKey ( curPawn . def . defName ) ) {
offsetX = curActor . offsetsByDefName [ curPawn . def . defName ] . x ;
offsetZ = curActor . offsetsByDefName [ curPawn . def . defName ] . y ;
} else {
curActor . offsetsByDefName . Add ( curPawn . def . defName , new Vector2 ( 0 , 0 ) ) ;
}
2020-05-30 21:10:22 +00:00
if ( curActor . rotationByDefName . ContainsKey ( curPawn . def . defName ) ) {
rotation = curActor . rotationByDefName [ curPawn . def . defName ] ;
}
else {
curActor . rotationByDefName . Add ( curPawn . def . defName , 180 ) ;
}
2020-05-30 06:10:31 +00:00
2020-05-30 21:10:22 +00:00
listingStandard . Label ( "Offset for race " + curPawn . def . defName + " in actor position " + curPawn . TryGetComp < CompBodyAnimator > ( ) . ActorIndex + ( curPawn . TryGetComp < CompBodyAnimator > ( ) . Mirror ? " mirrored" : "" ) ) ;
2020-05-30 06:10:31 +00:00
if ( curPawn . def . defName = = "Human" ) {
listingStandard . Label ( "Warning--You generally don't want to change human offsets, only alien offsets" ) ;
}
listingStandard . Label ( "X Offset: " + offsetX ) ;
offsetX = listingStandard . Slider ( offsetX , - 10 , 10 ) ;
listingStandard . Label ( "Z Offset: " + offsetZ ) ;
offsetZ = listingStandard . Slider ( offsetZ , - 10 , 10 ) ;
2020-05-30 21:10:22 +00:00
listingStandard . Label ( "Rotation: " + rotation ) ;
rotation = listingStandard . Slider ( rotation , - 180 , 180 ) ;
if ( listingStandard . ButtonText ( "Reset All" ) ) {
offsetX = 0 ;
offsetZ = 0 ;
rotation = 0 ;
}
2020-05-30 06:10:31 +00:00
if ( offsetX ! = curActor . offsetsByDefName [ curPawn . def . defName ] . x | | offsetZ ! = curActor . offsetsByDefName [ curPawn . def . defName ] . y ) {
curActor . offsetsByDefName [ curPawn . def . defName ] = new Vector2 ( offsetX , offsetZ ) ;
}
2020-05-30 21:10:22 +00:00
if ( rotation ! = curActor . rotationByDefName [ curPawn . def . defName ] ) {
curActor . rotationByDefName [ curPawn . def . defName ] = rotation ;
}
2020-05-30 06:10:31 +00:00
}
}
2020-05-30 21:10:22 +00:00
else {
listingStandard . Label ( "Select a pawn currently in an animation to change their offsets" ) ;
}
2020-05-30 06:10:31 +00:00
listingStandard . End ( ) ;
base . DoWindowContents ( inRect ) ;
}
}
}