class NetRunnerChargesGameController extends inkGameController
{
	editable var m_header : inkTextRef;
	editable var m_list : inkCompoundRef;
	editable var m_bar : inkWidgetRef;
	editable var m_value : inkTextRef;
	private var m_blackboard : weak< IBlackboard >;
	private var m_bbDefinition : UI_PlayerBioMonitorDef;
	private var m_netrunnerCapacityId : Uint32;
	private var m_netrunnerCurrentId : CallbackHandle;
	private var m_currentCharges : Int32;
	private var m_maxCharges : Int32;
	private var m_chargesList : array< weak< NetRunnerListItem > >;
	private var m_root : weak< inkWidget >;

	protected event OnInitialize()
	{
		m_root = GetRootWidget();
		inkCompoundRef.RemoveAllChildren( m_list );
		SetupBB();
	}

	protected event OnUnitialize()
	{
		RemoveBB();
	}

	private function SetupBB()
	{
		m_bbDefinition = GetAllBlackboardDefs().UI_PlayerBioMonitor;
		m_blackboard = GetBlackboardSystem().Get( m_bbDefinition );
		if( m_blackboard )
		{
			m_netrunnerCurrentId = m_blackboard.RegisterDelayedListenerFloat( m_bbDefinition.MemoryPercent, this, 'OnNetrunnerChargesUpdated' );
			OnNetrunnerChargesUpdated( m_blackboard.GetFloat( m_bbDefinition.MemoryPercent ) );
		}
	}

	private function RemoveBB()
	{
		if( m_blackboard )
		{
			m_blackboard.UnregisterDelayedListener( m_bbDefinition.MemoryPercent, m_netrunnerCurrentId );
		}
		m_blackboard = NULL;
	}

	protected event OnNetrunnerChargesUpdated( value : Float )
	{
		var normalizedValue : Int32;
		var scaledValue : Float;
		normalizedValue = ( ( Int32 )( value ) );
		scaledValue = value / 100.0;
		inkTextRef.SetText( m_value, ( ( String )( normalizedValue ) ) + "%" );
		inkWidgetRef.SetScale( m_bar, Vector2( scaledValue, 1.0 ) );
		if( value >= 100.0 )
		{
			Hide();
		}
		else
		{
			Show();
		}
	}

	public function Show()
	{
		m_root.SetVisible( true );
	}

	public function Hide()
	{
		m_root.SetVisible( false );
	}

}

class NetRunnerListItem extends inkLogicController
{
	editable var m_highlight : inkWidgetRef;

	protected event OnInitialize() {}

	public function ShowHighlight()
	{
		inkWidgetRef.SetVisible( m_highlight, true );
	}

	public function HideHighlight()
	{
		inkWidgetRef.SetVisible( m_highlight, false );
	}

}

