class InteractiveAdInkGameController extends DeviceInkGameControllerBase
{
	[ category = "Widget Refs" ]
	private editable var m_ProcessingVideo : inkVideoRef;
	[ category = "Widget Refs" ]
	private editable var m_PersonalAd : inkVideoRef;
	[ category = "Widget Refs" ]
	private editable var m_CommonAd : inkVideoRef;
	protected editable var m_fadeDuration : Float;
	default m_fadeDuration = 0.5f;
	private var m_animFade : inkAnimDef;
	private var m_animOptions : inkAnimOptions;
	private var m_showAd : Bool;
	private var m_onShowAdListener : CallbackHandle;
	private var m_onShowVendorListener : CallbackHandle;

	protected override function SetupWidgets()
	{
		if( !( m_isInitialized ) )
		{
			m_showAd = false;
			StartAdVideo();
		}
	}

	protected function CreateAnimation()
	{
		var fadeInterp : inkAnimTransparency;
		m_animFade = new inkAnimDef;
		fadeInterp = new inkAnimTransparency;
		fadeInterp.SetStartTransparency( 0.0 );
		fadeInterp.SetEndTransparency( 1.0 );
		fadeInterp.SetDuration( m_fadeDuration );
		m_animFade.AddInterpolator( fadeInterp );
		m_animOptions.loopType = inkanimLoopType.None;
	}

	protected override function UpdateActionWidgets( const widgetsData : ref< array< SActionWidgetPackage > > ) {}

	protected override function RegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.RegisterBlackboardCallbacks( blackboard );
		if( blackboard )
		{
			m_onShowAdListener = blackboard.RegisterListenerBool( ( ( InteractiveDeviceBlackboardDef )( GetOwner().GetBlackboardDef() ) ).showAd, this, 'OnShowAd' );
			m_onShowVendorListener = blackboard.RegisterListenerBool( ( ( InteractiveDeviceBlackboardDef )( GetOwner().GetBlackboardDef() ) ).showVendor, this, 'OnShowVendor' );
		}
	}

	protected override function UnRegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.UnRegisterBlackboardCallbacks( blackboard );
		if( blackboard )
		{
			blackboard.UnregisterListenerBool( ( ( InteractiveDeviceBlackboardDef )( GetOwner().GetBlackboardDef() ) ).showAd, m_onShowAdListener );
			blackboard.UnregisterListenerBool( ( ( InteractiveDeviceBlackboardDef )( GetOwner().GetBlackboardDef() ) ).showVendor, m_onShowVendorListener );
		}
	}

	protected event OnShowAd( flag : Bool )
	{
		if( flag )
		{
			inkVideoRef.SetVisible( m_PersonalAd, true );
			inkVideoRef.Play( m_PersonalAd );
		}
		else
		{
			inkVideoRef.SetVisible( m_PersonalAd, false );
			StopProcessingVideo();
		}
	}

	protected event OnShowVendor( flag : Bool )
	{
		StartProcessingVideo();
	}

	protected function StartAdVideo()
	{
		inkVideoRef.Stop( m_CommonAd );
		inkVideoRef.SetVisible( m_CommonAd, true );
		inkVideoRef.Play( m_CommonAd );
	}

	protected function StartProcessingVideo()
	{
		inkVideoRef.Stop( m_ProcessingVideo );
		inkVideoRef.SetVisible( m_ProcessingVideo, true );
		inkVideoRef.Play( m_ProcessingVideo );
	}

	protected function StopProcessingVideo()
	{
		inkVideoRef.Stop( m_ProcessingVideo );
		inkVideoRef.SetVisible( m_ProcessingVideo, false );
	}

	protected override function GetOwner() : Device
	{
		return ( ( Device )( GetOwnerEntity() ) );
	}

	protected override function Refresh( state : EDeviceStatus )
	{
		SetupWidgets();
		super.Refresh( state );
		HideActionWidgets();
		RequestActionWidgetsUpdate();
	}

}

