import class gameuiScreenProjectionsData extends IScriptable
{
	import var data : array< inkScreenProjection >;
}

import class inkHUDGameController extends inkGameController
{
	protected var m_showAnimDef : inkAnimDef;
	protected var m_hideAnimDef : inkAnimDef;
	private var m_showAnimationName : CName;
	default m_showAnimationName = 'unfold';
	private var m_hideAnimationName : CName;
	default m_hideAnimationName = 'fold';
	private var m_moduleShown : Bool;
	private var m_showAnimProxy : inkAnimProxy;
	private var m_hideAnimProxy : inkAnimProxy;

	protected import function ToggleVisibility( value : Bool, isSkippingInOutAnimation : Bool );

	protected function ShowRequest()
	{
		if( !( m_moduleShown ) )
		{
			m_moduleShown = true;
			GetRootWidget().SetVisible( true );
			if( m_hideAnimProxy )
			{
				m_hideAnimProxy.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnHideAnimationFinished' );
				m_hideAnimProxy.Stop();
				m_hideAnimProxy = NULL;
			}
			if( m_showAnimationName != '' )
			{
				m_showAnimProxy = PlayLibraryAnimation( m_showAnimationName );
			}
		}
	}

	protected function HideRequest()
	{
		if( m_moduleShown )
		{
			m_moduleShown = false;
			if( m_showAnimProxy )
			{
				m_showAnimProxy.Stop();
				m_showAnimProxy = NULL;
			}
			if( m_hideAnimationName != '' )
			{
				m_hideAnimProxy = PlayLibraryAnimation( m_hideAnimationName );
				m_hideAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnHideAnimationFinished' );
			}
			else
			{
				GetRootWidget().SetVisible( false );
			}
		}
	}

	protected function PlayInitFoldingAnim()
	{
		GetRootWidget().SetVisible( false );
		if( m_showAnimProxy )
		{
			m_showAnimProxy.Stop();
			m_showAnimProxy = NULL;
		}
		if( m_hideAnimationName != '' )
		{
			m_hideAnimProxy = PlayLibraryAnimation( m_hideAnimationName );
			m_hideAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnPlayInitFoldingAnimFinished' );
		}
	}

	protected event OnPlayInitFoldingAnimFinished( anim : inkAnimProxy )
	{
		GetRootWidget().SetVisible( true );
	}

	public virtual function UpdateRequired() {}

	protected event OnHideAnimationFinished( anim : inkAnimProxy )
	{
		GetRootWidget().SetVisible( false );
	}

	private function CreateContextChangeAnimations()
	{
		var alphaInterpolator : inkAnimTransparency;
		m_showAnimDef = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartTransparency( 0.0 );
		alphaInterpolator.SetEndTransparency( 1.0 );
		alphaInterpolator.SetDuration( 0.5 );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_showAnimDef.AddInterpolator( alphaInterpolator );
		m_hideAnimDef = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartTransparency( 1.0 );
		alphaInterpolator.SetEndTransparency( 0.0 );
		alphaInterpolator.SetDuration( 0.5 );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_hideAnimDef.AddInterpolator( alphaInterpolator );
	}

	public export virtual function GetIntroAnimation() : inkAnimDef
	{
		if( m_showAnimDef == NULL )
		{
			CreateContextChangeAnimations();
		}
		return m_showAnimDef;
	}

	public export virtual function GetOutroAnimation() : inkAnimDef
	{
		if( m_hideAnimDef == NULL )
		{
			CreateContextChangeAnimations();
		}
		return m_hideAnimDef;
	}

	protected function IsPlayingMultiplayer() : Bool
	{
		var playerObject : GameObject;
		playerObject = ( ( GameObject )( GetOwnerEntity() ) );
		return playerObject && GameInstance.GetRuntimeInfo( playerObject.GetGame() ).IsMultiplayer();
	}

}

import class inkProjectedHUDGameController extends inkHUDGameController
{
	protected import function RegisterScreenProjection( projectionData : inkScreenProjectionData ) : inkScreenProjection;
	protected import function UnregisterScreenProjection( projection : inkScreenProjection );
	protected import function SetShouldNotifyProjections( shouldNotify : Bool );
	protected import function EnableSleeping( enabled : Bool );
	protected import function WakeUp();
	public import function ApplyProjectionMarginOnWidget( widget : weak< inkWidget >, margin : inkMargin );
}

