class Crosshair_ChargeBar extends gameuiCrosshairBaseGameController
{
	private editable var m_bar : inkWidgetRef;
	private editable var m_ammo : inkTextRef;
	private var m_leftPart : weak< inkWidget >;
	private var m_rightPart : weak< inkWidget >;
	private var m_topPart : weak< inkWidget >;
	private var m_chargeBar : weak< inkRectangle >;
	private var m_sizeOfChargeBar : Vector2;
	private var m_chargeBBID : CallbackHandle;

	protected event OnInitialize()
	{
		super.OnInitialize();
		m_leftPart = ( ( inkWidget )( GetWidget( 'left' ) ) );
		m_rightPart = ( ( inkWidget )( GetWidget( 'right' ) ) );
		m_topPart = ( ( inkWidget )( GetWidget( 'top' ) ) );
		m_chargeBar = ( ( inkRectangle )( GetWidget( 'chargeBar/chargeBarFG' ) ) );
		m_sizeOfChargeBar = m_chargeBar.GetSize();
	}

	protected event OnPreIntro()
	{
		super.OnPreIntro();
		if( m_targetBB )
		{
			m_chargeBBID = m_targetBB.RegisterListenerFloat( GetAllBlackboardDefs().Weapon.Charge, this, 'OnChargeChanged' );
		}
	}

	protected event OnPreOutro()
	{
		if( m_targetBB )
		{
			m_targetBB.UnregisterListenerFloat( GetAllBlackboardDefs().Weapon.Charge, m_chargeBBID );
		}
		super.OnPreOutro();
	}

	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 m_rootWidget.PlayAnimation( anim );
	}

	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 );
	}

	protected event OnBulletSpreadChanged( spread : Vector2 )
	{
		super.OnBulletSpreadChanged( spread );
		m_leftPart.SetMargin( inkMargin( -( spread.X ), 0.0, 0.0, 0.0 ) );
		m_rightPart.SetMargin( inkMargin( spread.X, 0.0, 0.0, 0.0 ) );
		m_topPart.SetMargin( inkMargin( 0.0, -( spread.Y ), 0.0, 0.0 ) );
	}

	protected function OnChargeChanged( charge : Float )
	{
		m_chargeBar.SetSize( Vector2( MinF( m_sizeOfChargeBar.X, charge * 100.0 ), m_sizeOfChargeBar.Y ) );
	}

	protected override function ApplyCrosshairGUIState( state : CName, aimedAtEntity : Entity )
	{
		m_leftPart.SetState( state );
		m_rightPart.SetState( state );
		m_topPart.SetState( state );
	}

}

