class DebugNpcNameplateGameController extends inkProjectedHUDGameController
{
	private var m_isToggledOn : Bool;
	private var m_uiBlackboard : weak< IBlackboard >;
	private var m_bbNPCStatsInfo : CallbackHandle;
	private var m_nameplateProjection : inkScreenProjection;
	private var bufferedNPC : weak< GameObject >;
	private var m_rootWidget : weak< inkWidget >;
	private var m_debugText1 : weak< inkText >;
	private var m_debugText2 : weak< inkText >;

	protected event OnInitialize()
	{
		m_isToggledOn = false;
		m_rootWidget = GetRootWidget();
		m_rootWidget.SetVisible( false );
		m_debugText1 = ( ( inkText )( GetWidget( 'flex/vert/debugtext_1' ) ) );
		m_debugText2 = ( ( inkText )( GetWidget( 'flex/vert/debugtext_2' ) ) );
		RegisterDebugCommand( 'OnDebugNpcStats' );
		m_uiBlackboard = GetBlackboardSystem().Get( GetAllBlackboardDefs().UI_NPCNextToTheCrosshair );
		if( m_uiBlackboard )
		{
			m_bbNPCStatsInfo = m_uiBlackboard.RegisterListenerVariant( GetAllBlackboardDefs().UI_NPCNextToTheCrosshair.NameplateData, this, 'OnNameplateDataChanged' );
		}
	}

	protected event OnUninitialize()
	{
		if( m_uiBlackboard )
		{
			m_uiBlackboard.UnregisterListenerVariant( GetAllBlackboardDefs().UI_NPCNextToTheCrosshair.NameplateData, m_bbNPCStatsInfo );
		}
	}

	protected event OnDebugNpcStats()
	{
		var nameplateProjectionData : inkScreenProjectionData;
		m_isToggledOn = !( m_isToggledOn );
		m_rootWidget.SetVisible( m_isToggledOn );
		if( m_isToggledOn )
		{
			nameplateProjectionData.fixedWorldOffset = Vector4( 0.0, 0.0, 0.0, 0.0 );
			nameplateProjectionData.slotComponentName = 'UI_Slots';
			nameplateProjectionData.slotName = 'Nameplate';
			m_nameplateProjection = RegisterScreenProjection( nameplateProjectionData );
		}
		else
		{
			UnregisterScreenProjection( m_nameplateProjection );
		}
	}

	protected event OnNameplateDataChanged( value : Variant )
	{
		var helperString_1, helperString_2 : String;
		var incomingData : NPCNextToTheCrosshair;
		if( !( m_isToggledOn ) )
		{
			return false;
		}
		incomingData = ( ( NPCNextToTheCrosshair )value );
		if( bufferedNPC != incomingData.npc )
		{
			bufferedNPC = incomingData.npc;
			m_nameplateProjection.SetEntity( bufferedNPC );
		}
		if( incomingData.npc != NULL )
		{
			m_rootWidget.SetVisible( true );
			GetNPCDebugNameplateStats( incomingData.npc, helperString_1, helperString_2 );
			HelperUpdateText( helperString_1, helperString_2 );
		}
		else
		{
			m_rootWidget.SetVisible( false );
			m_nameplateProjection.SetEntity( NULL );
		}
	}

	protected event OnScreenProjectionUpdate( projections : gameuiScreenProjectionsData )
	{
		m_rootWidget.SetMargin( inkMargin( projections.data[ 0 ].currentPosition.X, projections.data[ 0 ].currentPosition.Y, 0.0, 0.0 ) );
	}

	private function HelperUpdateText( const argString1 : ref< String >, const argString2 : ref< String > )
	{
		m_debugText1.SetText( argString1 );
		m_debugText2.SetText( argString2 );
	}

	private function GetNPCDebugNameplateStats( obj : GameObject, str_1 : ref< String >, str_2 : ref< String > )
	{
		var temp_str : String;
		var temp_float : Float;
		var system : StatsSystem;
		system = GameInstance.GetStatsSystem( obj.GetGame() );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.Level );
		temp_str += ( "Level: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.PowerLevel );
		temp_str += ( "\nPowerLevel: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.Health );
		temp_str += ( "\nMax Health: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.Evasion );
		temp_str += ( "\nEvasion: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.PhysicalResistance );
		temp_str += ( "\nPhysical Res: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.ThermalResistance );
		temp_str += ( "\nThermal Res: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.ChemicalResistance );
		temp_str += ( "\nChemical Res: " + IntToString( RoundF( temp_float ) ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.ElectricResistance );
		temp_str += ( "\nEMP Res: " + IntToString( RoundF( temp_float ) ) );
		str_1 = temp_str;
		temp_str = "";
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.DPS );
		temp_str = "\nDPS: " + IntToString( RoundF( temp_float ) );
		temp_float = system.GetStatValue( obj.GetEntityID(), gamedataStatType.Accuracy );
		temp_str += ( "\nAccuracy: " + IntToString( RoundF( temp_float ) ) );
		str_2 = temp_str;
	}

}

