class ScreenMessageData extends IScriptable
{
	var m_messageRecord : ScreenMessageData_Record;
	var m_replaceTextWithCustomNumber : Bool;
	var m_customNumber : Int32;
}

class SetMessageRecordEvent extends Event
{
	[ customEditor = "TweakDBGroupInheritance;ScreenMessageData" ]
	editable var m_messageRecordID : TweakDBID;
	editable var m_replaceTextWithCustomNumber : Bool;
	editable var m_customNumber : Int32;

	public constexpr function GetFriendlyDescription() : String
	{
		return "Set Message Record";
	}

}

class LcdScreenController extends ScriptableDeviceComponent
{

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

}

class LcdScreenControllerPS extends ScriptableDeviceComponentPS
{
	default m_deviceName = "LocKey#193";
	default m_tweakDBRecord = T"Devices.LcdScreen";
	default m_tweakDBDescriptionRecord = T"device_descriptions.LcdScreen";
	default m_disableQuickHacks = true;
	default m_hasAuthorizationModule = true;
	[ category = "UI" ][ customEditor = "TweakDBGroupInheritance;ScreenMessageData" ]
	private instanceeditable persistent var m_messageRecordID : TweakDBID;
	[ category = "UI" ]
	private instanceeditable persistent var m_replaceTextWithCustomNumber : Bool;
	[ category = "UI" ]
	private instanceeditable persistent var m_customNumber : Int32;
	[ category = "UI" ]
	private inlined persistent var m_messageRecordSelector : ScreenMessageSelector;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
		if( !( IsStringValid( m_deviceName ) ) )
		{
			m_deviceName = "Gameplay-Devices-DisplayNames-Screen";
		}
	}

	private function OnSetMessageRecord( evt : SetMessageRecordEvent ) : EntityNotificationType
	{
		m_messageRecordID = evt.m_messageRecordID;
		m_replaceTextWithCustomNumber = evt.m_replaceTextWithCustomNumber;
		m_customNumber = evt.m_customNumber;
		if( m_messageRecordSelector )
		{
			m_messageRecordSelector.SetRecordID( evt.m_messageRecordID );
			m_messageRecordSelector.SetReplaceTextWithCustomNumber( evt.m_replaceTextWithCustomNumber );
			m_messageRecordSelector.SetCustomNumber( evt.m_customNumber );
		}
		return EntityNotificationType.SendThisEventToEntity;
	}

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

	protected override function GetQuickHackActions( out outActions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		var currentAction : ScriptableDeviceAction;
		currentAction = ActionGlitchScreen( T"DeviceAction.GlitchScreenSuicide", T"QuickHack.SuicideHackBase" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		outActions.PushBack( currentAction );
		currentAction = ActionGlitchScreen( T"DeviceAction.GlitchScreenBlind", T"QuickHack.BlindHack" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		outActions.PushBack( currentAction );
		currentAction = ActionGlitchScreen( T"DeviceAction.GlitchScreenGrenade", T"QuickHack.GrenadeHackBase" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		outActions.PushBack( currentAction );
		if( !( GlitchScreen.IsDefaultConditionMet( this, context ) ) )
		{
			SetActionsInactiveAll( outActions, "LocKey#7003" );
		}
		currentAction = ActionQuickHackDistraction();
		currentAction.SetObjectActionID( T"DeviceAction.MalfunctionClassHack" );
		currentAction.SetDurationValue( GetDistractionDuration( currentAction ) );
		currentAction.SetInactiveWithReason( QuickHackDistraction.IsDefaultConditionMet( this, context ), "LocKey#7003" );
		outActions.PushBack( currentAction );
		if( IsGlitching() || IsDistracting() )
		{
			SetActionsInactiveAll( outActions, "LocKey#7004" );
		}
		FinalizeGetQuickHackActions( outActions, context );
	}

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

	public const override function GetBlackboardDef() : LcdScreenBlackBoardDef
	{
		return GetAllBlackboardDefs().LcdScreenBlackBoard;
	}

	public const function HasCustomNumber() : Bool
	{
		return m_replaceTextWithCustomNumber;
	}

	public const function GetCustomNumber() : Int32
	{
		return m_customNumber;
	}

	public const function GetMessageRecordID() : TweakDBID
	{
		var id : TweakDBID;
		if( m_messageRecordSelector )
		{
			id = m_messageRecordSelector.GetRecordID();
		}
		if( !( TDBID.IsValid( id ) ) )
		{
			id = m_messageRecordID;
		}
		return id;
	}

	protected function SetMessageRecordID( id : TweakDBID )
	{
		m_messageRecordID = id;
		if( m_messageRecordSelector )
		{
			m_messageRecordSelector.SetRecordID( id );
		}
	}

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

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

}

