class NetworkMinigameBufferController extends inkLogicController
{
	protected editable var m_bufferSlotsContainer : inkWidgetRef;
	protected editable var m_elementLibraryName : CName;
	var m_slotList : array< weak< NetworkMinigameElementController > >;
	editable var m_blinker : inkWidgetRef;
	private var m_count : Int32;
	private var m_AnimProxy : inkAnimProxy;
	private var m_AnimOptions : inkAnimOptions;
	private var m_alpha_fadein : inkAnimDef;
	private var currentAlpha : Float;
	private var nextAlpha : Float;

	public function Spawn( size : Int32 )
	{
		var newMargin : inkMargin;
		var slotLogic : weak< NetworkMinigameElementController >;
		var slot : weak< inkWidget >;
		var i : Int32;
		var alphaInterpolator : inkAnimTransparency;
		m_count = 1;
		for( i = 0; i < size; i += 1 )
		{
			slot = SpawnFromLocal( inkWidgetRef.Get( m_bufferSlotsContainer ), m_elementLibraryName );
			slotLogic = ( ( NetworkMinigameElementController )( slot.GetController() ) );
			slotLogic.SetAsBufferSlot();
			m_slotList.PushBack( slotLogic );
		}
		newMargin.left = ( ( Float )( 50 * m_count ) );
		newMargin.top = 11.0;
		inkWidgetRef.SetMargin( m_blinker, newMargin );
		currentAlpha = 0.0;
		nextAlpha = 1.0;
		m_alpha_fadein = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartDelay( 0.5 );
		alphaInterpolator.SetDuration( 0.2 );
		alphaInterpolator.SetStartTransparency( currentAlpha );
		alphaInterpolator.SetEndTransparency( nextAlpha );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_alpha_fadein.AddInterpolator( alphaInterpolator );
		m_AnimOptions.playReversed = false;
		m_AnimOptions.executionDelay = 0.0;
		m_AnimOptions.loopType = inkanimLoopType.Cycle;
		m_AnimOptions.loopCounter = 1;
		m_AnimProxy = inkWidgetRef.PlayAnimationWithOptions( m_blinker, m_alpha_fadein, m_AnimOptions );
		m_AnimProxy.RegisterToCallback( inkanimEventType.OnEndLoop, this, 'OnEndLoop' );
	}

	public function SetEntries( const toSet : ref< array< ElementData > > )
	{
		var newMargin : inkMargin;
		var empity : ElementData;
		var i : Int32;
		var buffLoc : Float;
		for( i = 0; i < m_slotList.Size(); i += 1 )
		{
			m_slotList[ i ].SetContent( ( ( i < toSet.Size() ) ? ( toSet[ i ] ) : ( empity ) ) );
		}
		m_count += 1;
		if( m_count == 2 )
		{
			buffLoc = 165.0;
		}
		if( m_count == 3 )
		{
			buffLoc = 270.0;
		}
		if( m_count == 4 )
		{
			buffLoc = 385.0;
		}
		if( m_count == 5 )
		{
			buffLoc = 495.0;
		}
		if( m_count == 6 )
		{
			buffLoc = 605.0;
		}
		newMargin.left = buffLoc;
		newMargin.top = 11.0;
		inkWidgetRef.SetMargin( m_blinker, newMargin );
	}

	protected event OnEndLoop( proxy : inkAnimProxy )
	{
		var alphaInterpolator : inkAnimTransparency;
		if( currentAlpha == 0.0 )
		{
			currentAlpha = 1.0;
			nextAlpha = 0.0;
		}
		else
		{
			currentAlpha = 0.0;
			nextAlpha = 1.0;
		}
		m_alpha_fadein = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartDelay( 0.5 );
		alphaInterpolator.SetDuration( 0.2 );
		alphaInterpolator.SetStartTransparency( currentAlpha );
		alphaInterpolator.SetEndTransparency( nextAlpha );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_alpha_fadein.AddInterpolator( alphaInterpolator );
		m_AnimProxy.Stop();
		m_AnimProxy.UnregisterFromCallback( inkanimEventType.OnEndLoop, this, 'OnEndLoop' );
		m_AnimProxy = inkWidgetRef.PlayAnimationWithOptions( m_blinker, m_alpha_fadein, m_AnimOptions );
		m_AnimProxy.RegisterToCallback( inkanimEventType.OnEndLoop, this, 'OnEndLoop' );
	}

}

