class CrosshairWeaponStatsListener extends ScriptStatsListener
{
	private var m_controller : weak< BaseTechCrosshairController >;

	public function Init( controller : BaseTechCrosshairController, stat : gamedataStatType )
	{
		m_controller = controller;
		SetStatType( stat );
	}

	public override function OnStatChanged( ownerID : StatsObjectID, statType : gamedataStatType, diff : Float, total : Float )
	{
		m_controller.OnCrosshairWeaponStatChanged( ownerID, statType, diff, total );
	}

}

class BaseTechCrosshairController extends gameuiCrosshairBaseGameController
{
	private var m_player : weak< GameObject >;
	private var m_statsSystem : StatsSystem;
	private var m_fullChargeAvailable : Bool;
	private var m_overChargeAvailable : Bool;
	private var m_fullChargeListener : CrosshairWeaponStatsListener;
	private var m_overChargeListener : CrosshairWeaponStatsListener;

	protected event OnInitialize()
	{
		m_player = GetPlayerControlledObject();
		m_statsSystem = GameInstance.GetStatsSystem( m_player.GetGame() );
		m_fullChargeAvailable = m_statsSystem.GetStatBoolValue( m_player.GetEntityID(), gamedataStatType.CanFullyChargeWeapon );
		m_overChargeAvailable = m_statsSystem.GetStatBoolValue( m_player.GetEntityID(), gamedataStatType.CanOverchargeWeapon );
		m_fullChargeListener = new CrosshairWeaponStatsListener;
		m_fullChargeListener.Init( this, gamedataStatType.CanFullyChargeWeapon );
		m_statsSystem.RegisterListener( m_player.GetEntityID(), m_fullChargeListener );
		m_overChargeListener = new CrosshairWeaponStatsListener;
		m_overChargeListener.Init( this, gamedataStatType.CanOverchargeWeapon );
		m_statsSystem.RegisterListener( m_player.GetEntityID(), m_overChargeListener );
		inkWidgetRef.SetVisible( m_deadEyeWidget, false );
	}

	protected event OnUnitialize()
	{
		if( m_player )
		{
			m_statsSystem.UnregisterListener( m_player.GetEntityID(), m_fullChargeListener );
			m_statsSystem.UnregisterListener( m_player.GetEntityID(), m_overChargeListener );
		}
	}

	public function OnCrosshairWeaponStatChanged( ownerID : StatsObjectID, statType : gamedataStatType, diff : Float, total : Float )
	{
		switch( statType )
		{
			case gamedataStatType.CanFullyChargeWeapon:
				m_fullChargeAvailable = total > 0.0;
			OnWeaponChargingStatChanged();
			break;
			case gamedataStatType.CanOverchargeWeapon:
				m_overChargeAvailable = total > 0.0;
			OnWeaponChargingStatChanged();
			break;
		}
	}

	protected function IsFullChargeAvailable() : Bool
	{
		return m_fullChargeAvailable;
	}

	protected function IsOverChargeAvailable() : Bool
	{
		return m_overChargeAvailable;
	}

	protected function GetCurrentChargeLimit() : Float
	{
		var weaponObject : WeaponObject;
		weaponObject = ( ( WeaponObject )( GetWeaponItemObject() ) );
		if( IsOverChargeAvailable() )
		{
			return WeaponObject.GetOverchargeThreshold( weaponObject );
		}
		else if( IsFullChargeAvailable() )
		{
			return WeaponObject.GetFullyChargedThreshold( weaponObject );
		}
		else
		{
			return WeaponObject.GetBaseMaxChargeThreshold( weaponObject );
		}
	}

	protected virtual function OnWeaponChargingStatChanged() {}
}

