class inkButtonAnimatedController extends inkButtonController
{
	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;
		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;
	}

	protected event OnUnitialize() {}

	public function SetButtonText( const argValue : ref< String > )
	{
		var currListText : weak< inkText >;
		currListText = GetButton();
		currListText.SetText( argValue );
	}

	public function GetButtonText() : String
	{
		var currListText : weak< inkText >;
		currListText = GetButton();
		return currListText.GetText();
	}

	private function GetButton() : weak< inkText >
	{
		var root : weak< inkCanvas >;
		var currListText : weak< inkText >;
		root = ( ( inkCanvas )( GetRootWidget() ) );
		currListText = ( ( inkText )( root.GetWidget( 'textLabel' ) ) );
		return currListText;
	}

	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 );
			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 );
			m_animPulseProxy.Stop();
			m_animTarget_Pulse.SetOpacity( 0.0 );
			SetCursorContext( 'Default' );
		}
		if( newState == inkEButtonState.Press )
		{
			PlaySound( 'Button', 'OnPress' );
		}
		else if( newState == inkEButtonState.Hover && oldState != inkEButtonState.Press )
		{
			PlaySound( 'Button', 'OnHover' );
		}
	}

}

