Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AttachManualCameraComponent.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6 {
7  [Attribute(defvalue: "0")]
8  protected bool m_bRotateWithTarget;
9 
10  [Attribute(string.Format("%1", EAttachManualCameraType.INPUT), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EAttachManualCameraType))]
11  private EAttachManualCameraType m_AttachType;
12 
13  [Attribute(params: "layout")]
14  private ResourceName m_Layout;
15 
16  protected IEntity m_Target;
17  protected SCR_AttachEntity m_AttachHelper;
18  protected bool m_bAttachChanged;
19  private Widget m_Widget;
20  protected ref ScriptInvoker m_OnAttachChange = new ScriptInvoker();
21 
22  //------------------------------------------------------------------------------------------------
26  bool AttachTo(IEntity target)
27  {
28  //--- No target, already attached target or inactive target - ignore
29  if (!target || target == m_Target || !SCR_Enum.HasFlag(target.GetFlags(), EntityFlags.TRACEABLE))
30  return false;
31 
33  if (!camera)
34  return false;
35 
36  //--- Already attached - detach first
37  if (m_AttachHelper)
38  Detach();
39 
40  m_Target = target;
41 
42  //--- Create helper entity and attach camera to it, so it moves in its local coordinate space
43  //--- Don't attach on target itself, because we only want to move, not rotate camera with it
44  EntitySpawnParams spawnParams = new EntitySpawnParams;
45  spawnParams.Transform[3] = m_Target.CoordToParent(vector.Zero);
46  m_AttachHelper = SCR_AttachEntity.Cast(GetGame().SpawnEntity(SCR_AttachEntity, camera.GetWorld(), spawnParams));
47  m_AttachHelper.AttachTo(m_Target);
48  m_AttachHelper.RotateWithTarget(m_bRotateWithTarget);
49  m_AttachHelper.EOnPostFrame(m_AttachHelper, 0);
50  camera.AttachTo(m_AttachHelper);
51 
52  m_bAttachChanged = true;
53 
54  m_OnAttachChange.Invoke(true, m_Target);
55 
56  //Print("Attached to " + target.ToString(), LogLevel.DEBUG);
57 
58  return true;
59  }
60 
61  //------------------------------------------------------------------------------------------------
63  void Detach()
64  {
65  if (!m_AttachHelper)
66  return;
67 
69  if (!camera)
70  return;
71 
72  m_OnAttachChange.Invoke(false, m_Target);
73 
74  m_Target = null;
75 
76  //--- Detach and delete the attach helper
77  camera.Detach();
78  delete m_AttachHelper;
79 
80  m_bAttachChanged = true;
81 
82  //Print("Detach", LogLevel.DEBUG);
83  }
84 
85  //------------------------------------------------------------------------------------------------
88  ScriptInvoker GetOnAttachChange()
89  {
90  return m_OnAttachChange;
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  override void EOnCameraSave(SCR_ManualCameraComponentSave data)
95  {
96  if (m_Target)
97  {
98  data.m_aValues = {m_AttachType};
99  data.m_Target = m_Target;
100  }
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  override void EOnCameraLoad(SCR_ManualCameraComponentSave data)
105  {
106  if (data.m_Target && m_AttachType == data.m_aValues[0])
107  AttachTo(data.m_Target);
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  override void EOnCameraFrame(SCR_ManualCameraParam param)
112  {
113  //--- Target deleted, detach
114  if (m_AttachHelper && !m_Target)
115  Detach();
116 
117  if (!param.isManualInputEnabled)
118  {
119  if (m_Widget)
120  m_Widget.SetVisible(false);
121 
122  return;
123  }
124 
125  //--- Change attachment on input
126  switch (m_AttachType)
127  {
128  case EAttachManualCameraType.INPUT:
129  {
130  if (param.isManualInputEnabled && GetInputManager().GetActionTriggered("ManualCameraAttach"))
131  {
132  param.GetCursorWorldPos(); //--- Update entity under cursor
133  if (!AttachTo(param.target))
134  Detach();
135  }
136  break;
137  }
138 
139  case EAttachManualCameraType.PLAYER:
140  {
141  if (!m_AttachHelper)
142  AttachTo(SCR_PlayerController.GetLocalMainEntity());
143 
144  break;
145  }
146 
147  case EAttachManualCameraType.ENTITY:
148  {
149  if (!m_AttachHelper)
150  AttachTo(SCR_PlayerController.GetLocalMainEntity());
151 
152  break;
153  }
154  }
155 
156  //--- Convert camera coordinates to local space
157  if (m_bAttachChanged)
158  {
159  m_bAttachChanged = false;
160 
162  if (camera)
163  {
164  camera.GetLocalTransform(param.transform);
165  camera.GetLocalTransform(param.transformOriginal);
166  param.isDirty = true;
167  }
168 
169  if (m_Widget)
170  m_Widget.SetVisible(m_Target != null);
171  }
172 
173  //--- Update GUI
174  if (m_Widget && m_Target)
175  {
176  m_Widget.SetVisible(true);
177  vector screenPos = m_Widget.GetWorkspace().ProjWorldToScreen(m_AttachHelper.GetOrigin(), param.world);
178  if (screenPos[2] > 0)
179  FrameSlot.SetPos(m_Widget, screenPos[0], screenPos[1]);
180  }
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  override bool EOnCameraInit()
185  {
186  m_Widget = GetCameraEntity().CreateCameraWidget(m_Layout, false);
187  return true;
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  override void EOnCameraExit()
192  {
193  if (m_Widget)
194  m_Widget.RemoveFromHierarchy();
195 
196  delete m_AttachHelper;
197  }
198 }
199 
200 class SCR_AttachEntityClass : GenericEntityClass
201 {
202 }
203 
204 class SCR_AttachEntity : GenericEntity
205 {
206  private IEntity m_Target;
207  private bool m_bRotateWithTarget;
208 
209  //------------------------------------------------------------------------------------------------
212  void RotateWithTarget(bool rotate)
213  {
214  m_bRotateWithTarget = rotate;
215  }
216 
217  //------------------------------------------------------------------------------------------------
220  void AttachTo(IEntity target)
221  {
222  m_Target = target;
223  SetEventMask(EntityEvent.POSTFRAME);
224  SetFlags(EntityFlags.ACTIVE);
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  override void EOnPostFrame(IEntity owner, float timeSlice)
229  {
230  if (!m_Target)
231  return;
232 
234  {
235  vector transform[4];
236  m_Target.GetWorldTransform(transform);
237  SetWorldTransform(transform);
238  }
239  else
240  {
241  SetOrigin(m_Target.GetWorldTransformAxis(3));
242  }
243  }
244 }
245 
247 {
252 }
AttachTo
void AttachTo(IEntity target)
Definition: SCR_AttachManualCameraComponent.c:220
SpawnEntity
protected IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition: SCR_CatalogEntitySpawnerComponent.c:1008
SCR_ManualCamera
Definition: SCR_ManualCamera.c:16
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_Enum
Definition: SCR_Enum.c:1
RotateWithTarget
void RotateWithTarget(bool rotate)
Definition: SCR_AttachManualCameraComponent.c:212
SCR_BaseManualCameraComponent
Parent class from which all SCR_ManualCamera components inherit.
Definition: SCR_BaseManualCameraComponent.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Target
class SCR_AIPolar m_Target
m_Layout
ResourceName m_Layout
Definition: SCR_ActionsToolbarEditorUIComponent.c:6
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
m_Target
SCR_AttachManualCameraComponent m_Target
INPUT
@ INPUT
Definition: SCR_AttachManualCameraComponent.c:249
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ManualCameraComponentSave
Definition: SCR_ManualCameraSave.c:15
GetCameraEntity
protected SCR_ManualCamera GetCameraEntity()
Definition: SCR_BaseManualCameraComponent.c:59
SCR_ManualCameraParam
Parameter for carrying information between individual camera components.
Definition: SCR_ManualCameraParam.c:5
PLAYER
@ PLAYER
Definition: SCR_AttachManualCameraComponent.c:250
m_bRotateWithTarget
private bool m_bRotateWithTarget
Definition: SCR_AttachManualCameraComponent.c:207
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_AttachManualCameraComponent
Attach camera to a target.
Definition: SCR_AttachManualCameraComponent.c:5
EOnPostFrame
override void EOnPostFrame(IEntity owner, float timeSlice)
Definition: SCR_AttachManualCameraComponent.c:228
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
ENTITY
@ ENTITY
Definition: SCR_AttachManualCameraComponent.c:251
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
EAttachManualCameraType
EAttachManualCameraType
Definition: SCR_AttachManualCameraComponent.c:246
NONE
@ NONE
Definition: SCR_AttachManualCameraComponent.c:248