abstract class TriggerModeLogicController extends inkLogicController
{

	public virtual function OnTriggerModeChanged( value : TriggerMode_Record ) {}
}

abstract class AmmoLogicController extends inkLogicController
{
	protected var m_count : Uint32;
	protected var m_capacity : Uint32;

	public virtual function OnMagazineAmmoCountChanged( value : Uint32 )
	{
		m_count = value;
	}

	public virtual function OnMagazineAmmoCapacityChanged( value : Uint32 )
	{
		m_capacity = value;
	}

}

abstract class ChargeLogicController extends inkLogicController
{

	public virtual function OnChargeChanged( value : Float ) {}
}

class weaponIndicatorController extends inkHUDGameController
{
	const editable var m_triggerModeControllers : array< CName >;
	const editable var m_ammoLogicControllers : array< CName >;
	const editable var m_chargeLogicControllers : array< CName >;
	private var m_triggerModeInstances : array< weak< TriggerModeLogicController > >;
	private var m_ammoLogicInstances : array< weak< AmmoLogicController > >;
	private var m_chargeLogicInstances : array< weak< ChargeLogicController > >;
	private var bb : weak< IBlackboard >;
	private var m_blackboard : weak< IBlackboard >;
	private var m_onCharge : CallbackHandle;
	private var m_onTriggerMode : CallbackHandle;
	private var m_onMagazineAmmoCount : CallbackHandle;
	private var m_onMagazineAmmoCapacity : CallbackHandle;
	private var m_BufferedRosterData : SlotDataHolder;
	private var m_ActiveWeapon : SlotWeaponData;
	private var m_InventoryManager : InventoryDataManagerV2;

	protected event OnPlayerAttach( playerPuppet : GameObject )
	{
		var triggerModeInstance : weak< TriggerModeLogicController >;
		var ammoLogicInstance : weak< AmmoLogicController >;
		var chargeLogicInstance : weak< ChargeLogicController >;
		var i, count : Int32;
		var item : ItemObject;
		var game : GameInstance;
		var player : PlayerPuppet;
		var id : TweakDBID;
		var weapon : WeaponObject;
		player = ( ( PlayerPuppet )( playerPuppet ) );
		m_InventoryManager = new InventoryDataManagerV2;
		m_InventoryManager.Initialize( ( ( PlayerPuppet )( playerPuppet ) ) );
		item = ( ( ItemObject )( GetOwnerEntity() ) );
		game = item.GetGame();
		player = GetPlayer( game );
		id = T"AttachmentSlots.WeaponRight";
		weapon = ( ( WeaponObject )( GameInstance.GetTransactionSystem( game ).GetItemInSlot( player, id ) ) );
		m_blackboard = weapon.GetSharedData();
		bb = GetBlackboardSystem().Get( GetAllBlackboardDefs().UI_EquipmentData );
		count = m_triggerModeControllers.Size();
		for( i = 0; i < count; i += 1 )
		{
			triggerModeInstance = ( ( TriggerModeLogicController )( GetController( m_triggerModeControllers[ i ] ) ) );
			if( triggerModeInstance )
			{
				m_triggerModeInstances.PushBack( triggerModeInstance );
			}
		}
		count = m_ammoLogicControllers.Size();
		for( i = 0; i < count; i += 1 )
		{
			ammoLogicInstance = ( ( AmmoLogicController )( GetController( m_ammoLogicControllers[ i ] ) ) );
			if( ammoLogicInstance )
			{
				m_ammoLogicInstances.PushBack( ammoLogicInstance );
			}
		}
		count = m_chargeLogicControllers.Size();
		for( i = 0; i < count; i += 1 )
		{
			chargeLogicInstance = ( ( ChargeLogicController )( GetController( m_chargeLogicControllers[ i ] ) ) );
			if( chargeLogicInstance )
			{
				m_chargeLogicInstances.PushBack( chargeLogicInstance );
			}
		}
		if( m_triggerModeInstances.Size() )
		{
			m_onTriggerMode = m_blackboard.RegisterListenerVariant( GetAllBlackboardDefs().Weapon.TriggerMode, this, 'OnTriggerMode' );
			OnTriggerMode( weapon.GetCurrentTriggerMode() );
		}
		if( m_ammoLogicInstances.Size() )
		{
			m_onMagazineAmmoCount = bb.RegisterListenerVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData, this, 'OnMagazineAmmoCapacity' );
			bb.SignalVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData );
		}
		if( m_chargeLogicInstances.Size() )
		{
			m_onCharge = m_blackboard.RegisterListenerFloat( GetAllBlackboardDefs().Weapon.Charge, this, 'OnCharge' );
			m_blackboard.SignalFloat( GetAllBlackboardDefs().Weapon.Charge );
		}
	}

	protected event OnPlayerDetach( playerPuppet : GameObject )
	{
		if( m_triggerModeInstances.Size() && m_onTriggerMode )
		{
			m_blackboard.UnregisterListenerVariant( GetAllBlackboardDefs().Weapon.TriggerMode, m_onTriggerMode );
		}
		if( m_ammoLogicInstances.Size() && m_onMagazineAmmoCount )
		{
			bb.UnregisterListenerVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData, m_onMagazineAmmoCount );
		}
		if( m_chargeLogicInstances.Size() && m_onCharge )
		{
			m_blackboard.UnregisterListenerFloat( GetAllBlackboardDefs().Weapon.Charge, m_onCharge );
		}
	}

	protected event OnInitialize() {}

	protected event OnUninitialize() {}

	protected event OnCharge( value : Float )
	{
		var i, count : Int32;
		count = m_chargeLogicInstances.Size();
		for( i = 0; i < count; i += 1 )
		{
			m_chargeLogicInstances[ i ].OnChargeChanged( value );
		}
	}

	protected event OnTriggerMode( value : Variant )
	{
		var i, count : Int32;
		count = m_triggerModeInstances.Size();
		for( i = 0; i < count; i += 1 )
		{
			m_triggerModeInstances[ i ].OnTriggerModeChanged( ( ( TriggerMode_Record )value ) );
		}
	}

	protected event OnMagazineAmmoCount( value : Uint32 )
	{
		var i, count : Int32;
		count = m_ammoLogicInstances.Size();
		for( i = 0; i < count; i += 1 )
		{
			m_ammoLogicInstances[ i ].OnMagazineAmmoCountChanged( value );
		}
	}

	protected event OnMagazineAmmoCapacity( value : Variant )
	{
		var i, count : Int32;
		var currentData : SlotWeaponData;
		m_BufferedRosterData = ( ( SlotDataHolder )value );
		currentData = m_BufferedRosterData.weapon;
		if( ItemID.IsValid( currentData.weaponID ) )
		{
			m_ActiveWeapon = currentData;
			count = m_ammoLogicInstances.Size();
			for( i = 0; i < count; i += 1 )
			{
				m_ammoLogicInstances[ i ].OnMagazineAmmoCapacityChanged( ( ( Uint32 )( m_ActiveWeapon.ammoCurrent ) ) );
			}
		}
	}

}

