enum HighlightContext
{
	DEFAULT = 0,
	OUTLINE = 1,
	FILL = 2,
	FULL = 3,
}

class HighlightModule extends HUDModule
{

	protected override function Process( out task : HUDJob, mode : ActiveMode )
	{
		var instruction : HighlightInstance;
		if( !( task.actor ) )
		{
			return;
		}
		instruction = task.instruction.highlightInstructions;
		if( mode == ActiveMode.FOCUS )
		{
			instruction.SetState( InstanceState.ON, DuplicateLastInstance( task.actor ) );
			if( task.actor.IsRevealed() )
			{
				instruction.SetContext( HighlightContext.FULL, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
				return;
			}
			else if( IsActorLookedAt( task.actor ) )
			{
				instruction.SetContext( HighlightContext.FULL, true, task.actor.IsRevealed() );
				return;
			}
			else
			{
				instruction.SetContext( HighlightContext.FILL, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
				return;
			}
		}
		if( task.actor.IsRevealed() )
		{
			instruction.SetState( InstanceState.ON, DuplicateLastInstance( task.actor ) );
			if( mode == ActiveMode.FOCUS )
			{
				instruction.SetContext( HighlightContext.FULL, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
				return;
			}
			else
			{
				instruction.SetContext( HighlightContext.FULL, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
				return;
			}
		}
		if( m_hud.IsPulseActive() )
		{
			instruction.SetState( InstanceState.ON, DuplicateLastInstance( task.actor ) );
			instruction.SetContext( HighlightContext.FILL, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
			return;
		}
		if( IsActorLooted( task.actor ) )
		{
			instruction.SetState( InstanceState.ON, DuplicateLastInstance( task.actor ) );
			instruction.SetContext( HighlightContext.OUTLINE, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
			return;
		}
		if( IsActorLookedAt( task.actor ) )
		{
			instruction.SetState( InstanceState.HIDDEN, DuplicateLastInstance( task.actor ) );
			instruction.SetContext( HighlightContext.DEFAULT, IsActorLookedAt( task.actor ), task.actor.IsRevealed() );
			return;
		}
		instruction.SetState( InstanceState.DISABLED, DuplicateLastInstance( task.actor ) );
		instruction.SetContext( HighlightContext.DEFAULT, false, task.actor.IsRevealed() );
		return;
	}

	protected override function Process( out jobs : array< HUDJob >, mode : ActiveMode )
	{
		var i : Int32;
		for( i = 0; i < jobs.Size(); i += 1 )
		{
			Process( jobs[ i ], mode );
		}
	}

	public override function Suppress( jobs : ref< array< HUDJob > > )
	{
		var instruction : HighlightInstance;
		var i : Int32;
		for( i = 0; i < jobs.Size(); i += 1 )
		{
			instruction = jobs[ i ].instruction.highlightInstructions;
			instruction.SetState( InstanceState.DISABLED, DuplicateLastInstance( jobs[ i ].actor ) );
			instruction.SetContext( HighlightContext.DEFAULT, false, false );
		}
	}

	protected override function DuplicateLastInstance( actor : HUDActor ) : HighlightInstance
	{
		return ( ( HighlightInstance )( super.DuplicateLastInstance( actor ) ) );
	}

}

class HighlightInstance extends ModuleInstance
{
	var context : HighlightContext;
	var instant : Bool;

	public function SetContext( newContext : HighlightContext, _isLookedAt : Bool, _isRevealed : Bool, optional _instant : Bool )
	{
		context = newContext;
		isLookedAt = _isLookedAt;
		isRevealed = _isRevealed;
		instant = _instant;
	}

	public const function IsInstant() : Bool
	{
		return instant;
	}

	public const function GetContext() : HighlightContext
	{
		return context;
	}

}

