Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WorldEntityDelegateEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4  static override array<typename> Requires(IEntityComponentSource src)
5  {
7  }
8 };
9 
14 {
15  [Attribute(params: "et")]
16  protected ResourceName m_EntityPrefab;
17 
18  protected SCR_MenuLayoutEditorComponent m_MenuLayout;
19  protected SCR_EditableWorldEntityComponent m_Delegate;
20  protected IEntity m_TraceEntity;
21  protected bool m_bHasDelegate;
22  protected vector m_vLocalOffset;
23 
28  void PerformFirstAction(IEntity owner)
29  {
30  RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
31  RplId rplId = rplComponent.Id();
32 
33  Rpc(PerformFirstActionServer, rplId);
34  }
35  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
36  protected void PerformFirstActionServer(RplId rplId)
37  {
38  PerformFirstActionBroadcast(rplId);
39  Rpc(PerformFirstActionBroadcast, rplId);
40  }
41  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
42  protected void PerformFirstActionBroadcast(RplId rplId)
43  {
44  RplComponent rplComponent = RplComponent.Cast(Replication.FindItem(rplId));
45  IEntity owner = rplComponent.GetEntity();
46  BaseActionsManagerComponent actionsManager = BaseActionsManagerComponent.Cast(owner.FindComponent(BaseActionsManagerComponent));
47  ScriptedUserAction action = ScriptedUserAction.Cast(actionsManager.GetFirstAction());
48  action.PerformAction(owner, GetOwner());
49  }
50 
51  override protected void EOnFrame(IEntity owner, float timeSlice)
52  {
53  IEntity traceEntity = m_MenuLayout.GetTraceEntity();
54 
55  if (traceEntity != m_TraceEntity)
56  {
57  //--- Check if world entity deserves a delegate
58  m_bHasDelegate = false;
59  if (traceEntity)
60  {
61  SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.GetEditableEntity(traceEntity);
62  if (!editableEntity || !editableEntity.HasEntityState(EEditableEntityState.INTERACTIVE))
63  {
64  BaseActionsManagerComponent actionsManager = BaseActionsManagerComponent.Cast(traceEntity.FindComponent(BaseActionsManagerComponent));
65  if (actionsManager && actionsManager.GetActionsCount() == 1)
66  {
67  ScriptedUserAction action = ScriptedUserAction.Cast(actionsManager.GetFirstAction());
68  m_bHasDelegate = action && action.CanBePerformed(GetManager());
69 
70  if (m_bHasDelegate)
71  {
72  //--- Get action offset
73  array<UserActionContext> contexts = {};
74  actionsManager.GetContextList(contexts);
75  vector transform[4];
76  contexts[0].GetTransformationModel(transform);
77  m_vLocalOffset = transform[3];
78  }
79  }
80  }
81  }
82 
83  m_TraceEntity = traceEntity;
84 
85  if (m_bHasDelegate)
86  {
87  m_Delegate.RestoreParentEntity();
88  m_Delegate.SetOwnerScripted(GenericEntity.Cast(m_TraceEntity));
89  }
90  else
91  {
92  m_Delegate.RemoveParentEntity();
93  m_Delegate.SetOwnerScripted(null);
94  }
95  }
96 
97  //--- Update position to bounding center
98  if (m_TraceEntity && m_bHasDelegate)
99  {
100  vector pos = m_TraceEntity.CoordToParent(m_vLocalOffset);
101  m_Delegate.GetOwner().SetOrigin(pos);
102 
103  //-- Set delegate entity as hovered when just hovering over mesh
104  if (traceEntity == m_TraceEntity)
105  {
107  hoverFilter.SetEntityUnderCursor(m_Delegate, true);
108  }
109  }
110  }
111  override protected void EOnEditorActivate()
112  {
113  IEntity delegateEntity = GetGame().SpawnEntityPrefab(Resource.Load(m_EntityPrefab));
114  m_Delegate = SCR_EditableWorldEntityComponent.Cast(SCR_EditableEntityComponent.GetEditableEntity(delegateEntity));
115  if (!m_Delegate)
116  {
117  Print(string.Format("Cannot create world entity delegate from prefab @\"%1\", it doesn't have SCR_EditableWorldEntityComponent!"), LogLevel.WARNING);
118  RplComponent.DeleteRplEntity(delegateEntity, false);
119  return;
120  }
121 
122  SetEventMask(GetOwner(), EntityEvent.FRAME);
124  }
125  override protected void EOnEditorDeactivate()
126  {
127  if (m_Delegate)
128  m_Delegate.Delete();
129  ClearEventMask(GetOwner(), EntityEvent.FRAME);
130  }
131 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
m_TraceEntity
private IEntity m_TraceEntity
Definition: SCR_CursorEditorUIComponent.c:25
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Delegate
protected SCR_ServicePointDelegateComponent m_Delegate
Definition: SCR_ServicePointComponent.c:23
ScriptedUserAction
Definition: ScriptedUserAction.c:12
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_MenuLayoutEditorComponent
Definition: SCR_MenuLayoutEditorComponent.c:15
SCR_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_WorldEntityDelegateEditorComponent
Definition: SCR_WorldEntityDelegateEditorComponent.c:13
SCR_WorldEntityDelegateEditorComponentClass
Definition: SCR_WorldEntityDelegateEditorComponent.c:2
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180