enum EUIStealthIconType
{
	Invalid = 0,
	HostileHuman = 1,
	Camera = 2,
	Turret = 3,
	Drone = 4,
}

import struct gameuiDetectionParams
{
	import var detectionProgress : Float;
}

import class StealthIndicatorGameController extends inkHUDGameController
{
	private var m_rootWidget : weak< inkCompoundWidget >;

	protected event OnInitialize()
	{
		m_rootWidget = ( ( inkCompoundWidget )( GetRootWidget() ) );
	}

}

import class StealthIndicatorPartLogicController extends BaseDirectionalIndicatorPartLogicController
{
	private editable var m_arrowFrontWidget : inkImageRef;
	private editable var m_wrapper : inkCompoundRef;
	private editable var m_stealthIndicatorDeadZoneAngle : Float;
	default m_stealthIndicatorDeadZoneAngle = 40;
	private editable var m_slowestFlashTime : Float;
	default m_slowestFlashTime = .5;
	private var m_rootWidget : weak< inkCompoundWidget >;
	private var m_lastValue : Float;
	private var m_animProxy : inkAnimProxy;
	private var m_flashAnimProxy : inkAnimProxy;
	private var m_scaleAnimDef : inkAnimDef;

	protected event OnInitialize()
	{
		m_rootWidget = ( ( inkCompoundWidget )( GetRootWidget() ) );
		m_lastValue = 0.0;
		OnScaleIn();
	}

	protected event OnUpdateDetection( params : gameuiDetectionParams )
	{
		inkImageRef.SetTexturePart( m_arrowFrontWidget, StringToName( "stealth_fill_00" + RoundF( ClampF( params.detectionProgress, 0.0, 100.0 ) ) ) );
		m_rootWidget.SetState( ( ( params.detectionProgress >= m_lastValue ) ? ( 'Increasing' ) : ( 'Decreasing' ) ) );
		if( ( m_lastValue == 0.0 ) && ( params.detectionProgress != 0.0 ) )
		{
			PlayAnim( 'intro', 'OnIntroComplete', true );
		}
		if( ( m_lastValue == 100.0 ) && ( params.detectionProgress != 100.0 ) )
		{
			PlayAnim( 'intro', 'OnIntroComplete', true );
		}
		if( ( m_lastValue != 100.0 ) && ( params.detectionProgress == 100.0 ) )
		{
			PlayAnim( 'outro', 'OnOutroComplete', true );
		}
		if( ( m_lastValue != 0.0 ) && ( params.detectionProgress == 0.0 ) )
		{
			PlayAnim( 'outro', 'OnOutroComplete', true );
		}
		m_lastValue = params.detectionProgress;
	}

	private function PlayAnim( animName : CName, callback : CName, forceVisible : Bool )
	{
		if( forceVisible )
		{
			m_rootWidget.SetVisible( true );
		}
		m_animProxy = PlayLibraryAnimation( animName );
		m_animProxy.RegisterToCallback( inkanimEventType.OnFinish, this, callback );
	}

	protected event OnHideIndicator()
	{
		m_rootWidget.SetVisible( false );
	}

	protected event OnIntroComplete( proxy : inkAnimProxy ) {}

	protected event OnOutroComplete( proxy : inkAnimProxy )
	{
		m_rootWidget.SetVisible( false );
	}

	private function OnScaleIn()
	{
		var scaleInterpolator : inkAnimScale;
		m_scaleAnimDef = new inkAnimDef;
		scaleInterpolator = new inkAnimScale;
		scaleInterpolator.SetDuration( 0.1 );
		scaleInterpolator.SetStartScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetEndScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetType( inkanimInterpolationType.Linear );
		scaleInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_scaleAnimDef.AddInterpolator( scaleInterpolator );
		m_flashAnimProxy = inkCompoundRef.PlayAnimation( m_wrapper, m_scaleAnimDef );
		m_flashAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnScaleInComplete' );
	}

	protected event OnScaleInComplete( anim : inkAnimProxy )
	{
		m_flashAnimProxy.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnScaleInComplete' );
		OnScreenDelay();
	}

	private function OnScreenDelay()
	{
		var scaleInterpolator : inkAnimScale;
		var duration : Float;
		duration = m_slowestFlashTime - ( m_lastValue / 100.0 );
		m_scaleAnimDef = new inkAnimDef;
		scaleInterpolator = new inkAnimScale;
		scaleInterpolator.SetDuration( duration );
		scaleInterpolator.SetStartScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetEndScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetType( inkanimInterpolationType.Linear );
		scaleInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_scaleAnimDef.AddInterpolator( scaleInterpolator );
		m_flashAnimProxy = inkCompoundRef.PlayAnimation( m_wrapper, m_scaleAnimDef );
		m_flashAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnScreenDelayComplete' );
	}

	protected event OnScreenDelayComplete( anim : inkAnimProxy )
	{
		m_flashAnimProxy.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnScreenDelayComplete' );
		OnScaleOut();
	}

	private function OnScaleOut()
	{
		var scaleInterpolator : inkAnimScale;
		m_scaleAnimDef = new inkAnimDef;
		scaleInterpolator = new inkAnimScale;
		scaleInterpolator.SetDuration( 0.1 );
		scaleInterpolator.SetStartScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetEndScale( Vector2( 1.0, 1.0 ) );
		scaleInterpolator.SetType( inkanimInterpolationType.Linear );
		scaleInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_scaleAnimDef.AddInterpolator( scaleInterpolator );
		m_flashAnimProxy = inkCompoundRef.PlayAnimation( m_wrapper, m_scaleAnimDef );
		m_flashAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnScaleOutComplete' );
	}

	protected event OnScaleOutComplete( anim : inkAnimProxy )
	{
		m_flashAnimProxy.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnScaleOutComplete' );
		OnScaleIn();
	}

	public import function GetDetectionProgress() : Vector4;
}

