class NarrativePlateGameController extends inkProjectedHUDGameController
{
	private editable var m_plateHolder : inkWidgetRef;
	private var m_projection : inkScreenProjection;
	private var m_narrativePlateBlackboard : weak< IBlackboard >;
	private var m_narrativePlateBlackboardText : CallbackHandle;
	private var m_logicController : weak< NarrativePlateLogicController >;

	protected event OnInitialize()
	{
		var projectionData : inkScreenProjectionData;
		projectionData.fixedWorldOffset = Vector4( 0.0, 0.0, 0.0, 0.0 );
		projectionData.slotComponentName = 'UI_Slots';
		projectionData.slotName = 'NarrativePlate';
		m_projection = RegisterScreenProjection( projectionData );
		m_logicController = ( ( NarrativePlateLogicController )( inkWidgetRef.GetController( m_plateHolder ) ) );
		m_narrativePlateBlackboard = GetBlackboardSystem().Get( GetAllBlackboardDefs().UI_NarrativePlate );
		m_narrativePlateBlackboardText = m_narrativePlateBlackboard.RegisterDelayedListenerVariant( GetAllBlackboardDefs().UI_NarrativePlate.PlateData, this, 'OnNarrativePlateChanged' );
	}

	protected event OnUnitialize()
	{
		m_narrativePlateBlackboard.UnregisterListenerVariant( GetAllBlackboardDefs().UI_NarrativePlate.PlateData, m_narrativePlateBlackboardText );
	}

	protected event OnScreenProjectionUpdate( projections : gameuiScreenProjectionsData )
	{
		if( m_projection.GetEntity() != NULL )
		{
			inkWidgetRef.SetMargin( m_plateHolder, inkMargin( projections.data[ 0 ].currentPosition.X, projections.data[ 0 ].currentPosition.Y, 0.0, 0.0 ) );
		}
		else
		{
			inkWidgetRef.SetMargin( m_plateHolder, inkMargin( 0.0, 0.0, 0.0, 0.0 ) );
		}
	}

	protected event OnNarrativePlateChanged( value : Variant )
	{
		var plateData : NarrativePlateData;
		plateData = ( ( NarrativePlateData )value );
		m_projection.SetEntity( plateData.entity );
		m_logicController.SetVisible( plateData.entity != NULL );
		m_logicController.SetPlateText( plateData.text, plateData.caption );
	}

}

class NarrativePlateLogicController extends inkLogicController
{
	private editable var m_textWidget : inkWidgetRef;
	private editable var m_captionWidget : inkWidgetRef;
	private editable var m_root : inkWidgetRef;

	public function SetPlateText( const text : ref< String >, const caption : ref< String > )
	{
		var textWidget : weak< inkText >;
		textWidget = ( ( inkText )( inkWidgetRef.Get( m_textWidget ) ) );
		textWidget.SetText( text );
		textWidget = ( ( inkText )( inkWidgetRef.Get( m_captionWidget ) ) );
		textWidget.SetVisible( StrLen( caption ) > 0 );
		textWidget.SetText( caption );
	}

	public function SetVisible( visible : Bool )
	{
		inkWidgetRef.SetVisible( m_root, visible );
	}

}

