class FastTravelGameController extends inkGameController
{
	private editable var m_fastTravelPointsList : inkCompoundRef;
	private var m_menuEventDispatcher : weak< inkMenuEventDispatcher >;

	protected event OnInitialize()
	{
		Initialize();
	}

	protected event OnSetMenuEventDispatcher( menuEventDispatcher : weak< inkMenuEventDispatcher > )
	{
		m_menuEventDispatcher = menuEventDispatcher;
	}

	private function Initialize()
	{
		var i : Int32;
		var points : array< FastTravelPointData >;
		var currWidget : weak< inkWidget >;
		var controller : FastTravelButtonLogicController;
		points = GetFastTravelSystem().GetFastTravelPoints();
		inkCompoundRef.RemoveAllChildren( m_fastTravelPointsList );
		for( i = 0; i < points.Size(); i += 1 )
		{
			currWidget = SpawnFromLocal( inkCompoundRef.Get( m_fastTravelPointsList ), 'fastTravelPoint' );
			controller = ( ( FastTravelButtonLogicController )( currWidget.GetController() ) );
			if( controller != NULL )
			{
				controller.Initialize( points[ i ] );
				currWidget.RegisterToCallback( 'OnRelease', this, 'OnPerformFastTravel' );
			}
		}
	}

	private function GetFastTravelSystem() : FastTravelSystem
	{
		return ( ( FastTravelSystem )( GameInstance.GetScriptableSystemsContainer( GetOwner().GetGame() ).Get( 'FastTravelSystem' ) ) );
	}

	private function GetOwner() : GameObject
	{
		return ( ( GameObject )( GetOwnerEntity() ) );
	}

	private function PerformFastTravel( pointData : FastTravelPointData, player : GameObject )
	{
		var request : PerformFastTravelRequest;
		if( player == NULL )
		{
			return;
		}
		request = new PerformFastTravelRequest;
		request.pointData = pointData;
		request.player = player;
		GetFastTravelSystem().QueueRequest( request );
	}

	protected event OnPerformFastTravel( e : inkPointerEvent )
	{
		var controller : FastTravelButtonLogicController;
		var player : GameObject;
		if( e.IsAction( 'click' ) )
		{
			controller = ( ( FastTravelButtonLogicController )( e.GetCurrentTarget().GetController() ) );
			if( controller != NULL )
			{
				player = GameInstance.GetPlayerSystem( GetOwner().GetGame() ).GetLocalPlayerMainGameObject();
				PerformFastTravel( controller.GetFastTravelPointData(), player );
				m_menuEventDispatcher.SpawnEvent( 'OnCloseHubMenu' );
			}
		}
	}

}

