Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FocusManualCameraComponent.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6 {
7  [Attribute(params: "layout")]
8  private ResourceName m_Layout;
9 
10  [Attribute()]
11  private string m_sSoundEvent;
12 
13  private bool m_bIsInit;
14  private bool m_bIsFocus;
15  private bool m_bIsFocusRequsted;
16  private bool m_bIsFocusPosLocal;
17  private vector m_vFocusPos;
18  private vector m_vFocusPosWorld;
19  private float m_fFocusDistance;
20  private IEntity m_FocusEntity;
21  private SCR_CameraPostProcessEffect m_Effect;
22  private Widget m_Widget;
23  protected ref ScriptInvoker m_OnFocusChange = new ScriptInvoker();
24  protected ref ScriptInvoker m_OnFocusDistanceChange = new ScriptInvoker();
25 
26  //------------------------------------------------------------------------------------------------
30  bool GetFocusPos(out vector outPos)
31  {
32  if (!m_bIsFocus)
33  return false;
34 
35  outPos = m_vFocusPosWorld;
36  return true;
37  }
38 
39  //------------------------------------------------------------------------------------------------
41  float GetFocusDistance()
42  {
43  return m_fFocusDistance;
44  }
45 
46  //------------------------------------------------------------------------------------------------
48  void SetFocusToCursor()
49  {
50  if (!IsEnabled())
51  return;
52 
53  if (GetCameraEntity().GetCameraParam().GetCursorWorldPos(m_vFocusPos))
54  {
55  m_FocusEntity = GetCameraEntity().GetCameraParam().target;
56  m_bIsFocusRequsted = true;
57  }
58  else
59  {
60  ResetFocus();
61  }
62  }
63 
64  //------------------------------------------------------------------------------------------------
68  void SetFocus(vector pos, IEntity entity = null)
69  {
70  m_vFocusPos = pos;
71  m_FocusEntity = entity;
72  m_bIsFocusRequsted = true;
73  }
74 
75  //------------------------------------------------------------------------------------------------
77  void ResetFocus()
78  {
79  if (m_bIsInit && (!m_bIsFocus || !IsEnabled()))
80  return;
81 
82  if (m_bIsInit)
83  m_OnFocusChange.Invoke(false, m_vFocusPos, m_FocusEntity);
84 
85  m_fFocusDistance = -1;
86 
87  if (m_bIsInit)
88  m_OnFocusDistanceChange.Invoke();
89 
90  m_Effect.SetParam("FocalLength", 0);
91  m_Effect.SetParam("FocalLengthNear", 0);
92 
93  m_bIsFocus = false;
94  m_bIsFocusRequsted = false;
95  m_bIsFocusPosLocal = false;
96  m_vFocusPos = vector.Zero;
97  m_vFocusPosWorld = vector.Zero;
98  m_FocusEntity = null;
99  if (m_Widget)
100  m_Widget.SetVisible(false);
101  }
102 
103  //------------------------------------------------------------------------------------------------
106  ScriptInvoker GetOnFocusChange()
107  {
108  return m_OnFocusChange;
109  }
110 
111  //------------------------------------------------------------------------------------------------
114  ScriptInvoker GetOnFocusDistanceChange()
115  {
116  return m_OnFocusDistanceChange;
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  override void EOnCameraReset()
121  {
122  ResetFocus();
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  override void EOnCameraFrame(SCR_ManualCameraParam param)
127  {
128  if (!param.isManualInputEnabled)
129  {
130  if (m_Widget)
131  m_Widget.SetVisible(false);
132 
133  return;
134  }
135 
136  if (m_bIsFocusRequsted)
137  {
138  m_bIsFocusRequsted = false;
139 
140  m_bIsFocus = true;
141  m_bIsFocusPosLocal = m_FocusEntity != null;
142  if (m_bIsFocusPosLocal)
143  m_vFocusPos = m_FocusEntity.CoordToLocal(m_vFocusPos);
144 
145  m_Effect.SetParam("FocalLength", 500);
146  m_Effect.SetParam("FocalLengthNear", 500);
147 
148  if (!m_sSoundEvent.IsEmpty())
149  SCR_UISoundEntity.SoundEvent(m_sSoundEvent);
150 
151  m_OnFocusChange.Invoke(true, m_vFocusPos, m_FocusEntity);
152  }
153 
154  //--- Ignore when no custom focus was set
155  if (!m_bIsFocus)
156  return;
157 
158  //--- Get focus position
159  m_vFocusPosWorld = m_vFocusPos;
160  if (m_bIsFocusPosLocal)
161  {
162  if (m_FocusEntity)
163  {
164  //--- Set focus to position in target's coordinate space
165  m_vFocusPosWorld = m_FocusEntity.CoordToParent(m_vFocusPos);
166  }
167  else
168  {
169  //--- Local target was deleted, reset focus
170  ResetFocus();
171  return;
172  }
173  }
174 
175  //--- Update post-process
176  m_fFocusDistance = vector.Distance(m_vFocusPosWorld, CoordFromCamera(param.transform[3]));
177  m_Effect.SetParam("FocusDistance", m_fFocusDistance);
178  //m_Effect.SetParam("FocalChange", m_fFocusDistance);
179  m_OnFocusDistanceChange.Invoke();
180 
181  //--- Update GUI
182  if (m_Widget)
183  {
184  m_Widget.SetVisible(true);
185  vector screenPos = m_Widget.GetWorkspace().ProjWorldToScreen(m_vFocusPosWorld, param.world);
186  if (screenPos[2] > 0)
187  FrameSlot.SetPos(m_Widget, screenPos[0], screenPos[1]);
188  }
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  override void EOnCameraSave(SCR_ManualCameraComponentSave data)
193  {
194  if (!m_bIsFocus)
195  return;
196 
197  data.m_aValues = {m_vFocusPosWorld[0], m_vFocusPosWorld[1], m_vFocusPosWorld[2]};
198  data.m_Target = m_FocusEntity;
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  override void EOnCameraLoad(SCR_ManualCameraComponentSave data)
203  {
204  SetFocus(Vector(data.m_aValues[0], data.m_aValues[1], data.m_aValues[2]), data.m_Target);
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  override bool EOnCameraInit()
209  {
211  if (!postProcessManager)
212  {
213  Debug.Error("SCR_FocusManualCameraComponent requires SCR_PostProcessCameraComponent!");
214  return false;
215  }
216 
217  m_Effect = postProcessManager.FindEffect(PostProcessEffectType.DepthOfFieldBokeh);
218  if (!m_Effect)
219  {
220  Debug.Error("SCR_FocusManualCameraComponent requires DepthOfField post-process effect!");
221  return false;
222  }
223 
224  InputManager inputManager = GetInputManager();
225  if (!inputManager)
226  return false;
227 
228  inputManager.AddActionListener("ManualCameraFocus", EActionTrigger.DOWN, SetFocusToCursor);
229  inputManager.AddActionListener("ManualCameraFocusReset", EActionTrigger.DOWN, ResetFocus);
230 
231  m_Widget = GetCameraEntity().CreateCameraWidget(m_Layout, false);
232 
233  //--- Disable blur by default
234  m_bIsInit = false;
235  ResetFocus();
236  m_bIsInit = true;
237 
238  return true;
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  override void EOnCameraExit()
243  {
244  InputManager inputManager = GetInputManager();
245  if (!inputManager)
246  return;
247 
248  inputManager.RemoveActionListener("ManualCameraFocus", EActionTrigger.DOWN, SetFocusToCursor);
249  inputManager.RemoveActionListener("ManualCameraFocusReset", EActionTrigger.DOWN, ResetFocus);
250 
251  if (m_Widget)
252  m_Widget.RemoveFromHierarchy();
253  }
254 }
CoordFromCamera
protected vector CoordFromCamera(vector pos)
Definition: SCR_BaseManualCameraComponent.c:80
GetCursorWorldPos
bool GetCursorWorldPos(out vector worldPos, bool isNormalized=false, TraceFlags flags=-1)
Definition: SCR_CursorEditorUIComponent.c:122
SCR_BaseManualCameraComponent
Parent class from which all SCR_ManualCamera components inherit.
Definition: SCR_BaseManualCameraComponent.c:5
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
SCR_PostProcessCameraComponent
void SCR_PostProcessCameraComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_PostProcessCameraComponent.c:51
m_Layout
ResourceName m_Layout
Definition: SCR_ActionsToolbarEditorUIComponent.c:6
SCR_CameraPostProcessEffect
Definition: SCR_PostProcessCameraComponent.c:74
Attribute
typedef Attribute
Post-process effect of scripted camera.
IsEnabled
int IsEnabled()
Definition: SCR_BaseManualCameraComponent.c:99
SCR_ManualCameraComponentSave
Definition: SCR_ManualCameraSave.c:15
SCR_FocusManualCameraComponent
Focus camera on cursor position.
Definition: SCR_FocusManualCameraComponent.c:5
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
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
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