class AnimatedListItemController extends ListItemController
{
	protected editable var m_animOutName : CName;
	default m_animOutName = 'MenuButtonFadeOut';
	protected editable var m_animPulseName : CName;
	default m_animPulseName = 'MenuButtonPulse';
	protected editable var m_animTargetHover : inkWidgetRef;
	protected editable var m_animTargetPulse : inkWidgetRef;
	protected editable var m_normalRootOpacity : Float;
	default m_normalRootOpacity = 1.0f;
	protected editable var m_hoverRootOpacity : Float;
	default m_hoverRootOpacity = 1.0f;
	protected var m_rootWidget : weak< inkCompoundWidget >;
	protected var m_animTarget_Hover : weak< inkWidget >;
	protected var m_animTarget_Pulse : weak< inkWidget >;
	private var m_animHover : inkAnimDef;
	private var m_animPulse : inkAnimDef;
	private var m_animHoverProxy : inkAnimProxy;
	private var m_animPulseProxy : inkAnimProxy;
	private var m_animPulseOptions : inkAnimOptions;

	protected event OnInitialize()
	{
		var fadeOutInterp : inkAnimTransparency;
		var pulseInterp : inkAnimTransparency;
		super.OnInitialize();
		m_rootWidget = GetRootCompoundWidget();
		m_animTarget_Hover = inkWidgetRef.Get( m_animTargetHover );
		m_animTarget_Pulse = inkWidgetRef.Get( m_animTargetPulse );
		m_animHover = new inkAnimDef;
		fadeOutInterp = new inkAnimTransparency;
		fadeOutInterp.SetStartTransparency( 1.0 );
		fadeOutInterp.SetEndTransparency( 0.0 );
		fadeOutInterp.SetDuration( 0.15000001 );
		m_animHover.AddInterpolator( fadeOutInterp );
		m_animPulse = new inkAnimDef;
		pulseInterp = new inkAnimTransparency;
		pulseInterp.SetStartTransparency( 1.0 );
		pulseInterp.SetEndTransparency( 0.5 );
		pulseInterp.SetDuration( 0.75 );
		m_animPulse.AddInterpolator( pulseInterp );
		pulseInterp = new inkAnimTransparency;
		pulseInterp.SetStartTransparency( 1.0 );
		pulseInterp.SetEndTransparency( 1.0 );
		pulseInterp.SetDuration( 1.0 );
		m_animPulse.AddInterpolator( pulseInterp );
		pulseInterp = new inkAnimTransparency;
		pulseInterp.SetStartTransparency( 1.0 );
		pulseInterp.SetEndTransparency( 0.5 );
		pulseInterp.SetDuration( 0.75 );
		m_animPulse.AddInterpolator( pulseInterp );
		pulseInterp = new inkAnimTransparency;
		pulseInterp.SetStartTransparency( 0.5 );
		pulseInterp.SetEndTransparency( 0.5 );
		pulseInterp.SetDuration( 1.0 );
		m_animPulse.AddInterpolator( pulseInterp );
		m_animPulseOptions.loopType = inkanimLoopType.Cycle;
		m_animPulseOptions.loopCounter = 500;
		RegisterToCallback( 'OnAddedToList', this, 'OnAddedToList' );
	}

	protected event OnUninitialize()
	{
		UnregisterFromCallback( 'OnAddedToList', this, 'OnAddedToList' );
	}

	protected event OnButtonStateChanged( controller : weak< inkButtonController >, oldState : inkEButtonState, newState : inkEButtonState )
	{
		if( oldState == inkEButtonState.Normal && newState == inkEButtonState.Hover )
		{
			m_rootWidget.SetOpacity( m_hoverRootOpacity );
			m_animHoverProxy.Stop();
			m_animTarget_Hover.SetOpacity( 1.0 );
			if( inkWidgetRef.IsValid( m_animTargetPulse ) )
			{
				m_animPulseProxy.Stop();
				m_animPulseProxy = m_animTarget_Pulse.PlayAnimationWithOptions( m_animPulse, m_animPulseOptions );
			}
			SetCursorContext( 'Hover' );
		}
		else if( oldState == inkEButtonState.Hover && newState != inkEButtonState.Hover )
		{
			m_rootWidget.SetOpacity( m_normalRootOpacity );
			m_animHoverProxy.Stop();
			m_animHoverProxy = m_animTarget_Hover.PlayAnimation( m_animHover );
			if( inkWidgetRef.IsValid( m_animTargetPulse ) )
			{
				m_animPulseProxy.Stop();
				m_animTarget_Pulse.SetOpacity( 0.0 );
			}
			SetCursorContext( 'Default' );
		}
	}

	protected event OnAddedToList( target : weak< ListItemController > )
	{
		var m_animListText : inkAnimDef;
		var m_animTextInterp : inkAnimTextOffset;
		var stageOneTime, stageTwoTime : Float;
		if( !( inkTextRef.IsValid( m_labelPathRef ) ) )
		{
			return false;
		}
		else if( GetIndex() == 0 )
		{
			m_animListText = new inkAnimDef;
			m_animTextInterp = new inkAnimTextOffset;
			m_animTextInterp.SetDuration( 0.075 );
			m_animTextInterp.SetStartProgress( 0.25 );
			m_animTextInterp.SetEndProgress( 0.0 );
			m_animListText.AddInterpolator( m_animTextInterp );
			inkTextRef.Get( m_labelPathRef ).PlayAnimation( m_animListText );
		}
		else
		{
			stageOneTime = 0.1;
			stageTwoTime = 0.1 + ( MinF( 5.0, ( ( Float )( GetIndex() ) ) ) * 0.15000001 );
			m_animListText = new inkAnimDef;
			m_animTextInterp = new inkAnimTextOffset;
			m_animTextInterp.SetStartDelay( 0.0 );
			m_animTextInterp.SetDuration( stageOneTime );
			m_animTextInterp.SetStartProgress( 0.75 );
			m_animTextInterp.SetEndProgress( 0.01 );
			m_animTextInterp.SetType( inkanimInterpolationType.Quadratic );
			m_animTextInterp.SetMode( inkanimInterpolationMode.EasyOut );
			m_animListText.AddInterpolator( m_animTextInterp );
			m_animTextInterp = new inkAnimTextOffset;
			m_animTextInterp.SetStartDelay( stageOneTime );
			m_animTextInterp.SetDuration( stageTwoTime );
			m_animTextInterp.SetStartProgress( 0.01 );
			m_animTextInterp.SetEndProgress( 0.0 );
			m_animTextInterp.SetType( inkanimInterpolationType.Quadratic );
			m_animTextInterp.SetMode( inkanimInterpolationMode.EasyOut );
			m_animListText.AddInterpolator( m_animTextInterp );
			inkTextRef.Get( m_labelPathRef ).PlayAnimation( m_animListText );
		}
	}

}

