class CrosshairGameController_Mantis_Blade extends gameuiCrosshairBaseGameController
{
	private var m_weaponBBID : CallbackHandle;
	private var m_meleeWeaponState : gamePSMMeleeWeapon;
	private editable var m_targetColorChange : inkWidgetRef;
	private var holdAnim : inkAnimProxy;
	private var aimAnim : inkAnimProxy;
	private var m_isInHoldState : Bool;
	private var m_meleeLeapAttackObjectTagger : MeleeLeapAttackObjectTagger;

	protected event OnPlayerAttach( playerPuppet : GameObject )
	{
		var playerSMBB : IBlackboard;
		playerSMBB = GetPSMBlackboard( playerPuppet );
		m_weaponBBID = playerSMBB.RegisterDelayedListenerInt( GetAllBlackboardDefs().PlayerStateMachine.MeleeWeapon, this, 'OnPSMMeleeWeaponStateChanged' );
		OnPSMMeleeWeaponStateChanged( playerSMBB.GetInt( GetAllBlackboardDefs().PlayerStateMachine.MeleeWeapon ) );
		m_meleeLeapAttackObjectTagger = new MeleeLeapAttackObjectTagger;
		m_meleeLeapAttackObjectTagger.SetUp( playerPuppet );
		super.OnPreIntro();
	}

	protected event OnPlayerDetach( playerPuppet : GameObject )
	{
		var playerSMBB : IBlackboard;
		if( m_weaponBBID )
		{
			playerSMBB = GetPSMBlackboard( playerPuppet );
			playerSMBB.UnregisterDelayedListener( GetAllBlackboardDefs().PlayerStateMachine.MeleeWeapon, m_weaponBBID );
		}
	}

	protected event OnPSMMeleeWeaponStateChanged( value : Int32 )
	{
		var oldState, newState : gamePSMMeleeWeapon;
		oldState = m_meleeWeaponState;
		newState = ( ( gamePSMMeleeWeapon )( value ) );
		if( oldState != newState )
		{
			m_meleeWeaponState = newState;
			OnMeleeWeaponStateChange( oldState, newState );
		}
	}

	private function OnMeleeWeaponStateChange( oldState : gamePSMMeleeWeapon, newState : gamePSMMeleeWeapon )
	{
		switch( newState )
		{
			case gamePSMMeleeWeapon.ChargedHold:
			case gamePSMMeleeWeapon.Hold:
				OnState_Hold();
			break;
			default:
				OnState_Default();
			break;
		}
	}

	public override function GetIntroAnimation( firstEquip : Bool ) : inkAnimProxy
	{
		var anim : inkAnimDef;
		var alphaInterpolator : inkAnimTransparency;
		anim = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartTransparency( 0.0 );
		alphaInterpolator.SetEndTransparency( 1.0 );
		alphaInterpolator.SetDuration( 0.25 );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		anim.AddInterpolator( alphaInterpolator );
		return GetRootWidget().PlayAnimation( anim );
	}

	protected override function ApplyCrosshairGUIState( state : CName, aimedAtEntity : Entity )
	{
		inkWidgetRef.SetState( m_targetColorChange, state );
		UpdateTargetIndicator();
	}

	public function UpdateTargetIndicator()
	{
		if( m_targetEntity && m_isInHoldState )
		{
			m_meleeLeapAttackObjectTagger.SetVisionOnTargetObj( m_targetEntity, GetDistanceToTarget() );
		}
	}

	public override function GetOutroAnimation() : inkAnimProxy
	{
		var anim : inkAnimDef;
		var alphaInterpolator : inkAnimTransparency;
		anim = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartTransparency( 1.0 );
		alphaInterpolator.SetEndTransparency( 0.0 );
		alphaInterpolator.SetDuration( 0.25 );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		anim.AddInterpolator( alphaInterpolator );
		return m_rootWidget.PlayAnimation( anim );
	}

	private function PlayAnimation( animName : CName ) : inkAnimProxy
	{
		var m_animationProxy : inkAnimProxy;
		m_animationProxy = PlayLibraryAnimation( animName );
		return m_animationProxy;
	}

	protected function OnState_Hold()
	{
		if( holdAnim.IsPlaying() )
		{
			holdAnim.Stop();
		}
		holdAnim = PlayAnimation( 'go_to_hold_state' );
		m_isInHoldState = true;
		m_meleeLeapAttackObjectTagger.SetVisionOnTargetObj( m_targetEntity, GetDistanceToTarget() );
		UpdateCrosshairGUIState( false );
	}

	protected function OnState_Default()
	{
		if( aimAnim.IsPlaying() )
		{
			aimAnim.Stop();
		}
		aimAnim = PlayAnimation( 'go_to_default_state' );
		m_isInHoldState = false;
		m_meleeLeapAttackObjectTagger.ResetVisionOnTargetObj();
		UpdateCrosshairGUIState( false );
	}

}

