class InventoryStatsDisplay extends inkLogicController
{
	private editable var m_StatsRoot : inkCompoundRef;
	private editable var m_StatItemName : CName;
	private var m_StatItems : array< weak< InventoryStatItemV2 > >;

	public function Setup( const stats : ref< array< StatViewData > > )
	{
		var statView : weak< InventoryStatItemV2 >;
		var i, limit : Int32;
		limit = stats.Size();
		while( m_StatItems.Size() > limit )
		{
			statView = m_StatItems.PopBack();
			inkCompoundRef.RemoveChild( m_StatsRoot, statView.GetRootWidget() );
		}
		while( m_StatItems.Size() < limit )
		{
			statView = ( ( InventoryStatItemV2 )( SpawnFromLocal( inkCompoundRef.Get( m_StatsRoot ), m_StatItemName ).GetController() ) );
			m_StatItems.PushBack( statView );
		}
		for( i = 0; i < limit; i += 1 )
		{
			statView = m_StatItems[ i ];
			if( statView )
			{
				statView.Setup( stats[ i ], 6 + i );
			}
		}
	}

}

class InventoryStatItemV2 extends inkLogicController
{
	private editable var m_LabelRef : inkTextRef;
	private editable var m_ValueRef : inkTextRef;
	private editable var m_Icon : inkImageRef;
	private editable var m_BackgroundIcon : inkImageRef;
	private editable var m_TextGroup : inkWidgetRef;
	private var m_IntroPlayed : Bool;
	default m_IntroPlayed = false;

	public function Setup( const statViewData : ref< StatViewData >, framesDelay : Int32 )
	{
		Setup( statViewData.statName, statViewData.value, statViewData.type );
		if( !( m_IntroPlayed ) )
		{
			m_IntroPlayed = true;
			PlayIntroAnimation( framesDelay );
		}
	}

	public function Setup( const statViewData : ref< StatViewData > )
	{
		Setup( statViewData.statName, statViewData.value, statViewData.type );
	}

	public function Setup( scannerStatDetails : ScannerStatDetails )
	{
		Setup( "", ( ( Int32 )( scannerStatDetails.value ) ), scannerStatDetails.statType );
	}

	public function Setup( const statName : ref< String >, statValue : Int32, statType : gamedataStatType )
	{
		inkTextRef.SetLetterCase( m_LabelRef, textLetterCase.UpperCase );
		inkTextRef.SetText( m_LabelRef, statName );
		if( inkTextRef.IsValid( m_ValueRef ) )
		{
			inkTextRef.SetText( m_ValueRef, IntToString( statValue ) );
		}
		inkImageRef.SetTexturePart( m_BackgroundIcon, UIItemsHelper.GetBGIconNameForStat( statType ) );
		inkImageRef.SetTexturePart( m_Icon, UIItemsHelper.GetIconNameForStat( statType ) );
		GetRootWidget().SetState( UIItemsHelper.GetStateNameForStat( statType ) );
	}

	private function PlayIntroAnimation( framesDelay : Int32 )
	{
		var animationDef : inkAnimDef;
		var scaleInterp : inkAnimScale;
		var alphaInterp : inkAnimTransparency;
		animationDef = new inkAnimDef;
		scaleInterp = new inkAnimScale;
		scaleInterp.SetStartScale( Vector2( 0.0, 0.0 ) );
		scaleInterp.SetEndScale( Vector2( 1.0, 1.0 ) );
		scaleInterp.SetMode( inkanimInterpolationMode.EasyInOut );
		scaleInterp.SetType( inkanimInterpolationType.Sinusoidal );
		scaleInterp.SetDirection( inkanimInterpolationDirection.FromTo );
		scaleInterp.SetDuration( 0.25 );
		scaleInterp.SetStartDelay( 0.03 * ( ( Float )( framesDelay ) ) );
		animationDef.AddInterpolator( scaleInterp );
		inkImageRef.PlayAnimation( m_Icon, animationDef );
		animationDef = new inkAnimDef;
		alphaInterp = new inkAnimTransparency;
		alphaInterp.SetStartTransparency( 0.0 );
		alphaInterp.SetEndTransparency( 1.0 );
		alphaInterp.SetMode( inkanimInterpolationMode.EasyInOut );
		alphaInterp.SetType( inkanimInterpolationType.Sinusoidal );
		alphaInterp.SetDirection( inkanimInterpolationDirection.FromTo );
		alphaInterp.SetDuration( 0.25 );
		alphaInterp.SetStartDelay( 0.03 * ( ( Float )( framesDelay ) ) );
		animationDef.AddInterpolator( alphaInterp );
		inkWidgetRef.PlayAnimation( m_TextGroup, animationDef );
	}

}

