18 [
Attribute(
"1", UIWidgets.Auto,
"True to enable manual control.",
category:
"Manual Camera")]
19 private bool m_bInputEnabled;
21 [
Attribute(
"0", UIWidgets.Auto,
"True to create the camera at the position of this entity.",
category:
"Manual Camera")]
22 private bool m_bStartAtEntity;
25 private string m_sActionContext;
31 private ref array<ref SCR_BaseManualCameraComponent> m_aComponents;
35 private BaseWorld m_World;
36 private CameraManager m_CameraManager;
37 private InputManager m_InputManager;
38 private MenuManager m_MenuManager;
39 private IEntity m_Owner;
40 private ref SCR_SortedArray<SCR_BaseManualCameraComponent> m_aComponentsSorted =
new SCR_SortedArray<SCR_BaseManualCameraComponent>;
41 private ref array<SCR_BaseManualCameraComponent> m_aComponentsOnFrame =
new array<SCR_BaseManualCameraComponent>;
42 private int m_iComponentsCount;
43 private int m_iComponentsOnFrameCount;
44 private float m_fFOVDefault = 1;
46 private ref ScriptInvoker Event_OnCursorPos;
47 private vector m_vTransformPrev[4];
48 private bool m_bIsDirtyExternal;
49 private Widget m_Widget;
56 protected void RegisterComponents()
64 if (cameraComponent.IsEnabled())
65 m_aComponentsSorted.Insert(cameraComponent.GetPriority(), cameraComponent);
67 m_iComponentsCount = m_aComponentsSorted.Count();
71 protected void InitComponents()
73 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
75 if (m_aComponentsSorted[i].
InitBase(
this))
76 m_aComponentsOnFrame.Insert(m_aComponentsSorted[i]);
78 m_iComponentsOnFrameCount = m_aComponentsOnFrame.Count();
82 protected void ProcessComponents(
float timeSlice = 0)
86 GetLocalTransform(transform);
87 bool inputEnabled = m_bInputEnabled && !IsDisabledByMenu();
88 vector velocity = vector.Zero;
89 if (m_Param) velocity = m_Param.velocityOriginal;
93 m_Param.isDirtyExternal = m_bIsDirtyExternal;
94 m_bIsDirtyExternal =
false;
98 m_Param.isDirty =
true;
109 for (
int c = 0; c < m_iComponentsOnFrameCount; c++)
111 component = m_aComponentsOnFrame[c];
112 if (component.IsEnabled() && component.HasFlag(m_Param.flag))
113 component.EOnCameraFrame(m_Param);
118 m_Param.ShowDebug(
this);
123 m_Param.ProcessTransform();
125 SetLocalTransform(m_Param.transform);
128 m_vTransformPrev = m_Param.transform;
130 m_Param.velocityOriginal = m_Param.transform[3] - m_Param.transformOriginal[3];
136 void SaveComponents(notnull array<ref SCR_ManualCameraComponentSave> outData)
139 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
145 m_aComponentsSorted[i].EOnCameraSave(save);
147 if (save.m_aValues && !save.m_aValues.IsEmpty())
149 save.m_sTypeName = m_aComponentsSorted[i].Type().ToString();
152 int dataCount = outData.Count();
153 while (d < dataCount)
156 if (outData[d].m_sTypeName == save.m_sTypeName)
158 outData.RemoveOrdered(d);
164 outData.InsertAt(save, d);
172 void LoadComponents(array<ref SCR_ManualCameraComponentSave>
data)
177 type = dataEntry.m_sTypeName.ToType();
178 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
180 if (m_aComponentsSorted[i].Type() ==
type && m_aComponentsSorted[i].
IsEnabled())
181 m_aComponentsSorted[i].EOnCameraLoad(dataEntry);
188 void ResetComponents()
190 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
193 m_aComponentsSorted[i].EOnCameraReset();
202 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
204 if (m_aComponentsSorted[i].Type() ==
type)
205 return m_aComponentsSorted[i];
211 protected void MoveToCamera(CameraBase camera =
null)
213 if (!camera) camera = GetPreviousCamera();
216 camera.GetTransform(matrix);
221 protected CameraBase GetPreviousCamera()
223 if (!m_CameraManager)
return null;
226 array<CameraBase> cameras =
new array<CameraBase>();
227 m_CameraManager.GetCamerasList(cameras);
230 for (
int i = cameras.Count() - 1; i >= 0; i--)
232 if (cameras[i] !=
this)
return cameras[i];
240 bool TrySwitchToControlledEntityCamera()
243 if (!m_CameraManager || m_CameraManager.CurrentCamera() !=
this)
247 CameraBase camera =
GetGame().GetPlayerController().GetPlayerCamera();
251 camera = GetPreviousCamera();
255 m_CameraManager.SetCamera(camera);
265 void SwitchToPreviousCamera()
268 if (!m_CameraManager || m_CameraManager.CurrentCamera() !=
this)
271 CameraBase camera = GetPreviousCamera();
273 m_CameraManager.SetCamera(camera);
277 protected bool IsFirstCamera()
279 if (!m_CameraManager)
282 array<CameraBase> cameras =
new array<CameraBase>();
283 m_CameraManager.GetCamerasList(cameras);
285 int count = cameras.Count();
290 return cameras[0] ==
this;
296 protected bool IsDisabledByMenu()
309 void AttachTo(IEntity parent)
311 if (parent == GetParent())
return;
314 GetWorldTransform(transform);
315 parent.AddChild(
this, 0);
316 SetWorldTransform(transform);
318 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
320 m_aComponentsSorted[i].EOnCameraParentChange(
true, parent);
328 IEntity parent = GetParent();
332 GetWorldTransform(transform);
333 parent.RemoveChild(
this);
334 SetWorldTransform(transform);
336 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
338 m_aComponentsSorted[i].EOnCameraParentChange(
false, parent);
345 void SetInputEnabled(
bool enable)
347 m_bInputEnabled = enable;
353 bool IsInputEnabled()
355 return m_bInputEnabled;
361 float GetDefaultFOV()
363 return m_fFOVDefault;
371 return m_Param.isManualInput;
377 void SetDirty(
bool isDirty)
379 m_bIsDirtyExternal = isDirty;
395 Widget CreateCameraWidget(ResourceName
layout,
bool isVisible =
true)
397 if (!m_Widget ||
layout.IsEmpty())
return null;
399 Widget widget =
GetGame().GetWorkspace().CreateWidgets(
layout, m_Widget);
400 if (!widget)
return null;
402 widget.SetVisible(isVisible);
422 if (m_iComponentsCount == -1)
return;
425 for (
int i = m_iComponentsCount - 1; i >= 0; i--)
427 m_aComponentsSorted[i].EOnCameraExit();
429 m_iComponentsCount = -1;
439 override protected void EOnPostFrame(IEntity owner,
float timeSlice)
441 if (m_CameraManager && m_CameraManager.CurrentCamera() !=
this)
444 timeSlice = timeSlice /
m_World.GetTimeScale();
445 ProcessComponents(timeSlice);
449 override protected void EOnInit(IEntity owner)
453 if (owner.GetFlags() & EntityFlags.EDITOR_ONLY)
455 owner.ClearEventMask(EntityEvent.POSTFRAME);
462 world.RegisterEntityToBeUpdatedWhileGameIsPaused(
this);
466 if (m_CameraManager) m_CameraManager.SetCamera(
this);
469 if (!m_bStartAtEntity && !IsFirstCamera())
475 m_Widget =
GetGame().GetWorkspace().CreateWidget(WidgetType.FrameWidgetTypeID, WidgetFlags.VISIBLE | WidgetFlags.IGNORE_CURSOR | WidgetFlags.NOFOCUS, Color.FromInt(Color.WHITE), 0);
476 m_Widget.SetName(Type().ToString());
477 FrameSlot.SetAnchorMin(m_Widget, 0, 0);
478 FrameSlot.SetAnchorMax(m_Widget, 1, 1);
479 FrameSlot.SetOffsets(m_Widget, 0, 0, 0, 0);
483 DiagMenu.RegisterMenu(
SCR_DebugMenuID.DEBUGUI_MANUAL_CAMERA,
"Manual Camera",
"");
484 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_MANUAL_CAMERA_DEBUG,
"",
"Show debug menu",
"Manual Camera",
false);
487 ProcessComponents(0);
503 if (m_Widget) m_Widget.RemoveFromHierarchy();
505 ArmaReforgerScripted game =
GetGame();
508 m_CameraManager = game.GetCameraManager();
511 RegisterComponents();
513 SetFlags(EntityFlags.ACTIVE);
514 SetEventMask(EntityEvent.INIT | EntityEvent.POSTFRAME);
516 SetName(
"ManualCamera");
526 world.UnregisterEntityToBeUpdatedWhileGameIsPaused(
this);
530 SwitchToPreviousCamera();