class HubMenuInstanceData extends IScriptable
{
	var m_ID : Uint32;
}

class MenuScenario_HubMenu extends MenuScenario_BaseMenu
{
	var m_hubMenuInitData : weak< HubMenuInitData >;
	var m_currentState : weak< inkMenusState >;
	var m_combatRestriction : Bool;
	var m_hubMenuInstanceID : Uint32;

	public constexpr function GetMenuName() : CName
	{
		return 'hub_menu';
	}

	protected override function GotoIdleState()
	{
		var hubMenuInstanceData : HubMenuInstanceData;
		if( m_currMenuName != GetMenuName() )
		{
			CloseMenu();
			m_currentState.CloseMenu( GetMenuName() );
			m_currentState.OpenMenu( GetMenuName(), m_hubMenuInitData );
			m_currMenuName = GetMenuName();
			m_hubMenuInstanceID += ( ( Uint32 )( 1 ) );
			hubMenuInstanceData = new HubMenuInstanceData;
			hubMenuInstanceData.m_ID = m_hubMenuInstanceID;
			m_currentState.DispatchEvent( m_currMenuName, 'OnHubMenuInstanceData', hubMenuInstanceData );
		}
		else
		{
			super.GotoIdleState();
		}
	}

	protected event OnEnterScenario( prevScenario : CName, userData : IScriptable )
	{
		var hubCtrl : MenuHubLogicController;
		var hubMenu : weak< inkWidget >;
		var hubMenuInstanceData : HubMenuInstanceData;
		m_hubMenuInitData = ( ( HubMenuInitData )( userData ) );
		m_combatRestriction = m_hubMenuInitData.m_combatRestriction;
		m_currentState = GetMenusState();
		m_currentState.OpenMenu( GetMenuName(), m_hubMenuInitData );
		m_currMenuName = GetMenuName();
		m_hubMenuInstanceID = 1;
		hubMenuInstanceData = new HubMenuInstanceData;
		hubMenuInstanceData.m_ID = m_hubMenuInstanceID;
		m_currentState.DispatchEvent( m_currMenuName, 'OnHubMenuInstanceData', hubMenuInstanceData );
		hubMenu = m_currentState.GetMenu( GetMenuName() );
		if( m_hubMenuInitData )
		{
			hubCtrl = ( ( MenuHubLogicController )( hubMenu.GetControllerByType( 'MenuHubLogicController' ) ) );
			hubCtrl.SelectMenuExternally( m_hubMenuInitData.m_menuName, m_hubMenuInitData.m_submenuName, m_hubMenuInitData.m_userData );
		}
	}

	protected event OnNetworkBreachBegin()
	{
		GotoIdleState();
		SwitchToScenario( 'MenuScenario_NetworkBreach' );
	}

	protected event OnSwitchToTimeManager()
	{
		OpenSubMenu( 'time_manager' );
	}

	protected event OnSelectMenuItem( userData : IScriptable )
	{
		var isFullscreenDifferent : Bool;
		var isDataDifferent : Bool;
		var menuItemData : MenuItemData;
		menuItemData = ( ( MenuItemData )( userData ) );
		isFullscreenDifferent = menuItemData.m_menuData.fullscreenName != '' && menuItemData.m_menuData.fullscreenName != m_currMenuName;
		isDataDifferent = menuItemData.m_menuData.userData != m_currUserData;
		if( isFullscreenDifferent || isDataDifferent )
		{
			OnOpenMenu( menuItemData.m_menuData.fullscreenName, menuItemData.m_menuData.userData );
		}
	}

	protected event OnOpenMenu( menuName : CName, optional userData : IScriptable )
	{
		var menuState : weak< inkMenusState >;
		menuState = GetMenusState();
		if( m_currMenuName != '' && m_currMenuName != GetMenuName() )
		{
			menuState.DispatchEvent( m_currMenuName, 'OnCloseMenu' );
			menuState.CloseMenu( m_currMenuName );
		}
		m_currMenuName = menuName;
		menuState.OpenMenu( m_currMenuName, userData );
	}

	protected event OnCloseHubMenu()
	{
		GotoIdleState();
	}

	protected event OnRequestHubMenu()
	{
		super.GotoIdleState();
	}

	protected event OnCloseHubMenuRequest()
	{
		super.GotoIdleState();
	}

	protected event OnHotkeySwitchToMap()
	{
		ToggleMenu( 'world_map' );
	}

	protected event OnHotkeySwitchToCrafting()
	{
		if( !( m_combatRestriction ) )
		{
			ToggleMenu( 'crafting_main' );
		}
	}

	protected event OnHotkeySwitchToJournal()
	{
		ToggleMenu( 'quest_log' );
	}

	protected event OnHotkeySwitchToInventory()
	{
		ToggleMenu( 'inventory_screen' );
	}

	protected event OnHotkeySwitchToPerks()
	{
		ToggleMenu( 'new_perks' );
	}

	public function ToggleMenu( menuName : CName )
	{
		var evt : OpenMenuRequest;
		if( m_currMenuName == menuName )
		{
			OnCloseHubMenuRequest();
		}
		else
		{
			evt = new OpenMenuRequest;
			evt.m_menuName = menuName;
			evt.m_isMainMenu = true;
			QueueBroadcastEvent( evt );
		}
	}

}

