class DisplayGlassController extends ScriptableDeviceComponent
{

	public const override function GetPS() : DisplayGlassControllerPS
	{
		return ( ( DisplayGlassControllerPS )( GetBasePS() ) );
	}

}

class DisplayGlassControllerPS extends ScriptableDeviceComponentPS
{
	default m_deviceName = "LocKey#2069";
	default m_tweakDBRecord = T"Devices.DisplayGlass";
	default m_tweakDBDescriptionRecord = T"device_descriptions.DisplayGlass";
	protected instanceeditable var m_isTinted : Bool;
	protected instanceeditable var m_useAppearances : Bool;
	protected instanceeditable var m_clearAppearance : CName;
	protected instanceeditable var m_tintedAppearance : CName;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
	}

	protected override function GameAttached() {}

	public quest const function IsTinted() : Bool
	{
		return m_isTinted;
	}

	public const function UsesAppearances() : Bool
	{
		return m_useAppearances;
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		if( ToggleGlassTint.IsDefaultConditionMet( this, context ) && context.requestType == gamedeviceRequestType.External )
		{
			actions.PushBack( ActionToggleGlassTint() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	protected const override function CanCreateAnyQuickHackActions() : Bool
	{
		return true;
	}

	protected override function GetQuickHackActions( out outActions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		var currentAction : ScriptableDeviceAction;
		currentAction = ActionToggleGlassTintHack();
		currentAction.SetObjectActionID( T"DeviceAction.ToggleStateClassHack" );
		currentAction.SetInactiveWithReason( ToggleGlassTint.IsDefaultConditionMet( this, context ), "LocKey#7003" );
		outActions.PushBack( currentAction );
		FinalizeGetQuickHackActions( outActions, context );
	}

	public override function GetQuestActionByName( actionName : CName ) : DeviceAction
	{
		var action : DeviceAction;
		action = super.GetQuestActionByName( actionName );
		if( action == NULL )
		{
			switch( actionName )
			{
				case 'QuestForceTintGlass':
					action = ActionQuestForceTintGlass();
				break;
				case 'QuestForceClearGlass':
					action = ActionQuestForceClearGlass();
				break;
			}
		}
		return action;
	}

	public override function GetQuestActions( out actions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		super.GetQuestActions( actions, context );
		actions.PushBack( ActionQuestForceTintGlass() );
		actions.PushBack( ActionQuestForceClearGlass() );
	}

	private function ActionQuestForceTintGlass() : QuestForceTintGlass
	{
		var action : QuestForceTintGlass;
		action = new QuestForceTintGlass;
		action.clearanceLevel = DefaultActionsParametersHolder.GetQuestClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		return action;
	}

	public function OnQuestForceTintGlass( evt : QuestForceTintGlass ) : EntityNotificationType
	{
		m_isTinted = true;
		NotifyParents();
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	private function ActionQuestForceClearGlass() : QuestForceClearGlass
	{
		var action : QuestForceClearGlass;
		action = new QuestForceClearGlass;
		action.clearanceLevel = DefaultActionsParametersHolder.GetQuestClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		return action;
	}

	public function OnQuestForceClearGlass( evt : QuestForceClearGlass ) : EntityNotificationType
	{
		m_isTinted = false;
		NotifyParents();
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public function OnToggleGlassTint( evt : ToggleGlassTint ) : EntityNotificationType
	{
		m_isTinted = ( ( m_isTinted ) ? ( false ) : ( true ) );
		NotifyParents();
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	protected function ActionToggleGlassTint() : ToggleGlassTint
	{
		var action : ToggleGlassTint;
		action = new ToggleGlassTint;
		action.clearanceLevel = DefaultActionsParametersHolder.GetToggleOpenClearance();
		action.SetUp( this );
		action.SetProperties( m_isTinted );
		action.AddDeviceName( GetDeviceName() );
		action.CreateInteraction();
		action.CreateActionWidgetPackage();
		return action;
	}

	public function OnToggleGlassTintHack( evt : ToggleGlassTintHack ) : EntityNotificationType
	{
		m_isTinted = ( ( m_isTinted ) ? ( false ) : ( true ) );
		NotifyParents();
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	protected function ActionToggleGlassTintHack() : ToggleGlassTintHack
	{
		var action : ToggleGlassTintHack;
		action = new ToggleGlassTintHack;
		action.clearanceLevel = DefaultActionsParametersHolder.GetToggleOpenClearance();
		action.SetUp( this );
		action.SetProperties( m_isTinted );
		action.AddDeviceName( GetDeviceName() );
		action.CreateInteraction();
		action.CreateActionWidgetPackage();
		return action;
	}

	public const function GetTintAppearance() : CName
	{
		return m_tintedAppearance;
	}

	public const function GetClearAppearance() : CName
	{
		return m_clearAppearance;
	}

	protected override function GetDeviceIconTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.ScreenDeviceIcon";
	}

	protected override function GetBackgroundTextureTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.ScreenDeviceBackground";
	}

}

