enum ESwitchAction { ToggleOn = 0, ToggleActivate = 1, } class SimpleSwitchController extends MasterController { public const override function GetPS() : SimpleSwitchControllerPS { return ( ( SimpleSwitchControllerPS )( GetBasePS() ) ); } } class SimpleSwitchControllerPS extends MasterControllerPS { default m_deviceName = "LocKey#115"; default m_tweakDBRecord = T"Devices.SimpleSwitch"; default m_tweakDBDescriptionRecord = T"device_descriptions.SimpleSwitch"; protected instanceeditable persistent var m_switchAction : ESwitchAction; [ customEditor = "TweakDBGroupInheritance;Interactions.InteractionChoice;Interactions.MountChoice" ] protected instanceeditable var m_nameForON : TweakDBID; [ customEditor = "TweakDBGroupInheritance;Interactions.InteractionChoice;Interactions.MountChoice" ] protected instanceeditable var m_nameForOFF : TweakDBID; protected event OnInstantiated() { super.OnInstantiated(); if( !( IsStringValid( m_deviceName ) ) ) { m_deviceName = "LocKey#115"; } } protected override function Initialize() { super.Initialize(); RefreshSlaves_Event( true ); } public const override function GetExpectedSlaveState() : EDeviceStatus { if( m_switchAction == ESwitchAction.ToggleOn ) { return GetDeviceState(); } return EDeviceStatus.INVALID; } protected const override function GetClearance() : Clearance { return Clearance.CreateClearance( 2, 2 ); } public function IsLightSwitch() : Bool { if( m_switchAction == ESwitchAction.ToggleOn ) { return true; } else { return false; } } public override function GetActions( out outActions : array< DeviceAction >, context : GetActionsContext ) : Bool { super.GetActions( outActions, context ); if( ToggleON.IsDefaultConditionMet( this, context ) ) { outActions.PushBack( ActionToggleON() ); } SetActionIllegality( outActions, 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 = ActionQuickHackToggleON(); currentAction.SetObjectActionID( T"DeviceAction.ToggleStateClassHack" ); currentAction.SetInactiveWithReason( ToggleON.IsDefaultConditionMet( this, context ), "LocKey#7003" ); outActions.PushBack( currentAction ); FinalizeGetQuickHackActions( outActions, context ); } protected export override function OnRefreshSlavesEvent( evt : RefreshSlavesEvent ) : EntityNotificationType { RefreshSlaves( evt.onInitialize ); return EntityNotificationType.DoNotNotifyEntity; } protected virtual function RefreshSlaves( optional onInitialize : Bool ) { var i : Int32; var action : ScriptableDeviceAction; var devices : array< DeviceComponentPS >; var device : ScriptableDeviceComponentPS; devices = GetImmediateSlaves(); action = GetAction(); if( action ) { for( i = 0; i < devices.Size(); i += 1 ) { device = ( ( ScriptableDeviceComponentPS )( devices[ i ] ) ); if( !( device ) ) { continue; } if( onInitialize && device.IsConnectedToCLS() ) { continue; } ExecutePSAction( action, devices[ i ] ); } } } private function GetAction() : ScriptableDeviceAction { var actionToGet : ScriptableDeviceAction; if( m_switchAction == ESwitchAction.ToggleOn ) { if( IsON() ) { actionToGet = ActionSetDeviceON(); } else if( IsOFF() ) { actionToGet = ActionSetDeviceOFF(); } } else if( m_switchAction == ESwitchAction.ToggleActivate ) { if( IsON() ) { actionToGet = ActionActivateDevice(); } else if( IsOFF() ) { actionToGet = ActionDeactivateDevice(); } } return actionToGet; } public override function ActionToggleON() : ToggleON { var action : ToggleON; action = new ToggleON; action.clearanceLevel = DefaultActionsParametersHolder.GetToggleOnClearance(); action.SetUp( this ); action.SetProperties( m_deviceState, m_nameForON, m_nameForOFF ); action.AddDeviceName( m_deviceName ); action.CreateActionWidgetPackage(); action.CreateInteraction(); return action; } public override function OnToggleON( evt : ToggleON ) : EntityNotificationType { var notifier : ActionNotifier; notifier = new ActionNotifier; notifier.SetNone(); super.OnToggleON( evt ); RefreshSlaves(); return EntityNotificationType.SendThisEventToEntity; } protected override function OnQuestForceON( evt : QuestForceON ) : EntityNotificationType { super.OnQuestForceON( evt ); RefreshSlaves(); return EntityNotificationType.SendPSChangedEventToEntity; } protected override function OnQuestForceOFF( evt : QuestForceOFF ) : EntityNotificationType { super.OnQuestForceOFF( evt ); RefreshSlaves(); return EntityNotificationType.SendPSChangedEventToEntity; } }