class TextAnimOnTextChange extends inkLogicController
{
	private editable var textField : inkTextRef;
	private editable var animationName : CName;
	default animationName = 'default';
	private var m_BlinkAnim : inkAnimDef;
	private var m_ScaleAnim : inkAnimDef;
	private var bufferedValue : String;

	protected event OnInitialize()
	{
		var alphaInterpolator2 : inkAnimTransparency;
		var scaleInterpolator : inkAnimScale;
		m_BlinkAnim = new inkAnimDef;
		alphaInterpolator2 = new inkAnimTransparency;
		alphaInterpolator2.SetDuration( 0.5 );
		alphaInterpolator2.SetStartTransparency( 0.1 );
		alphaInterpolator2.SetEndTransparency( 1.0 );
		m_BlinkAnim.AddInterpolator( alphaInterpolator2 );
		m_ScaleAnim = new inkAnimDef;
		scaleInterpolator = new inkAnimScale;
		scaleInterpolator.SetDuration( 0.5 );
		scaleInterpolator.SetStartScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetEndScale( Vector2( 1.20000005, 1.20000005 ) );
		m_ScaleAnim.AddInterpolator( scaleInterpolator );
		inkTextRef.RegisterToCallback( textField, 'OnTextChanged', this, 'OnChangeTextToInject' );
	}

	protected event OnUninitialize()
	{
		inkTextRef.UnregisterFromCallback( textField, 'OnTextChanged', this, 'OnChangeTextToInject' );
	}

	protected event OnChangeTextToInject( str : String )
	{
		if( bufferedValue != str )
		{
			if( animationName == 'default' || animationName == '' )
			{
				GetRootWidget().PlayAnimation( m_BlinkAnim );
				GetRootWidget().PlayAnimation( m_ScaleAnim );
			}
			else
			{
				PlayLibraryAnimation( animationName );
			}
		}
		bufferedValue = str;
	}

}

