class drillMachineEvent extends Event
{
	var newTargetDevice : weak< GameObject >;
	var newIsActive : Bool;
}

class drillMachine extends WeaponObject
{
	private var m_rewireComponent : RewireComponent;
	private var m_player : weak< GameObject >;
	private var m_scanManager : DrillMachineScanManager;
	private var m_screen_postprocess : IVisualComponent;
	private var m_screen_backside : IVisualComponent;
	private var m_isScanning : Bool;
	private var m_isActive : Bool;
	private var m_targetDevice : weak< GameObject >;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'ui', 'worlduiWidgetComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'rewire', 'RewireComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'screen_postprocess', 'entMeshComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'screen_backside', 'entSkinnedMeshComponent', false );
		EntityRequestComponentsInterface.RequestComponent( ri, 'scan_manager', 'DrillMachineScanManager', false );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_rewireComponent = ( ( RewireComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'rewire' ) ) );
		m_screen_postprocess = ( ( IVisualComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'screen_postprocess' ) ) );
		m_screen_backside = ( ( IVisualComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'screen_backside' ) ) );
		m_scanManager = ( ( DrillMachineScanManager )( EntityResolveComponentsInterface.GetComponent( ri, 'scan_manager' ) ) );
	}

	protected event OnGameAttached()
	{
		m_player = GetPlayer( GetGame() );
		TogglePostprocess( false );
	}

	protected event OnRewireEvent( evt : RewireEvent )
	{
		switch( evt.state )
		{
			case EDrillMachineRewireState.InsideInteractionRange:
				m_isActive = true;
			break;
			case EDrillMachineRewireState.OutsideInteractionRange:
				m_isActive = false;
		}
	}

	protected event OnScanEvent( evt : DrillScanEvent )
	{
		var drillerScanEvent : DrillerScanEvent;
		drillerScanEvent = new DrillerScanEvent;
		drillerScanEvent.newIsScanning = evt.IsScanning;
		QueueEvent( drillerScanEvent );
	}

	protected event OnPostProcessEvent( evt : DrillScanPostProcessEvent )
	{
		TogglePostprocess( evt.IsEnabled );
		ToggleScreenBack( !( evt.IsEnabled ) );
	}

	private function ToggleScreenBack( isEnable : Bool )
	{
		m_screen_backside.Toggle( isEnable );
	}

	private function TogglePostprocess( isEnable : Bool )
	{
		m_screen_postprocess.Toggle( isEnable );
	}

	private function ToggleMinigameAnimation( isEnable : Bool )
	{
		var animEvt : AnimInputSetterFloat;
		animEvt = new AnimInputSetterFloat;
		animEvt.key = 'rewiring_state';
		animEvt.value = 0.0;
		if( isEnable )
		{
			animEvt.value = 1.0;
		}
		QueueEvent( animEvt );
	}

	private function ToggleFingerAnimation( isEnable : Bool )
	{
		var animEvt : AnimInputSetterInt;
		animEvt = new AnimInputSetterInt;
		animEvt.key = 'driller_stick_pressed';
		animEvt.value = 0;
		if( isEnable )
		{
			animEvt.value = 1;
		}
		GetPlayer( GetGame() ).QueueEvent( animEvt );
		QueueEvent( animEvt );
	}

	protected event OnDrillerInputAction( actionChosen : InteractionChoice ) {}

	protected event OnDrillMachineEvent( evt : drillMachineEvent )
	{
		if( evt.newTargetDevice != NULL )
		{
			m_targetDevice = evt.newTargetDevice;
		}
		if( evt.newIsActive != m_isActive )
		{
			m_isActive = evt.newIsActive;
		}
	}

	public const override function IsActive() : Bool
	{
		return m_isActive;
	}

}

