import class WeaponRosterGameController extends inkHUDGameController
{
	[ category = "on foot weapon roster" ]
	editable var m_weaponName : inkTextRef;
	[ category = "on foot weapon roster" ]
	editable var m_weaponIcon : inkImageRef;
	[ category = "on foot weapon roster" ]
	editable var m_weaponCurrentAmmo : inkTextRef;
	[ category = "on foot weapon roster" ]
	editable var m_weaponTotalAmmo : inkTextRef;
	[ category = "on foot weapon roster" ]
	editable var m_weaponAmmoWrapper : inkWidgetRef;
	[ category = "on foot weapon roster" ]
	editable var m_onFootContainer : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_weaponizedVehicleContainer : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_weaponizedVehicleMissileLauncherContainer : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_weaponizedVehicleMachinegunContainer : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_machinegunAmmo : inkTextRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_machinegunReloadingProgressBar : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_machinegunReloadingProgressBarFill : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_missileLauncherAmmo : inkTextRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_missileLauncherReloadingProgressBar : inkWidgetRef;
	[ category = "Weaponized Vehicle Roster" ]
	editable var m_missileLauncherReloadingProgressBarFill : inkWidgetRef;
	[ category = "Smart Weapons" ]
	private editable var m_smartLinkFirmwareOnline : inkCompoundRef;
	[ category = "Smart Weapons" ]
	private editable var m_smartLinkFirmwareOffline : inkCompoundRef;
	private var m_uiEquipmentDataBlackboard : weak< IBlackboard >;
	private var m_ammoHackedListenerId : CallbackHandle;
	private var m_BBWeaponList : CallbackHandle;
	private var m_BBAmmoLooted : CallbackHandle;
	private var m_dataListenerId : CallbackHandle;
	private var m_onMagazineAmmoCount : CallbackHandle;
	private var m_remoteControlledVehicleDataCallback : CallbackHandle;
	private var m_psmWeaponStateChangedCallback : CallbackHandle;
	private var m_VisionStateBlackboardId : CallbackHandle;
	private var m_weaponParamsListenerId : CallbackHandle;
	private var m_weaponizedVehicleMachineGunAmmoChangedCallback : CallbackHandle;
	private var m_weaponizedVehicleMissileLauncherChargesChangedCallback : CallbackHandle;
	private var m_weaponRecord : WeaponItem_Record;
	private var m_activeWeapon : SlotWeaponData;
	private var m_player : weak< PlayerPuppet >;
	private var m_PlayerMuppet : weak< Muppet >;
	private var m_transitionAnimProxy : inkAnimProxy;
	private var m_outOfAmmoAnim : inkAnimProxy;
	private var m_folded : Bool;
	default m_folded = true;
	private var m_isUnholstered : Bool;
	default m_isUnholstered = false;
	private var m_inVehicle : Bool;
	private var m_inWeaponizedVehicle : Bool;
	default m_inWeaponizedVehicle = false;
	private var m_InventoryManager : InventoryDataManagerV2;
	private var m_weaponItemData : InventoryItemData;
	private var m_weaponizedVehiclePowerWeaponReloadTime : Float;
	default m_weaponizedVehiclePowerWeaponReloadTime = -1.f;
	private var m_weaponizedVehiclePowerWeaponReloadElapsedTime : Float;
	default m_weaponizedVehiclePowerWeaponReloadElapsedTime = -1.f;
	private var m_weaponizedVehicleMissileLauncherMaxCharges : Uint32;
	default m_weaponizedVehicleMissileLauncherMaxCharges = 0;
	private var m_weaponizedVehicleMissileLauncherRechargeTime : Float;
	default m_weaponizedVehicleMissileLauncherRechargeTime = -1.f;
	private var m_weaponizedVehicleMissileLauncherRechargeElapsedTime : Float;
	default m_weaponizedVehicleMissileLauncherRechargeElapsedTime = -1.f;

	protected event OnInitialize()
	{
		PlayInitFoldingAnim();
		inkCompoundRef.SetVisible( m_smartLinkFirmwareOffline, false );
		inkCompoundRef.SetVisible( m_smartLinkFirmwareOnline, false );
	}

	protected event OnUninitialize()
	{
		m_InventoryManager.UnInitialize();
	}

	protected event OnPlayerAttach( playerPuppet : GameObject )
	{
		m_player = ( ( PlayerPuppet )( playerPuppet ) );
		m_PlayerMuppet = ( ( Muppet )( playerPuppet ) );
		m_InventoryManager = new InventoryDataManagerV2;
		m_InventoryManager.Initialize( m_player );
		RegisterBlackboards();
		UpdateVehicleRoster( GameInstance.GetMountingFacility( m_player.GetGame() ).GetMountingInfoSingleWithObjects( m_player ) );
	}

	protected event OnPlayerDetach( playerPuppet : GameObject )
	{
		UnregisterBlackboards();
		m_player = NULL;
		m_PlayerMuppet = NULL;
	}

	protected event OnMountingEvent( evt : MountingEvent )
	{
		if( evt.relationship.relationshipType == gameMountingRelationshipType.Parent && evt.relationship.otherMountableType == gameMountingObjectType.Vehicle )
		{
			UpdateVehicleRoster( evt.request.lowLevelMountingInfo );
		}
	}

	protected event OnUnmountingEvent( evt : UnmountingEvent )
	{
		Fold();
		m_inVehicle = false;
		m_inWeaponizedVehicle = false;
		ResetWeaponizedVehiclePowerWeaponProgressBar();
		ResetWeaponizedVehicleMissileLauncherProgressBar();
	}

	protected event OnUpdate( dT : Float )
	{
		var progress : Float;
		if( ( m_weaponizedVehiclePowerWeaponReloadTime > 0.0 ) && ( m_weaponizedVehiclePowerWeaponReloadElapsedTime != -1.0 ) )
		{
			m_weaponizedVehiclePowerWeaponReloadElapsedTime += dT;
			progress = MinF( m_weaponizedVehiclePowerWeaponReloadElapsedTime / m_weaponizedVehiclePowerWeaponReloadTime, 1.0 );
			inkWidgetRef.SetScale( m_machinegunReloadingProgressBarFill, Vector2( progress, 1.0 ) );
			if( progress >= 1.0 )
			{
				ResetWeaponizedVehiclePowerWeaponProgressBar();
			}
		}
		if( m_weaponizedVehicleMissileLauncherRechargeElapsedTime != -1.0 )
		{
			m_weaponizedVehicleMissileLauncherRechargeElapsedTime += dT;
			progress = MinF( m_weaponizedVehicleMissileLauncherRechargeElapsedTime / m_weaponizedVehicleMissileLauncherRechargeTime, 1.0 );
			inkWidgetRef.SetScale( m_missileLauncherReloadingProgressBarFill, Vector2( progress, 1.0 ) );
			if( progress >= 1.0 )
			{
				m_weaponizedVehicleMissileLauncherRechargeElapsedTime -= m_weaponizedVehicleMissileLauncherRechargeTime;
			}
		}
	}

	private function RegisterBlackboards()
	{
		var psmBlackboard : weak< IBlackboard >;
		var blackboardSystem : BlackboardSystem;
		var uiActiveWeaponDataBlackboard : weak< IBlackboard >;
		var uiActiveVehicleBlackboard : weak< IBlackboard >;
		var uiInteractionsBlackboard : weak< IBlackboard >;
		var uiHackingBlackboard : weak< IBlackboard >;
		blackboardSystem = GetBlackboardSystem();
		uiActiveWeaponDataBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_ActiveWeaponData );
		uiActiveVehicleBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_ActiveVehicleData );
		uiInteractionsBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UIInteractions );
		uiHackingBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_Hacking );
		m_uiEquipmentDataBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_EquipmentData );
		m_dataListenerId = uiInteractionsBlackboard.RegisterDelayedListenerVariant( GetAllBlackboardDefs().UIInteractions.LootData, this, 'OnUpdateData' );
		if( IsPlayingMultiplayer() )
		{
			m_BBWeaponList = m_uiEquipmentDataBlackboard.RegisterListenerVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData, this, 'OnWeaponDataChanged_MP' );
		}
		else
		{
			m_BBWeaponList = m_uiEquipmentDataBlackboard.RegisterListenerVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData, this, 'OnWeaponDataChanged' );
		}
		m_remoteControlledVehicleDataCallback = uiActiveVehicleBlackboard.RegisterListenerVariant( GetAllBlackboardDefs().UI_ActiveVehicleData.RemoteControlledVehicleData, this, 'OnRemoteControlledVehicleChanged', true );
		m_BBAmmoLooted = m_uiEquipmentDataBlackboard.RegisterListenerBool( GetAllBlackboardDefs().UI_EquipmentData.ammoLooted, this, 'OnAmmoLooted' );
		m_uiEquipmentDataBlackboard.SignalVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData );
		m_uiEquipmentDataBlackboard.SignalBool( GetAllBlackboardDefs().UI_EquipmentData.ammoLooted );
		m_onMagazineAmmoCount = uiInteractionsBlackboard.RegisterListenerUint( GetAllBlackboardDefs().Weapon.MagazineAmmoCount, this, 'OnMagazineAmmoCount' );
		m_weaponParamsListenerId = uiActiveWeaponDataBlackboard.RegisterDelayedListenerVariant( GetAllBlackboardDefs().UI_ActiveWeaponData.SmartGunParams, this, 'OnSmartGunParams' );
		m_ammoHackedListenerId = uiHackingBlackboard.RegisterDelayedListenerBool( GetAllBlackboardDefs().UI_Hacking.ammoIndicator, this, 'OnAmmoIndicatorHacked' );
		if( IsPlayingMultiplayer() )
		{
			if( m_PlayerMuppet )
			{
				psmBlackboard = GetPSMBlackboard( m_PlayerMuppet );
				m_VisionStateBlackboardId = psmBlackboard.RegisterListenerInt( GetAllBlackboardDefs().PlayerStateMachine.Vision, this, 'OnPSMVisionStateChanged' );
			}
		}
		else
		{
			if( m_player && m_player.IsControlledByLocalPeer() )
			{
				psmBlackboard = GetPSMBlackboard( m_player );
				m_VisionStateBlackboardId = psmBlackboard.RegisterListenerInt( GetAllBlackboardDefs().PlayerStateMachine.Vision, this, 'OnPSMVisionStateChanged' );
			}
		}
		m_psmWeaponStateChangedCallback = psmBlackboard.RegisterListenerInt( GetAllBlackboardDefs().PlayerStateMachine.Weapon, this, 'OnPSMWeaponStateChanged' );
		m_weaponizedVehicleMachineGunAmmoChangedCallback = uiActiveVehicleBlackboard.RegisterListenerUint( GetAllBlackboardDefs().UI_ActiveVehicleData.MountedPowerWeaponAmmo, this, 'OnWeaponizedVehicleMachineGunAmmoChanged' );
		m_weaponizedVehicleMissileLauncherChargesChangedCallback = uiActiveVehicleBlackboard.RegisterListenerUint( GetAllBlackboardDefs().UI_ActiveVehicleData.MountedMissileLauncherAmmo, this, 'OnWeaponizedVehicleMissileLauncherChargesChanged' );
	}

	private function UnregisterBlackboards()
	{
		var psmBlackboard : weak< IBlackboard >;
		var blackboardSystem : BlackboardSystem;
		var uiActiveWeaponDataBlackboard : weak< IBlackboard >;
		var uiActiveVehicleBlackboard : weak< IBlackboard >;
		var uiInteractionsBlackboard : weak< IBlackboard >;
		var uiHackingBlackboard : weak< IBlackboard >;
		blackboardSystem = GetBlackboardSystem();
		uiActiveWeaponDataBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_ActiveWeaponData );
		uiActiveVehicleBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_ActiveVehicleData );
		uiInteractionsBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UIInteractions );
		uiHackingBlackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_Hacking );
		if( m_weaponizedVehicleMachineGunAmmoChangedCallback )
		{
			uiActiveVehicleBlackboard.UnregisterListenerUint( GetAllBlackboardDefs().UI_ActiveVehicleData.MountedPowerWeaponAmmo, m_weaponizedVehicleMachineGunAmmoChangedCallback );
		}
		if( m_weaponizedVehicleMissileLauncherChargesChangedCallback )
		{
			uiActiveVehicleBlackboard.UnregisterListenerUint( GetAllBlackboardDefs().UI_ActiveVehicleData.MountedMissileLauncherAmmo, m_weaponizedVehicleMissileLauncherChargesChangedCallback );
		}
		if( IsPlayingMultiplayer() )
		{
			if( m_PlayerMuppet )
			{
				psmBlackboard = GetPSMBlackboard( m_PlayerMuppet );
				psmBlackboard.UnregisterListenerInt( GetAllBlackboardDefs().PlayerStateMachine.Vision, m_VisionStateBlackboardId );
			}
		}
		else
		{
			if( m_player )
			{
				psmBlackboard = GetPSMBlackboard( m_player );
				psmBlackboard.UnregisterListenerInt( GetAllBlackboardDefs().PlayerStateMachine.Vision, m_VisionStateBlackboardId );
			}
		}
		if( m_psmWeaponStateChangedCallback )
		{
			psmBlackboard.UnregisterListenerInt( GetAllBlackboardDefs().PlayerStateMachine.Weapon, m_psmWeaponStateChangedCallback );
		}
		if( m_remoteControlledVehicleDataCallback )
		{
			uiActiveVehicleBlackboard.UnregisterListenerVariant( GetAllBlackboardDefs().UI_ActiveVehicleData.RemoteControlledVehicleData, m_remoteControlledVehicleDataCallback );
		}
		m_uiEquipmentDataBlackboard.UnregisterListenerVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData, m_BBWeaponList );
		m_uiEquipmentDataBlackboard.UnregisterListenerBool( GetAllBlackboardDefs().UI_EquipmentData.ammoLooted, m_BBAmmoLooted );
		uiInteractionsBlackboard.UnregisterDelayedListener( GetAllBlackboardDefs().UIInteractions.LootData, m_dataListenerId );
		uiInteractionsBlackboard.UnregisterListenerUint( GetAllBlackboardDefs().Weapon.MagazineAmmoCount, m_onMagazineAmmoCount );
		uiActiveWeaponDataBlackboard.UnregisterDelayedListener( GetAllBlackboardDefs().UI_ActiveWeaponData.SmartGunParams, m_weaponParamsListenerId );
		uiHackingBlackboard.UnregisterDelayedListener( GetAllBlackboardDefs().UI_Hacking.ammoIndicator, m_ammoHackedListenerId );
	}

	protected event OnUpdateData( value : Variant )
	{
		if( m_uiEquipmentDataBlackboard )
		{
			m_uiEquipmentDataBlackboard.SignalVariant( GetAllBlackboardDefs().UI_EquipmentData.EquipmentData );
		}
	}

	protected event OnAmmoIndicatorHacked( value : Bool )
	{
		inkWidgetRef.Get( m_onFootContainer ).SetEffectEnabled( inkEffectType.Glitch, 'hacking', value );
		inkWidgetRef.Get( m_weaponizedVehicleContainer ).SetEffectEnabled( inkEffectType.Glitch, 'hacking', value );
	}

	protected event OnPSMWeaponStateChanged( value : Int32 )
	{
		UpdateWeaponizedVehicleMountedPowerWeaponProgressBarVisibility( ( ( gamePSMRangedWeaponStates )( value ) ) );
	}

	protected event OnPSMVisionStateChanged( value : Int32 )
	{
		switch( ( ( gamePSMVision )( value ) ) )
		{
			case gamePSMVision.Default:
			{
				if( m_isUnholstered )
				{
					Unfold();
				}
				break;
			}
			case gamePSMVision.Focus:
			{
				Fold();
				break;
			}
		}
	}

	protected event OnRemoteControlledVehicleChanged( value : Variant )
	{
		var data : RemoteControlDrivingUIData;
		data = ( ( RemoteControlDrivingUIData )value );
		GetRootWidget().SetVisible( data.remoteControlledVehicle == NULL );
	}

	protected event OnSmartGunParams( argParams : Variant )
	{
		var smartData : smartGunUIParameters;
		smartData = ( ( smartGunUIParameters )argParams );
		if( m_isUnholstered )
		{
			if( RPGManager.GetWeaponEvolution( InventoryItemData.GetID( m_weaponItemData ) ) == gamedataWeaponEvolution.Smart && !( ShouldIgnoreSmartUI() ) )
			{
				inkCompoundRef.SetVisible( m_smartLinkFirmwareOffline, !( smartData.hasRequiredCyberware ) );
				inkCompoundRef.SetVisible( m_smartLinkFirmwareOnline, smartData.hasRequiredCyberware );
			}
			else
			{
				inkCompoundRef.SetVisible( m_smartLinkFirmwareOffline, false );
				inkCompoundRef.SetVisible( m_smartLinkFirmwareOnline, false );
			}
		}
	}

	protected event OnAmmoLooted( value : Bool )
	{
		var allAmmoCount : Int32;
		allAmmoCount = RPGManager.GetAmmoCountValue( m_player, m_activeWeapon.weaponID ) - m_activeWeapon.ammoCurrent;
		inkTextRef.SetText( m_weaponTotalAmmo, GetAmmoText( allAmmoCount, 4 ) );
	}

	protected event OnWeaponDataChanged( value : Variant )
	{
		var data : SlotWeaponData;
		var weaponType : gamedataItemType;
		var item : gameItemData;
		data = ( ( SlotDataHolder )value ).weapon;
		m_isUnholstered = ItemID.IsValid( data.weaponID );
		if( m_isUnholstered )
		{
			if( m_activeWeapon.weaponID != data.weaponID )
			{
				item = m_InventoryManager.GetPlayerItemData( data.weaponID );
				m_weaponItemData = m_InventoryManager.GetInventoryItemData( item );
				m_weaponRecord = TweakDBInterface.GetWeaponItemRecord( ItemID.GetTDBID( data.weaponID ) );
				weaponType = m_weaponRecord.ItemTypeHandle().Type();
				if( weaponType != gamedataItemType.Wea_VehiclePowerWeapon && weaponType != gamedataItemType.Wea_VehicleMissileLauncher )
				{
					LoadWeaponIcon();
					inkTextRef.SetText( m_weaponName, InventoryItemData.GetName( m_weaponItemData ) );
					if( m_weaponRecord.EvolutionHandle().Type() != gamedataWeaponEvolution.Smart || ShouldIgnoreSmartUI() )
					{
						inkCompoundRef.SetVisible( m_smartLinkFirmwareOffline, false );
						inkCompoundRef.SetVisible( m_smartLinkFirmwareOnline, false );
					}
				}
			}
			m_activeWeapon = data;
			SetRosterSlotData();
			Unfold();
		}
		else
		{
			Fold();
		}
	}

	protected event OnWeaponizedVehicleMachineGunAmmoChanged( value : Uint32 )
	{
		var ammoText : String;
		ammoText = GetAmmoText( ( ( Int32 )( value ) ), 3 );
		inkTextRef.SetText( m_machinegunAmmo, ammoText );
	}

	protected event OnWeaponizedVehicleMissileLauncherChargesChanged( value : Uint32 )
	{
		var ammoText : String;
		ammoText = GetAmmoText( ( ( Int32 )( value ) ), 3 );
		inkTextRef.SetText( m_missileLauncherAmmo, ammoText );
		if( value == m_weaponizedVehicleMissileLauncherMaxCharges )
		{
			ResetWeaponizedVehicleMissileLauncherProgressBar();
		}
		else
		{
			if( m_weaponizedVehicleMissileLauncherRechargeElapsedTime == -1.0 )
			{
				m_weaponizedVehicleMissileLauncherRechargeElapsedTime = 0.0;
				inkWidgetRef.SetVisible( m_missileLauncherReloadingProgressBar, true );
			}
		}
	}

	private function Fold()
	{
		if( m_folded )
		{
			return;
		}
		m_folded = true;
		if( m_transitionAnimProxy && m_transitionAnimProxy.IsValid() )
		{
			m_transitionAnimProxy.GotoEndAndStop();
			m_transitionAnimProxy = NULL;
		}
		m_transitionAnimProxy = PlayLibraryAnimation( ( ( m_inWeaponizedVehicle ) ? ( 'fold_vehicles' ) : ( 'fold' ) ) );
	}

	private function Unfold()
	{
		if( !( m_folded ) )
		{
			return;
		}
		m_folded = false;
		if( m_transitionAnimProxy && m_transitionAnimProxy.IsValid() )
		{
			m_transitionAnimProxy.GotoEndAndStop();
			m_transitionAnimProxy = NULL;
		}
		m_transitionAnimProxy = PlayLibraryAnimation( ( ( m_inWeaponizedVehicle ) ? ( 'unfold_vehicles' ) : ( 'unfold' ) ) );
		UpdateWeaponizedVehicleMountedPowerWeaponProgressBarVisibility( ( ( gamePSMRangedWeaponStates )( GetPSMBlackboard( m_player ).GetInt( GetAllBlackboardDefs().PlayerStateMachine.Weapon ) ) ) );
	}

	private function ShouldHideAmmoCount() : Bool
	{
		var weaponType : gamedataItemType;
		weaponType = m_weaponRecord.ItemTypeHandle().Type();
		return ( ( ( ( ( ( ( ( ( ( ( ( ( ( weaponType == gamedataItemType.Wea_Melee || weaponType == gamedataItemType.Wea_Fists ) || weaponType == gamedataItemType.Wea_Hammer ) || weaponType == gamedataItemType.Wea_Katana ) || weaponType == gamedataItemType.Wea_Knife ) || weaponType == gamedataItemType.Wea_OneHandedClub ) || weaponType == gamedataItemType.Wea_ShortBlade ) || weaponType == gamedataItemType.Wea_TwoHandedClub ) || weaponType == gamedataItemType.Wea_LongBlade ) || weaponType == gamedataItemType.Wea_Axe ) || weaponType == gamedataItemType.Wea_Machete ) || weaponType == gamedataItemType.Wea_Chainsword ) || weaponType == gamedataItemType.Wea_Sword ) || weaponType == gamedataItemType.Cyb_NanoWires ) || weaponType == gamedataItemType.Cyb_MantisBlades ) || weaponType == gamedataItemType.Cyb_StrongArms;
	}

	private function SetRosterSlotData()
	{
		var weaponType : gamedataItemType;
		var isWeaponTotalAmmoVisible : Bool;
		var weaponTotalAmmo : Int32;
		var isFist : Bool;
		var iconName : CName;
		var options : inkAnimOptions;
		weaponType = m_weaponRecord.ItemTypeHandle().Type();
		if( m_outOfAmmoAnim && m_outOfAmmoAnim.IsValid() )
		{
			m_outOfAmmoAnim.Stop();
		}
		if( weaponType == gamedataItemType.Wea_VehiclePowerWeapon )
		{
			inkWidgetRef.SetState( m_weaponizedVehicleMachinegunContainer, 'Default' );
			inkWidgetRef.SetState( m_weaponizedVehicleMissileLauncherContainer, 'Disabled' );
			return;
		}
		else if( weaponType == gamedataItemType.Wea_VehicleMissileLauncher )
		{
			inkWidgetRef.SetState( m_weaponizedVehicleMachinegunContainer, 'Disabled' );
			inkWidgetRef.SetState( m_weaponizedVehicleMissileLauncherContainer, 'Default' );
			return;
		}
		if( ShouldHideAmmoCount() )
		{
			inkWidgetRef.SetVisible( m_weaponAmmoWrapper, false );
		}
		else
		{
			if( GameInstance.GetQuestsSystem( m_player.GetGame() ).GetFact( 'q001_hide_ammo_counter' ) == 0 )
			{
				iconName = GetItemTypeIcon();
				weaponTotalAmmo = RPGManager.GetAmmoCountValue( m_player, m_activeWeapon.weaponID ) - m_activeWeapon.ammoCurrent;
				isFist = ( ( m_activeWeapon.ammoCurrent == 0 ) && ( weaponTotalAmmo == 0 ) ) && iconName == '';
				if( !( isFist ) )
				{
					inkTextRef.SetText( m_weaponCurrentAmmo, GetAmmoText( m_activeWeapon.ammoCurrent, 3 ) );
					isWeaponTotalAmmoVisible = !( m_inVehicle ) && !( m_player.IsReplacer() );
					if( isWeaponTotalAmmoVisible )
					{
						inkTextRef.SetText( m_weaponTotalAmmo, GetAmmoText( weaponTotalAmmo, 4 ) );
					}
					inkTextRef.SetVisible( m_weaponTotalAmmo, isWeaponTotalAmmoVisible );
				}
				inkWidgetRef.SetVisible( m_weaponAmmoWrapper, !( isFist ) );
			}
			else
			{
				inkWidgetRef.SetVisible( m_weaponAmmoWrapper, false );
			}
			if( ( ( m_activeWeapon.ammoCurrent == 0 ) && ( weaponTotalAmmo == 0 ) ) && iconName != '' )
			{
				options.loopType = inkanimLoopType.Cycle;
				options.loopInfinite = true;
				m_outOfAmmoAnim = PlayLibraryAnimation( 'out_of_ammo', options );
			}
		}
	}

	private function UpdateVehicleRoster( mountingInfo : MountingInfo )
	{
		var uiActiveVehicleBlackboard : weak< IBlackboard >;
		var vehicle : VehicleObject;
		var vehicleDataPackageRecord : VehicleDataPackage_Record;
		m_inVehicle = EntityID.IsDefined( mountingInfo.parentId );
		Fold();
		if( m_inVehicle )
		{
			vehicle = ( ( VehicleObject )( GameInstance.FindEntityByID( m_player.GetGame(), mountingInfo.parentId ) ) );
			vehicleDataPackageRecord = vehicle.GetRecord().VehDataPackageHandle();
			if( vehicleDataPackageRecord )
			{
				m_inWeaponizedVehicle = vehicleDataPackageRecord.DriverCombat().Type() == gamedataDriverCombatType.MountedWeapons;
				if( m_inWeaponizedVehicle )
				{
					uiActiveVehicleBlackboard = GetBlackboardSystem().Get( GetAllBlackboardDefs().UI_ActiveVehicleData );
					OnWeaponizedVehicleMachineGunAmmoChanged( uiActiveVehicleBlackboard.GetUint( GetAllBlackboardDefs().UI_ActiveVehicleData.MountedPowerWeaponAmmo ) );
					if( vehicle.CanSwitchWeapons() )
					{
						inkWidgetRef.SetVisible( m_weaponizedVehicleMissileLauncherContainer, true );
						m_weaponizedVehicleMissileLauncherMaxCharges = ( ( Uint32 )( GameInstance.GetStatsSystem( m_player.GetGame() ).GetStatValue( m_player.GetEntityID(), gamedataStatType.VehicleMissileLauncherMaxCharges ) ) );
						m_weaponizedVehicleMissileLauncherRechargeTime = GameInstance.GetStatsSystem( m_player.GetGame() ).GetStatValue( m_player.GetEntityID(), gamedataStatType.VehicleMissileLauncherRechargeDuration );
						OnWeaponizedVehicleMissileLauncherChargesChanged( uiActiveVehicleBlackboard.GetUint( GetAllBlackboardDefs().UI_ActiveVehicleData.MountedMissileLauncherAmmo ) );
					}
					else
					{
						inkWidgetRef.SetVisible( m_weaponizedVehicleMissileLauncherContainer, false );
					}
				}
			}
		}
	}

	private function UpdateWeaponizedVehicleMountedPowerWeaponProgressBarVisibility( state : gamePSMRangedWeaponStates )
	{
		var weaponType : gamedataItemType;
		if( m_inWeaponizedVehicle )
		{
			if( state == gamePSMRangedWeaponStates.Reload )
			{
				weaponType = m_weaponRecord.ItemTypeHandle().Type();
				if( weaponType == gamedataItemType.Wea_VehiclePowerWeapon )
				{
					if( m_weaponizedVehiclePowerWeaponReloadTime == -1.0 )
					{
						m_weaponizedVehiclePowerWeaponReloadElapsedTime = 0.0;
						m_weaponizedVehiclePowerWeaponReloadTime = GetPSMBlackboard( m_player ).GetFloat( GetAllBlackboardDefs().PlayerStateMachine.LatestWeaponReloadTime );
						inkWidgetRef.SetVisible( m_machinegunReloadingProgressBar, true );
					}
					return;
				}
			}
		}
	}

	private function ResetWeaponizedVehiclePowerWeaponProgressBar()
	{
		m_weaponizedVehiclePowerWeaponReloadElapsedTime = -1.0;
		m_weaponizedVehiclePowerWeaponReloadTime = -1.0;
		inkWidgetRef.SetVisible( m_machinegunReloadingProgressBar, false );
	}

	private function ResetWeaponizedVehicleMissileLauncherProgressBar()
	{
		m_weaponizedVehicleMissileLauncherRechargeElapsedTime = -1.0;
		inkWidgetRef.SetVisible( m_missileLauncherReloadingProgressBar, false );
	}

	protected event OnWeaponDataChanged_MP( value : Variant )
	{
		var currentData : SlotWeaponData;
		var item : gameItemData;
		var weaponItemType : gamedataItemType;
		currentData = ( ( SlotDataHolder )value ).weapon;
		if( ItemID.IsValid( currentData.weaponID ) )
		{
			if( m_activeWeapon.weaponID != currentData.weaponID )
			{
				item = m_InventoryManager.GetPlayerItemData( currentData.weaponID );
				m_weaponItemData = m_InventoryManager.GetInventoryItemData( item );
			}
			m_activeWeapon = currentData;
			weaponItemType = InventoryItemData.GetItemType( m_weaponItemData );
			SetRosterSlotData_MP( ( ( ( ( ( ( ( ( ( ( ( weaponItemType == gamedataItemType.Wea_Melee || weaponItemType == gamedataItemType.Wea_Fists ) || weaponItemType == gamedataItemType.Wea_Hammer ) || weaponItemType == gamedataItemType.Wea_Katana ) || weaponItemType == gamedataItemType.Wea_Knife ) || weaponItemType == gamedataItemType.Wea_OneHandedClub ) || weaponItemType == gamedataItemType.Wea_ShortBlade ) || weaponItemType == gamedataItemType.Wea_TwoHandedClub ) || weaponItemType == gamedataItemType.Wea_LongBlade ) || weaponItemType == gamedataItemType.Wea_Axe ) || weaponItemType == gamedataItemType.Wea_Machete ) || weaponItemType == gamedataItemType.Wea_Chainsword ) || weaponItemType == gamedataItemType.Wea_Sword );
			Unfold();
			if( RPGManager.GetWeaponEvolution( InventoryItemData.GetID( m_weaponItemData ) ) != gamedataWeaponEvolution.Smart || ShouldIgnoreSmartUI() )
			{
				inkCompoundRef.SetVisible( m_smartLinkFirmwareOffline, false );
				inkCompoundRef.SetVisible( m_smartLinkFirmwareOnline, false );
			}
		}
		else
		{
			Fold();
		}
	}

	private function SetRosterSlotData_MP( isMelee : Bool )
	{
		var iconName : CName;
		var allAmmoCount : Int32;
		var showAmmoCounter : Bool;
		var options : inkAnimOptions;
		options.loopType = inkanimLoopType.Cycle;
		options.loopInfinite = true;
		allAmmoCount = RPGManager.GetAmmoCountValue( m_PlayerMuppet, m_activeWeapon.weaponID ) - m_activeWeapon.ammoCurrent;
		inkTextRef.SetText( m_weaponCurrentAmmo, GetAmmoText( m_activeWeapon.ammoCurrent, 3 ) );
		inkTextRef.SetText( m_weaponTotalAmmo, GetAmmoText( allAmmoCount, 4 ) );
		showAmmoCounter = GameInstance.GetQuestsSystem( m_PlayerMuppet.GetGame() ).GetFact( 'q001_hide_ammo_counter' ) == 0;
		inkTextRef.SetVisible( m_weaponCurrentAmmo, showAmmoCounter );
		inkTextRef.SetVisible( m_weaponTotalAmmo, showAmmoCounter && !( m_PlayerMuppet.IsReplacer() ) );
		if( m_outOfAmmoAnim && m_outOfAmmoAnim.IsPlaying() )
		{
			m_outOfAmmoAnim.Stop();
		}
		iconName = GetItemTypeIcon();
		LoadWeaponIcon();
		if( isMelee )
		{
			inkTextRef.SetVisible( m_weaponCurrentAmmo, false );
			inkTextRef.SetVisible( m_weaponTotalAmmo, false );
		}
		else
		{
			if( ( ( m_activeWeapon.ammoCurrent == 0 ) && ( allAmmoCount == 0 ) ) && iconName != '' )
			{
				m_outOfAmmoAnim = PlayLibraryAnimation( 'out_of_ammo', options );
			}
			else
			{
				if( m_outOfAmmoAnim )
				{
					m_outOfAmmoAnim.Stop();
				}
			}
			if( ( ( m_activeWeapon.ammoCurrent == 0 ) && ( allAmmoCount == 0 ) ) && iconName == '' )
			{
				inkTextRef.SetVisible( m_weaponCurrentAmmo, false );
				inkTextRef.SetVisible( m_weaponTotalAmmo, false );
			}
		}
		inkTextRef.SetText( m_weaponName, InventoryItemData.GetName( m_weaponItemData ) );
	}

	private function LoadWeaponIcon()
	{
		InkImageUtils.RequestSetImage( this, m_weaponIcon, m_weaponRecord.HudIcon().GetID() );
	}

	private function GetItemTypeIcon() : CName
	{
		switch( InventoryItemData.GetItemType( m_weaponItemData ) )
		{
			case gamedataItemType.Wea_AssaultRifle:
				return 'tech_rifle';
			case gamedataItemType.Wea_Handgun:
				return 'pistol';
			case gamedataItemType.Wea_Katana:
				return 'katana';
			case gamedataItemType.Wea_Sword:
				return 'katana';
			case gamedataItemType.Wea_Knife:
				return 'katana';
			case gamedataItemType.Wea_LightMachineGun:
				return 'smart_gun';
			case gamedataItemType.Wea_LongBlade:
				return 'katana';
			case gamedataItemType.Wea_Axe:
				return 'katana';
			case gamedataItemType.Wea_Chainsword:
				return 'katana';
			case gamedataItemType.Wea_Machete:
				return 'katana';
			case gamedataItemType.Wea_Melee:
				return 'tech_rifle';
			case gamedataItemType.Wea_OneHandedClub:
				return 'tech_rifle';
			case gamedataItemType.Wea_PrecisionRifle:
				return 'tech_rifle';
			case gamedataItemType.Wea_Revolver:
				return 'pistol';
			case gamedataItemType.Wea_Rifle:
				return 'tech_rifle';
			case gamedataItemType.Wea_ShortBlade:
				return 'katana';
			case gamedataItemType.Wea_Shotgun:
				return 'shotgun';
			case gamedataItemType.Wea_ShotgunDual:
				return 'shotgun';
			case gamedataItemType.Wea_SniperRifle:
				return 'tech_rifle';
			case gamedataItemType.Wea_SubmachineGun:
				return 'smart_gun';
			case gamedataItemType.Wea_TwoHandedClub:
				return 'katana';
			case gamedataItemType.Wea_Fists:
				return 'katana';
			default:
				return '';
		}
		return '';
	}

	private function GetAmmoText( ammoCount : Int32, textLength : Int32 ) : String
	{
		return SpaceFill( IntToString( Max( ammoCount, 0 ) ), textLength, ESpaceFillMode.JustifyRight, "0" );
	}

	private function ShouldIgnoreSmartUI() : Bool
	{
		return TweakDBInterface.GetBool( ItemID.GetTDBID( InventoryItemData.GetID( m_weaponItemData ) ) + T".ignoreSmartCrosshair", false );
	}

}

