class MenuHubLogicController extends inkLogicController
{
	private editable var m_menuObject : inkWidgetRef;
	private editable var m_btnCrafting : inkWidgetRef;
	private editable var m_btnPerks : inkWidgetRef;
	private editable var m_btnStats : inkWidgetRef;
	private editable var m_btnInventory : inkWidgetRef;
	private editable var m_btnBackpack : inkWidgetRef;
	private editable var m_btnCyberware : inkWidgetRef;
	private editable var m_btnMap : inkWidgetRef;
	private editable var m_btnJournal : inkWidgetRef;
	private editable var m_btnPhone : inkWidgetRef;
	private editable var m_btnTarot : inkWidgetRef;
	private editable var m_btnShard : inkWidgetRef;
	private editable var m_btnCodex : inkWidgetRef;
	private editable var m_panelInventory : inkWidgetRef;
	private editable var m_panelJournal : inkWidgetRef;
	private editable var m_panelCharacter : inkWidgetRef;
	private var m_menusData : MenuDataBuilder;
	private var m_tooltipsManager : weak< gameuiTooltipsManager >;
	private editable var m_tooltipsManagerRef : inkWidgetRef;

	protected event OnInitialize()
	{
		m_tooltipsManager = ( ( gameuiTooltipsManager )( inkWidgetRef.GetControllerByType( m_tooltipsManagerRef, 'gameuiTooltipsManager' ) ) );
		m_tooltipsManager.Setup( ETooltipsStyle.Menus );
		( ( MenuItemController )( inkWidgetRef.GetController( m_btnInventory ) ) ).SetHoverPanel( m_panelInventory );
		( ( MenuItemController )( inkWidgetRef.GetController( m_btnJournal ) ) ).SetHoverPanel( m_panelJournal );
		( ( MenuItemController )( inkWidgetRef.GetController( m_btnPerks ) ) ).SetHoverPanel( m_panelCharacter );
		SetActive( true );
	}

	protected event OnUninitialize()
	{
		SetActive( false );
	}

	protected event OnSelectByCursor( evt : SelectMenuRequest )
	{
		var currentMenuItem : MenuItemController;
		var openMenuEvt : OpenMenuRequest;
		currentMenuItem = evt.m_eventData;
		if( currentMenuItem )
		{
			openMenuEvt = new OpenMenuRequest;
			openMenuEvt.m_eventData = currentMenuItem.m_menuData;
			openMenuEvt.m_isMainMenu = true;
			openMenuEvt.m_jumpBack = currentMenuItem.IsHyperlink();
			QueueEvent( openMenuEvt );
		}
	}

	public function SetMenusData( menuData : MenuDataBuilder, perkPoints, attrPoints : Int32 )
	{
		var dataCharacter : MenuData;
		m_menusData = menuData;
		HubMenuUtils.SetMenuData( m_btnCrafting, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Crafting ) ) ) );
		dataCharacter = m_menusData.GetData( ( ( Int32 )( HubMenuItems.Character ) ) );
		dataCharacter.attrFlag = attrPoints > 0;
		dataCharacter.perkFlag = perkPoints > 0;
		dataCharacter.attrText = ( ( Int32 )( attrPoints ) );
		dataCharacter.perkText = ( ( Int32 )( perkPoints ) );
		HubMenuUtils.SetMenuData( m_btnPerks, dataCharacter );
		HubMenuUtils.SetMenuData( m_btnStats, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Stats ) ) ) );
		HubMenuUtils.SetMenuData( m_btnInventory, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Inventory ) ) ) );
		HubMenuUtils.SetMenuData( m_btnBackpack, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Backpack ) ) ) );
		HubMenuUtils.SetMenuData( m_btnCyberware, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Cyberware ) ) ) );
		HubMenuUtils.SetMenuData( m_btnMap, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Map ) ) ) );
		HubMenuUtils.SetMenuData( m_btnJournal, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Journal ) ) ) );
		HubMenuUtils.SetMenuData( m_btnPhone, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Phone ) ) ) );
		HubMenuUtils.SetMenuData( m_btnTarot, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Tarot ) ) ) );
		HubMenuUtils.SetMenuData( m_btnCodex, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Codex ) ) ) );
		HubMenuUtils.SetMenuData( m_btnShard, m_menusData.GetData( ( ( Int32 )( HubMenuItems.Shards ) ) ) );
	}

	public function SetActive( isActive : Bool )
	{
		inkWidgetRef.SetVisible( m_menuObject, isActive );
		if( isActive )
		{
			RegisterToGlobalInputCallback( 'OnPostOnRelease', this, 'OnSelectByButton' );
		}
		else
		{
			UnregisterFromGlobalInputCallback( 'OnPostOnRelease', this, 'OnSelectByButton' );
		}
	}

	public function SelectMenuExternally( menuName : CName, optional submenuName : CName, optional userData : IScriptable )
	{
		var evt : OpenMenuRequest;
		var subMenuData : array< MenuData >;
		var evtMenuData : MenuData;
		evt = new OpenMenuRequest;
		evt.m_menuName = menuName;
		if( userData )
		{
			evt.m_eventData.userData = userData;
			evt.m_eventData.m_overrideDefaultUserData = true;
			if( IsNameValid( submenuName ) )
			{
				evtMenuData.userData = userData;
				subMenuData.PushBack( evtMenuData );
				evt.m_eventData.subMenus = subMenuData;
				evt.m_eventData.m_overrideSubMenuUserData = true;
			}
		}
		evt.m_submenuName = submenuName;
		evt.m_isMainMenu = true;
		QueueEvent( evt );
	}

}

