struct ScrollingText
{
	const editable var textArray : array< String >;
}

class textScrollingAnimController extends inkLogicController
{
	editable var m_scannerDetailsHackLog : inkTextRef;
	editable var m_defaultScrollSpeed : Float;
	default m_defaultScrollSpeed = 0.05f;
	editable var m_playOnInit : Bool;
	default m_playOnInit = false;
	editable var m_numOfLines : Int32;
	default m_numOfLines = 4;
	editable var m_numOfStartingLines : Int32;
	default m_numOfStartingLines = 0;
	editable var m_transparency : Float;
	default m_transparency = 1.0f;
	editable var m_gapIndex : Int32;
	default m_gapIndex = 0;
	editable var m_binaryOnly : Bool;
	default m_binaryOnly = false;
	editable var m_binaryClusterCount : Int32;
	default m_binaryClusterCount = 4;
	editable var m_scrollingText : ScrollingText;
	private var m_logArray : array< String >;
	private var m_upload_counter : Float;
	private var m_scrollSpeed : Float;
	private var m_fastScrollSpeed : Float;
	private var m_panel : weak< inkCompoundWidget >;
	private var m_alpha_fadein : inkAnimDef;
	private var m_AnimProxy : inkAnimProxy;
	private var m_AnimOptions : inkAnimOptions;
	private var m_lineCount : Int32;

	protected event OnInitialize()
	{
		m_panel.SetVisible( false );
		m_fastScrollSpeed = 0.05;
		m_logArray.Resize( m_numOfLines + 15 );
		inkTextRef.SetText( m_scannerDetailsHackLog, "" );
		if( m_playOnInit )
		{
			StartScroll();
		}
	}

	public function StartScroll( optional fast : Bool )
	{
		var alphaInterpolator : inkAnimTransparency;
		var i : Int32;
		m_panel.SetVisible( true );
		inkTextRef.SetText( m_scannerDetailsHackLog, "" );
		m_upload_counter = 0.0;
		m_logArray.Clear();
		m_logArray.Resize( m_numOfLines + 15 );
		inkTextRef.StopAllAnimations( m_scannerDetailsHackLog );
		m_scrollSpeed = ( ( fast ) ? ( m_fastScrollSpeed ) : ( m_defaultScrollSpeed ) );
		if( m_numOfStartingLines > 0 )
		{
			for( i = 0; i < m_numOfStartingLines; i += 1 )
			{
				m_upload_counter += 1.0;
				AddToHackLog( RoundF( m_upload_counter ) );
			}
		}
		m_alpha_fadein = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetDuration( m_scrollSpeed );
		alphaInterpolator.SetStartTransparency( m_transparency );
		alphaInterpolator.SetEndTransparency( m_transparency );
		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.loopInfinite = true;
		m_AnimProxy = inkTextRef.PlayAnimationWithOptions( m_scannerDetailsHackLog, m_alpha_fadein, m_AnimOptions );
		m_AnimProxy.RegisterToCallback( inkanimEventType.OnEndLoop, this, 'OnEndLoop' );
	}

	public function StopScroll()
	{
		m_AnimProxy.Stop();
		m_AnimProxy.UnregisterFromCallback( inkanimEventType.OnEndLoop, this, 'OnEndLoop' );
		m_panel.SetVisible( false );
		inkTextRef.SetText( m_scannerDetailsHackLog, "" );
		m_upload_counter = 0.0;
		m_logArray.Clear();
		m_logArray.Resize( m_numOfLines + 15 );
		inkTextRef.StopAllAnimations( m_scannerDetailsHackLog );
	}

	private function AddToHackLog( count : Int32 )
	{
		var s : String;
		var sOut : String;
		var i : Int32;
		var j : Int32;
		for( i = 1; i < ( m_logArray.Size() - 1 ); i += 1 )
		{
			m_logArray[ i ] = m_logArray[ i + 1 ];
		}
		for( j = 0; j < m_binaryClusterCount; j += 1 )
		{
			for( i = 0; i < 4; i += 1 )
			{
				s = s + RoundF( RandRangeF( 0.0, 2.0 ) );
			}
			s = s + " ";
		}
		j = RoundF( RandRangeF( 0.0, 15.0 ) );
		if( j < 6 )
		{
			s = s + "\n";
		}
		if( ( m_gapIndex != 0 ) && ( m_lineCount >= m_gapIndex ) )
		{
			m_lineCount = 0;
			s = "\n\n";
		}
		else
		{
			if( m_binaryOnly )
			{
				s = s + "\n";
			}
			else
			{
				if( m_scrollingText.textArray.Size() == 0 )
				{
					j = RoundF( RandRangeF( 0.0, ( ( Float )( m_numOfLines ) ) ) );
					if( j == 0 )
					{
						s = "Checking sent packets... Success\n";
					}
					if( j == 1 )
					{
						s = "Clearing bufffers... Success\n";
					}
					if( j == 2 )
					{
						s = "Resizing buffer... Success\n";
					}
					if( j == 3 )
					{
						s = "Pinging connection... Done\n";
					}
					if( j == 4 )
					{
						s = "Clearing logs... Done\n";
					}
				}
				else
				{
					j = RoundF( RandRangeF( 0.0, ( ( Float )( m_scrollingText.textArray.Size() ) ) ) );
					s = m_scrollingText.textArray[ j ];
				}
			}
		}
		m_logArray[ m_numOfLines ] = s;
		sOut = "Port Probe V42.6A.9V.6B\n";
		for( i = 0; i < m_logArray.Size(); i += 1 )
		{
			sOut = sOut + m_logArray[ i ];
		}
		inkTextRef.SetText( m_scannerDetailsHackLog, sOut );
		m_lineCount += 1;
	}

	protected event OnEndLoop( proxy : inkAnimProxy )
	{
		m_upload_counter += 1.0;
		AddToHackLog( RoundF( m_upload_counter ) );
	}

}

