class TooltipAnimationController extends inkLogicController
{
	private editable var m_tooltipContainer : inkWidgetRef;
	private var m_tooltipAnimHideDef : inkAnimDef;
	private var m_tooltipDelayedShowDef : inkAnimDef;
	private var m_tooltipAnimHide : inkAnimProxy;
	private var m_tooltipDelayedShow : inkAnimProxy;
	private var m_axisDataThreshold : Float;
	default m_axisDataThreshold = 0.4;
	private var m_mouseDataThreshold : Float;
	default m_mouseDataThreshold = 0.9;
	private var m_isHidden : Bool;

	protected event OnInitialize()
	{
		RegisterToGlobalInputCallback( 'OnPostOnAxis', this, 'OnAxisInput' );
		RegisterToGlobalInputCallback( 'OnPostOnRelative', this, 'OnAxisInput' );
		m_tooltipAnimHideDef = GetShowingAnimation();
		m_tooltipDelayedShowDef = GetHidingAnimation();
	}

	protected event OnUninitialize()
	{
		UnregisterFromGlobalInputCallback( 'OnPostOnAxis', this, 'OnAxisInput' );
		UnregisterFromGlobalInputCallback( 'OnPostOnRelative', this, 'OnAxisInput' );
	}

	protected event OnAxisInput( evt : inkPointerEvent )
	{
		var axisData : Float;
		axisData = evt.GetAxisData();
		if( ( ( evt.IsAction( 'left_stick_x' ) || evt.IsAction( 'left_stick_y' ) ) && ( AbsF( axisData ) > m_axisDataThreshold ) ) || ( ( evt.IsAction( 'mouse_x' ) || evt.IsAction( 'mouse_y' ) ) && ( AbsF( axisData ) > m_mouseDataThreshold ) ) )
		{
			if( m_tooltipAnimHide && m_tooltipAnimHide.IsPlaying() )
			{
			}
			else if( m_tooltipDelayedShow && m_tooltipDelayedShow.IsPlaying() )
			{
				m_tooltipDelayedShow.Stop( true );
				m_tooltipDelayedShow = inkWidgetRef.PlayAnimation( m_tooltipContainer, m_tooltipDelayedShowDef );
				m_tooltipDelayedShow.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnShown' );
			}
			else
			{
				if( m_tooltipAnimHide )
				{
					m_tooltipAnimHide.Stop( true );
					m_tooltipAnimHide = NULL;
				}
				m_tooltipAnimHide = inkWidgetRef.PlayAnimation( m_tooltipContainer, m_tooltipAnimHideDef );
				m_tooltipAnimHide.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnHidden' );
			}
		}
	}

	protected event OnHidden( proxy : inkAnimProxy )
	{
		if( m_tooltipDelayedShow )
		{
			m_tooltipDelayedShow.Stop( true );
			m_tooltipDelayedShow = NULL;
		}
		m_tooltipDelayedShow = inkWidgetRef.PlayAnimation( m_tooltipContainer, m_tooltipDelayedShowDef );
		m_tooltipDelayedShow.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnShown' );
		m_isHidden = true;
	}

	protected event OnShown( proxy : inkAnimProxy )
	{
		m_isHidden = false;
	}

	private function GetShowingAnimation() : inkAnimDef
	{
		var transparencyAnimation : inkAnimDef;
		var transparencyInterpolator : inkAnimTransparency;
		transparencyAnimation = new inkAnimDef;
		transparencyInterpolator = new inkAnimTransparency;
		transparencyInterpolator.SetDuration( 0.1 );
		transparencyInterpolator.SetStartDelay( 0.1 );
		transparencyInterpolator.SetDirection( inkanimInterpolationDirection.FromTo );
		transparencyInterpolator.SetType( inkanimInterpolationType.Exponential );
		transparencyInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		transparencyInterpolator.SetStartTransparency( 0.0 );
		transparencyInterpolator.SetEndTransparency( 1.0 );
		transparencyAnimation.AddInterpolator( transparencyInterpolator );
		return transparencyAnimation;
	}

	private function GetHidingAnimation() : inkAnimDef
	{
		var transparencyAnimation : inkAnimDef;
		var transparencyInterpolator : inkAnimTransparency;
		transparencyAnimation = new inkAnimDef;
		transparencyInterpolator = new inkAnimTransparency;
		transparencyInterpolator.SetDuration( 0.05 );
		transparencyInterpolator.SetDirection( inkanimInterpolationDirection.To );
		transparencyInterpolator.SetType( inkanimInterpolationType.Exponential );
		transparencyInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		transparencyInterpolator.SetEndTransparency( 0.0 );
		transparencyAnimation.AddInterpolator( transparencyInterpolator );
		return transparencyAnimation;
	}

}