class MenuScenario_RadialHubMenu extends MenuScenario_BaseMenu
{
	var m_hubMenuInitData : weak< HubMenuInitData >;
	var m_currentState : weak< inkMenusState >;
	var m_combatRestriction : Bool;
	var m_hubMenuInstanceID : Uint32;

	public constexpr function GetMenuName() : CName
	{
		return 'radial_hub_menu';
	}

	protected override function GotoIdleState()
	{
		var hubMenuInstanceData : HubMenuInstanceData;
		if( m_currMenuName != GetMenuName() )
		{
			CloseMenu();
			m_currentState.CloseMenu( GetMenuName() );
			m_currentState.OpenMenu( GetMenuName(), m_hubMenuInitData );
			m_currMenuName = GetMenuName();
			m_hubMenuInstanceID += ( ( Uint32 )( 1 ) );
			hubMenuInstanceData = new HubMenuInstanceData;
			hubMenuInstanceData.m_ID = m_hubMenuInstanceID;
			m_currentState.DispatchEvent( m_currMenuName, 'OnHubMenuInstanceData', hubMenuInstanceData );
		}
		else
		{
			super.GotoIdleState();
		}
	}

	protected event OnEnterScenario( prevScenario : CName, userData : IScriptable )
	{
		var hubCtrl : RadialMenuHubLogicController;
		var hubMenu : weak< inkWidget >;
		var hubMenuInstanceData : HubMenuInstanceData;
		m_hubMenuInitData = ( ( HubMenuInitData )( userData ) );
		m_combatRestriction = m_hubMenuInitData.m_combatRestriction;
		m_currentState = GetMenusState();
		m_currentState.OpenMenu( GetMenuName(), m_hubMenuInitData );
		m_currMenuName = GetMenuName();
		m_hubMenuInstanceID = 102400;
		hubMenuInstanceData = new HubMenuInstanceData;
		hubMenuInstanceData.m_ID = m_hubMenuInstanceID;
		m_currentState.DispatchEvent( m_currMenuName, 'OnHubMenuInstanceData', hubMenuInstanceData );
		hubMenu = m_currentState.GetMenu( GetMenuName() );
		if( m_hubMenuInitData )
		{
			hubCtrl = ( ( RadialMenuHubLogicController )( hubMenu.GetControllerByType( 'RadialMenuHubLogicController' ) ) );
			hubCtrl.SelectMenuExternally( m_hubMenuInitData.m_menuName, m_hubMenuInitData.m_submenuName, m_hubMenuInitData.m_userData );
		}
	}

	protected event OnNetworkBreachBegin()
	{
		GotoIdleState();
		SwitchToScenario( 'MenuScenario_NetworkBreach' );
	}

	protected event OnSwitchToTimeManager()
	{
		OpenSubMenu( 'time_manager' );
	}

	protected event OnSelectMenuItem( userData : IScriptable )
	{
		var isFullscreenDifferent : Bool;
		var isDataDifferent : Bool;
		var menuItemData : MenuItemData;
		menuItemData = ( ( MenuItemData )( userData ) );
		isFullscreenDifferent = menuItemData.m_menuData.fullscreenName != '' && menuItemData.m_menuData.fullscreenName != m_currMenuName;
		isDataDifferent = menuItemData.m_menuData.userData != m_currUserData;
		if( isFullscreenDifferent || isDataDifferent )
		{
			OnOpenMenu( menuItemData.m_menuData.fullscreenName, menuItemData.m_menuData.userData );
		}
	}

	protected event OnOpenMenu( menuName : CName, optional userData : IScriptable )
	{
		var menuState : weak< inkMenusState >;
		menuState = GetMenusState();
		if( m_currMenuName != '' && m_currMenuName != GetMenuName() )
		{
			menuState.DispatchEvent( m_currMenuName, 'OnCloseMenu' );
			menuState.CloseMenu( m_currMenuName );
		}
		m_currMenuName = menuName;
		menuState.OpenMenu( m_currMenuName, userData );
	}

	protected event OnCloseHubMenu()
	{
		GotoIdleState();
	}

	protected event OnRequestHubMenu()
	{
		super.GotoIdleState();
	}

	protected event OnCloseHubMenuRequest()
	{
		super.GotoIdleState();
	}

	protected event OnHotkeySwitchToMap()
	{
		ToggleMenu( 'world_map' );
	}

	protected event OnHotkeySwitchToCrafting()
	{
		if( !( m_combatRestriction ) )
		{
			ToggleMenu( 'crafting_main' );
		}
	}

	protected event OnHotkeySwitchToJournal()
	{
		ToggleMenu( 'quest_log' );
	}

	protected event OnHotkeySwitchToInventory()
	{
		ToggleMenu( 'inventory_screen' );
	}

	protected event OnHotkeySwitchToPerks()
	{
		ToggleMenu( 'new_perks' );
	}

	public function ToggleMenu( menuName : CName )
	{
		var evt : OpenMenuRequest;
		if( m_currMenuName == menuName )
		{
			OnCloseHubMenuRequest();
		}
		else
		{
			evt = new OpenMenuRequest;
			evt.m_menuName = menuName;
			evt.m_isMainMenu = true;
			QueueBroadcastEvent( evt );
		}
	}

}

