Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FocusManualCameraComponent.c
Go to the documentation of this file.
1
2
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;
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 //------------------------------------------------------------------------------------------------
42 {
43 return m_fFocusDistance;
44 }
45
46 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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)
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 //------------------------------------------------------------------------------------------------
110
111 //------------------------------------------------------------------------------------------------
118
119 //------------------------------------------------------------------------------------------------
120 override void EOnCameraReset()
121 {
122 ResetFocus();
123 }
124
125 //------------------------------------------------------------------------------------------------
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);
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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
bool GetCursorWorldPos(out vector worldPos, bool isNormalized=false, TraceFlags flags=-1)
Get all prefabs that have the spawner data
void SCR_PostProcessCameraComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Debug.c:13
Input management system for user interactions.
Parent class from which all SCR_ManualCamera components inherit.
Focus camera on cursor position.
override void EOnCameraLoad(SCR_ManualCameraComponentSave data)
void SetFocus(vector pos, IEntity entity=null)
override void EOnCameraSave(SCR_ManualCameraComponentSave data)
override void EOnCameraFrame(SCR_ManualCameraParam param)
void SetFocusToCursor()
Set focus to cursor position.
Widget CreateCameraWidget(ResourceName layout, bool isVisible=true)
SCR_ManualCameraParam GetCameraParam()
Parameter for carrying information between individual camera components.
IEntity target
Entity under cursor.
BaseWorld world
World in which the camera exists.
SCR_FieldOfViewSettings Attribute
EActionTrigger
proto native vector Vector(float x, float y, float z)
PostProcessEffectType
Definition EnWorld.c:20
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134