class blunderbussWeaponController extends inkGameController
{
	private var m_chargeWidgetInitialY : Float;
	private var m_chargeWidgetSize : Vector2;
	private var m_semiAutoModeInfo : weak< inkWidget >;
	private var m_chargeModeInfo : weak< inkWidget >;
	private var m_semiAutoModeIndicator : weak< inkWidget >;
	private var m_chargeModeIndicator : weak< inkWidget >;
	private var m_shots : array< weak< inkWidget > >;
	private var m_charge : weak< inkWidget >;
	private var m_onCharge : CallbackHandle;
	private var m_onTriggerMode : CallbackHandle;
	private var m_onMagazineAmmoCount : CallbackHandle;
	private var m_blackboard : weak< IBlackboard >;

	protected event OnInitialize()
	{
		var item : ItemObject;
		var game : GameInstance;
		var player : PlayerPuppet;
		var id : TweakDBID;
		var weapon : WeaponObject;
		var i, count : Int32;
		var canvas : inkCanvas;
		var panel : inkVerticalPanel;
		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();
		m_onCharge = m_blackboard.RegisterListenerFloat( GetAllBlackboardDefs().Weapon.Charge, this, 'OnCharge' );
		m_onTriggerMode = m_blackboard.RegisterListenerVariant( GetAllBlackboardDefs().Weapon.TriggerMode, this, 'OnTriggerMode' );
		m_onMagazineAmmoCount = m_blackboard.RegisterListenerUint( GetAllBlackboardDefs().Weapon.MagazineAmmoCount, this, 'OnMagazineAmmoCount' );
		m_semiAutoModeInfo = GetWidget( 'Panel/TriggerModeInfoCanvas/SemiAutoModeInfo' );
		m_chargeModeInfo = GetWidget( 'Panel/TriggerModeInfoCanvas/ChargeModeInfo' );
		m_semiAutoModeIndicator = GetWidget( 'Panel/TriggerModeIndicatorsCanvas/SemiAutoModeOn' );
		m_chargeModeIndicator = GetWidget( 'Panel/TriggerModeIndicatorsCanvas/ChargeModeOn' );
		OnTriggerMode( weapon.GetCurrentTriggerMode() );
		panel = ( ( inkVerticalPanel )( m_semiAutoModeInfo ) );
		count = panel.GetNumChildren();
		for( i = 0; i < count; i += 1 )
		{
			canvas = ( ( inkCanvas )( panel.GetWidget( i ) ) );
			m_shots.PushBack( canvas.GetWidget( 'Value' ) );
		}
		OnMagazineAmmoCount( m_blackboard.GetUint( GetAllBlackboardDefs().Weapon.MagazineAmmoCount ) );
		m_charge = ( ( inkRectangle )( GetWidget( 'Panel/TriggerModeInfoCanvas/ChargeModeInfo/Value' ) ) );
		m_chargeWidgetSize = m_charge.GetSize();
		m_chargeWidgetInitialY = m_chargeWidgetSize.Y;
		OnCharge( m_blackboard.GetFloat( GetAllBlackboardDefs().Weapon.Charge ) );
	}

	protected event OnUninitialize()
	{
		m_blackboard.UnregisterListenerFloat( GetAllBlackboardDefs().Weapon.Charge, m_onCharge );
		m_blackboard.UnregisterListenerVariant( GetAllBlackboardDefs().Weapon.TriggerMode, m_onTriggerMode );
		m_blackboard.UnregisterListenerUint( GetAllBlackboardDefs().Weapon.MagazineAmmoCount, m_onMagazineAmmoCount );
		m_shots.Clear();
		OnCharge( 1.0 );
	}

	protected event OnCharge( value : Float )
	{
		m_chargeWidgetSize.Y = m_chargeWidgetInitialY * value;
		m_charge.SetSize( m_chargeWidgetSize );
	}

	protected event OnTriggerMode( value : Variant )
	{
		var isChargeMode : Bool;
		isChargeMode = ( ( TriggerMode_Record )value ).Type() == gamedataTriggerMode.Charge;
		m_semiAutoModeInfo.SetVisible( !( isChargeMode ) );
		m_chargeModeInfo.SetVisible( isChargeMode );
		m_semiAutoModeIndicator.SetVisible( !( isChargeMode ) );
		m_chargeModeIndicator.SetVisible( isChargeMode );
	}

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

}

