class MessageCounterController extends inkGameController
{
	protected editable var m_messageCounter : inkTextRef;
	private var m_rootWidget : weak< inkWidget >;
	private var m_CallInformationBBID : CallbackHandle;
	private var m_journalManager : weak< JournalManager >;
	private var m_Owner : weak< GameObject >;

	protected event OnInitialize()
	{
		m_rootWidget = GetRootWidget();
		m_Owner = ( ( GameObject )( GetPlayerControlledObject() ) );
		m_journalManager = GameInstance.GetJournalManager( m_Owner.GetGame() );
		m_journalManager.RegisterScriptCallback( this, 'OnJournalUpdate', gameJournalListenerType.State );
		UpdateData();
	}

	protected event OnUnitialize()
	{
		m_journalManager.UnregisterScriptCallback( this, 'OnJournalUpdate' );
	}

	public function UpdateData()
	{
		var contacts : array< weak< JournalEntry > >;
		var context : JournalRequestContext;
		var i, unreadedMessages : Int32;
		unreadedMessages = 0;
		context.stateFilter.active = true;
		m_journalManager.GetContacts( context, contacts );
		for( i = 0; i < contacts.Size(); i += 1 )
		{
			if( contacts[ i ] )
			{
				if( !( m_journalManager.IsEntryVisited( contacts[ i ] ) ) )
				{
					unreadedMessages = unreadedMessages + 1;
				}
			}
		}
		inkTextRef.SetText( m_messageCounter, IntToString( unreadedMessages ) );
		m_rootWidget.SetVisible( unreadedMessages != 0 );
	}

	protected event OnJournalUpdate( entryHash : Uint32, className : CName, notifyOption : JournalNotifyOption, changeType : JournalChangeType )
	{
		UpdateData();
	}

}

