class NetworkAreaActivationEvent extends Event
{
	var enable : Bool;
}

class NetworkAreaController extends MasterController
{

	public const override function GetPS() : NetworkAreaControllerPS
	{
		return ( ( NetworkAreaControllerPS )( GetBasePS() ) );
	}

}

class NetworkAreaControllerPS extends MasterControllerPS
{
	default m_deviceName = "DBGNetworkName";
	default m_revealDevicesGrid = false;
	default m_drawGridLink = false;
	private var m_isActive : Bool;
	private var m_visualizerID : Uint32;
	private persistent var m_hudActivated : Bool;
	private persistent var m_currentlyAvailableCharges : Int32;
	private persistent var m_maxAvailableCharges : Int32;

	protected override function Initialize()
	{
		super.Initialize();
	}

	public const function AreaEntered()
	{
		var activationEvent : NetworkAreaActivationEvent;
		activationEvent = new NetworkAreaActivationEvent;
		activationEvent.enable = true;
		QueuePSEvent( GetID(), GetClassName(), activationEvent );
	}

	public const function AreaExited()
	{
		var activationEvent : NetworkAreaActivationEvent;
		activationEvent = new NetworkAreaActivationEvent;
		activationEvent.enable = false;
		QueuePSEvent( GetID(), GetClassName(), activationEvent );
	}

	public function OnNetworkAreaActivation( evt : NetworkAreaActivationEvent ) : EntityNotificationType
	{
		if( evt.enable )
		{
			Activate();
		}
		else
		{
			Deactivate();
		}
		return EntityNotificationType.DoNotNotifyEntity;
	}

	private function Activate()
	{
		m_isActive = true;
		if( m_hudActivated )
		{
			UpdateNetrunnerHUD();
		}
	}

	private function Deactivate()
	{
		m_isActive = false;
		HideResourceOnHUD();
	}

	private function HideResourceOnHUD()
	{
		var bioMonitorHUD : IBlackboard;
		var bbSystem : BlackboardSystem;
		bbSystem = GameInstance.GetBlackboardSystem( GetGameInstance() );
		bioMonitorHUD = bbSystem.Get( GetAllBlackboardDefs().UI_PlayerBioMonitor );
		bioMonitorHUD.SetInt( GetAllBlackboardDefs().UI_PlayerBioMonitor.CurrentNetrunnerCharges, -1 );
		GameInstance.GetDebugVisualizerSystem( GetGameInstance() ).ClearLayer( m_visualizerID );
	}

	private function UpdateNetrunnerHUD()
	{
		var bioMonitorHUD : IBlackboard;
		var bbSystem : BlackboardSystem;
		bbSystem = GameInstance.GetBlackboardSystem( GetGameInstance() );
		bioMonitorHUD = bbSystem.Get( GetAllBlackboardDefs().UI_PlayerBioMonitor );
		bioMonitorHUD.SetInt( GetAllBlackboardDefs().UI_PlayerBioMonitor.CurrentNetrunnerCharges, m_currentlyAvailableCharges );
		bioMonitorHUD.SetInt( GetAllBlackboardDefs().UI_PlayerBioMonitor.NetworkChargesCapacity, m_maxAvailableCharges );
		bioMonitorHUD.SetName( GetAllBlackboardDefs().UI_PlayerBioMonitor.NetworkName, StringToName( m_deviceName ) );
		GameInstance.GetDebugVisualizerSystem( GetGameInstance() ).ClearLayer( m_visualizerID );
		m_visualizerID = GameInstance.GetDebugVisualizerSystem( GetGameInstance() ).DrawText( Vector4( 20.0, 550.0, 0.0, 0.0 ), ( ( "NETRUNNER CHARGES: " + IntToString( m_currentlyAvailableCharges ) ) + " / " ) + IntToString( m_maxAvailableCharges ), , SColor.Blue() );
		m_hudActivated = true;
	}

}

