abstract class InteractionUIBase extends inkHUDGameController
{
	protected var m_InteractionsBlackboard : weak< IBlackboard >;
	protected var m_InteractionsBBDefinition : UIInteractionsDef;
	protected var m_DialogsDataListenerId : CallbackHandle;
	protected var m_DialogsActiveHubListenerId : CallbackHandle;
	protected var m_DialogsSelectedChoiceListenerId : CallbackHandle;
	protected var m_InteractionsDataListenerId : CallbackHandle;
	private var m_lootingDataListenerId : CallbackHandle;
	protected var m_AreDialogsOpen : Bool;
	protected var m_AreContactsOpen : Bool;
	protected var m_IsLootingOpen : Bool;
	protected var m_AreInteractionsOpen : Bool;
	private var m_interactionIsScrollable : Bool;
	private var m_dialogIsScrollable : Bool;
	private var m_lootingIsScrollable : Bool;

	protected event OnInitialize()
	{
		m_AreDialogsOpen = false;
		m_AreContactsOpen = false;
		m_IsLootingOpen = false;
		m_AreInteractionsOpen = false;
		m_InteractionsBlackboard = GetBlackboardSystem().Get( GetAllBlackboardDefs().UIInteractions );
		m_InteractionsBBDefinition = GetAllBlackboardDefs().UIInteractions;
		if( m_InteractionsBlackboard )
		{
			m_DialogsDataListenerId = m_InteractionsBlackboard.RegisterDelayedListenerVariant( m_InteractionsBBDefinition.DialogChoiceHubs, this, 'OnDialogsData' );
			m_DialogsActiveHubListenerId = m_InteractionsBlackboard.RegisterDelayedListenerInt( m_InteractionsBBDefinition.ActiveChoiceHubID, this, 'OnDialogsActivateHub' );
			m_DialogsSelectedChoiceListenerId = m_InteractionsBlackboard.RegisterDelayedListenerInt( m_InteractionsBBDefinition.SelectedIndex, this, 'OnDialogsSelectIndex' );
			m_lootingDataListenerId = m_InteractionsBlackboard.RegisterDelayedListenerVariant( m_InteractionsBBDefinition.LootData, this, 'OnLootingData' );
			m_InteractionsDataListenerId = m_InteractionsBlackboard.RegisterDelayedListenerVariant( m_InteractionsBBDefinition.InteractionChoiceHub, this, 'OnInteractionData' );
			OnDialogsData( m_InteractionsBlackboard.GetVariant( m_InteractionsBBDefinition.DialogChoiceHubs ) );
			OnDialogsActivateHub( m_InteractionsBlackboard.GetInt( m_InteractionsBBDefinition.ActiveChoiceHubID ) );
			OnDialogsSelectIndex( m_InteractionsBlackboard.GetInt( m_InteractionsBBDefinition.SelectedIndex ) );
		}
		OnInteractionsChanged();
	}

	protected event OnUninitialize()
	{
		if( m_InteractionsBlackboard )
		{
			m_InteractionsBlackboard.UnregisterDelayedListener( m_InteractionsBBDefinition.DialogChoiceHubs, m_DialogsDataListenerId );
			m_InteractionsBlackboard.UnregisterDelayedListener( m_InteractionsBBDefinition.ActiveChoiceHubID, m_DialogsActiveHubListenerId );
			m_InteractionsBlackboard.UnregisterDelayedListener( m_InteractionsBBDefinition.SelectedIndex, m_DialogsSelectedChoiceListenerId );
			m_InteractionsBlackboard.UnregisterDelayedListener( m_InteractionsBBDefinition.InteractionChoiceHub, m_InteractionsDataListenerId );
			m_InteractionsBlackboard.UnregisterDelayedListener( m_InteractionsBBDefinition.LootData, m_lootingDataListenerId );
		}
	}

	protected event OnDialogsData( value : Variant )
	{
		var data : DialogChoiceHubs;
		data = ( ( DialogChoiceHubs )value );
		m_AreDialogsOpen = data.choiceHubs.Size() > 0;
		m_dialogIsScrollable = data.choiceHubs.Size() > 1;
		UpdateDialogsData( data );
		OnInteractionsChanged();
		UpdateListBlackboard();
	}

	protected event OnLootingData( value : Variant )
	{
		var data : LootData;
		data = ( ( LootData )value );
		m_lootingIsScrollable = data.isActive && ( data.choices.Size() > 1 );
		UpdateListBlackboard();
	}

	protected virtual function UpdateDialogsData( const data : ref< DialogChoiceHubs > )
	{
		OnInteractionsChanged();
	}

	protected event OnDialogsActivateHub( activeHubId : Int32 )
	{
		OnInteractionsChanged();
	}

	protected event OnDialogsSelectIndex( index : Int32 )
	{
		OnInteractionsChanged();
	}

	protected event OnInteractionData( value : Variant )
	{
		var data : InteractionChoiceHubData;
		data = ( ( InteractionChoiceHubData )value );
		m_AreInteractionsOpen = data.active;
		m_interactionIsScrollable = data.active && ( data.choices.Size() > 1 );
		UpdateInteractionData( data );
		OnInteractionsChanged();
		UpdateListBlackboard();
	}

	protected virtual function UpdateInteractionData( const data : ref< InteractionChoiceHubData > )
	{
		OnInteractionsChanged();
	}

	protected virtual function OnInteractionsChanged() {}

	private function UpdateListBlackboard()
	{
		m_InteractionsBlackboard.SetBool( m_InteractionsBBDefinition.HasScrollableInteraction, ( m_interactionIsScrollable || m_dialogIsScrollable ) || m_lootingIsScrollable );
	}

}

