import class gameuiDriverCombatMountedMissileLauncherCrosshairGameController extends gameuiCrosshairBaseGameController
{
	private editable var m_lockingAnimationWidget : inkWidgetRef;
	private var m_lockingAnimationProxy : inkAnimProxy;
	private var m_psmTrackedTargetChangedCallback : CallbackHandle;
	private var m_currentTarget : weak< IPlacedComponent >;

	protected event OnPlayerAttach( player : GameObject )
	{
		super.OnPlayerAttach( player );
		m_psmTrackedTargetChangedCallback = m_psmBlackboard.RegisterListenerVariant( GetAllBlackboardDefs().PlayerStateMachine.TrackedTarget, this, 'OnPSMTrackedTargetChanged', true );
	}

	protected event OnPlayerDetach( player : GameObject )
	{
		super.OnPlayerDetach( player );
		if( m_psmTrackedTargetChangedCallback )
		{
			m_psmBlackboard.UnregisterListenerVariant( GetAllBlackboardDefs().PlayerStateMachine.TrackedTarget, m_psmTrackedTargetChangedCallback );
		}
	}

	protected event OnPSMTrackedTargetChanged( value : Variant )
	{
		var animation : CName;
		if( m_lockingAnimationProxy && m_lockingAnimationProxy.IsValid() )
		{
			m_lockingAnimationProxy.GotoStartAndStop();
		}
		m_currentTarget = ( ( weak< weak< IPlacedComponent > > )value );
		if( m_currentTarget )
		{
			animation = ( ( PlayerDevelopmentSystem.GetData( m_playerPuppet ).IsNewPerkBoughtAnyLevel( gamedataNewPerkType.Tech_Right_Milestone_1 ) ) ? ( 'locking_short' ) : ( 'locking' ) );
			m_lockingAnimationProxy = PlayLibraryAnimation( animation, inkAnimOptions() );
			inkWidgetRef.SetVisible( m_lockingAnimationWidget, true );
		}
		else
		{
			inkWidgetRef.SetVisible( m_lockingAnimationWidget, false );
		}
	}

	protected export function UpdateLockingAnimationWidgetTranslation( uiScreenResolution : Vector2 )
	{
		var uiWidgetResolution : Vector2;
		var ratio : Vector2;
		var scale : Vector2;
		var projection : Vector2;
		var position : Vector2;
		uiWidgetResolution = Vector2( 3840.0, 2160.0 );
		if( m_currentTarget )
		{
			ratio.X = uiWidgetResolution.X / uiScreenResolution.X;
			ratio.Y = uiWidgetResolution.Y / uiScreenResolution.Y;
			if( ratio.X > ratio.Y )
			{
				scale.X = 1.0;
				scale.Y = ratio.X / ratio.Y;
			}
			else
			{
				scale.X = ratio.Y / ratio.X;
				scale.Y = 1.0;
			}
			projection = ProjectWorldToScreen( Matrix.GetTranslation( m_currentTarget.GetLocalToWorld() ) );
			position.X = ( ( uiWidgetResolution.X * 0.5 ) * projection.X ) * scale.X;
			position.Y = ( ( ( uiWidgetResolution.Y * 0.5 ) * projection.Y ) * -1.0 ) * scale.Y;
			inkWidgetRef.SetTranslation( m_lockingAnimationWidget, position );
		}
	}

	public export override function GetIntroAnimation( firstEquip : Bool ) : inkAnimProxy
	{
		return PlayLibraryAnimation( 'intro' );
	}

	public export override function GetOutroAnimation() : inkAnimProxy
	{
		return PlayLibraryAnimation( 'outro' );
	}

	protected override function OnState_Aim()
	{
		m_rootWidget.SetVisible( true );
	}

}

