Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CameraEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "Camera for in-game editor. Works only with SCR_EditorBaseEntity!", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 };
5 
6 //~ Script Invokers
9 
10 
14 {
15  [Attribute("", UIWidgets.ResourceNamePicker, "Prefab of class SCR_ManualCamera", "et", category: "Camera")]
16  protected ResourceName m_CameraPrefab;
17 
18  [Attribute(defvalue: "1", category: "Init", desc: "Should the camera move above player when it initializes?")]
19  protected bool m_bMoveUpOnInit;
20 
21  [Attribute(defvalue: "10", category: "Init", desc: "Initial camera distance.")]
22  protected float m_fDistance;
23 
24  [Attribute(defvalue: "0 50 0")]
25  protected vector m_vDefaultOffset;
26 
27  [Attribute(defvalue: "0 -45 0")]
28  protected vector m_vDefaultAngle;
29 
30  protected CameraManager m_CameraManager;
31  protected SCR_ManualCamera m_Camera;
32  protected SCR_CameraDataEditorComponent m_CameraData;
33  protected vector m_vInitCameraTransform[4];
34  protected vector m_vPreActivateCameraTransform[4];
35  protected IEntity m_PreActivateControlledEntity;
36  protected bool m_bIsReplacingCamera;
37  protected ref ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated> m_OnCameraCreate = new ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated>();
38 
40  //--- Public Functions
45  SCR_ManualCamera GetCamera()
46  {
47  return m_Camera;
48  }
54  bool GetCamera(out SCR_ManualCamera camera)
55  {
56  if (!m_Camera) return false;
57  camera = m_Camera;
58  return true;
59  }
64  static SCR_ManualCamera GetCameraInstance()
65  {
67  if (cameraManager) return cameraManager.GetCamera();
68  return null;
69  }
74  ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated> GetOnCameraCreate()
75  {
76  return m_OnCameraCreate;
77  }
83  void SetInitTransform(vector transform[4])
84  {
85  m_vInitCameraTransform = transform;
86  }
87 
89  //--- Protected Functions
90  protected void InitCameraTransform()
91  {
92  if (!m_CameraManager)
93  return;
94 
95  //--- If a camera exists, base the view on it. If there is no camera, use terrain default.
96  CameraBase currentCamera = m_CameraManager.CurrentCamera();
97  if (!currentCamera)
98  {
99  //--- Use one of pre-defined defaults (if available)
101  if (cameraDefaults)
102  {
103  if (cameraDefaults.GetRandomPosition(m_vInitCameraTransform))
104  return;
105  }
106 
107  //--- Use world center
108  BaseWorld world = GetGame().GetWorld();
109  if (!world) return;
110 
111  vector mins, maxs;
112  world.GetBoundBox(mins, maxs);
113  vector center = mins + (maxs - mins) / 2;
114  center[1] = world.GetSurfaceY(center[0], center[2]);
115  center += m_vDefaultOffset;
116  m_vInitCameraTransform[3] = center;
117  Math3D.AnglesToMatrix(m_vDefaultAngle, m_vInitCameraTransform);
118  return;
119  }
120 
121  //--- In case of player camera, wait for it to be initialized (moved toward its target). ToDo: Cleaner?
122  if (currentCamera.GetParent() && currentCamera.GetLocalTransformAxis(3).Length() > 100)
123  return;
124 
125  currentCamera.GetWorldTransform(m_vInitCameraTransform);
126  }
127  protected void TryCreateCamera()
128  {
129  if ((!m_CameraData || !m_CameraData.IsSave()) && m_vInitCameraTransform[3] == vector.Zero)
130  {
131  InitCameraTransform();
132  }
133  else
134  {
135  CreateCamera();
136  }
137  }
138  protected bool TryForceCamera()
139  {
140  if (!m_Camera || !m_CameraManager)
141  return false;
142 
143  if (m_Camera != m_CameraManager.CurrentCamera())
144  {
145  array<CameraBase> cameras = {};
146  m_CameraManager.GetCamerasList(cameras);
147  if (cameras.Contains(m_Camera))
148  m_CameraManager.SetCamera(m_Camera);
149  }
150 
151  return true;
152  }
153  protected void ReplaceCamera()
154  {
155  m_bIsReplacingCamera = true;
156  if (m_CameraData)
157  m_CameraData.SaveComponents(m_Camera);
158  CreateCamera();
159  }
160  protected void CreateCamera()
161  {
162  delete m_Camera;
163 
164  if (GetOwner().IsRemoved())
165  return;
166 
167  EntitySpawnParams spawnParams = new EntitySpawnParams();
168  spawnParams.Transform = m_vInitCameraTransform;
169 
170  ResourceName prefab = GetCameraPrefab();
171  if (prefab.IsEmpty())
172  {
173  m_Camera = SCR_ManualCamera.Cast(GetGame().SpawnEntity(SCR_ManualCamera, GetGame().GetWorld(), spawnParams));
174  }
175  else
176  {
177  m_Camera = SCR_ManualCamera.Cast(GetGame().SpawnEntityPrefab(Resource.Load(prefab), GetGame().GetWorld(), spawnParams));
178  }
179 
180  m_Camera.GetOnCameraDeactivate().Insert(OnCameraDectivate);
181  Math3D.MatrixIdentity4(m_vInitCameraTransform);
182 
183  if (m_CameraData)
184  m_CameraData.LoadComponents(m_Camera);
185 
186  m_OnCameraCreate.Invoke(m_Camera);
187 
188  //--- When opening the editor, move the camera above player
189  if (m_bMoveUpOnInit && !m_bIsReplacingCamera)
190  {
191  if (m_PreActivateControlledEntity)
192  {
194  if (teleportComponent)
195  {
196  if (m_vPreActivateCameraTransform[3] == vector.Zero)
197  m_Camera.GetWorldTransform(m_vPreActivateCameraTransform);
198 
199  //--- Reset roll
200  vector angles = Math3D.MatrixToAngles(m_vPreActivateCameraTransform);
201  angles[2] = 0;
202  Math3D.AnglesToMatrix(angles, m_vPreActivateCameraTransform);
203 
204  m_Camera.SetTransform(m_vPreActivateCameraTransform);
205  bool disableInterruption = !GetGame().GetInputManager().IsUsingMouseAndKeyboard();
206  teleportComponent.TeleportCamera(m_vPreActivateCameraTransform[3], true, true, true, disableInterruption, m_fDistance, true);
207  }
208  }
209  }
210  m_bIsReplacingCamera = false;
211  m_PreActivateControlledEntity = null;
212  }
213  protected void OnCameraDectivate()
214  {
215  //--- Force camera
216  if (m_CameraManager && m_Camera) m_CameraManager.SetCamera(m_Camera);
217  }
218  protected ResourceName GetCameraPrefab()
219  {
220  return m_CameraPrefab;
221  }
222 
224  //--- Default functions
225  override void ResetEditorComponent()
226  {
227  m_Camera.ResetComponents();
228  }
229  override protected void EOnEditorInit()
230  {
231  m_CameraManager = GetGame().GetCameraManager();
233  }
234  override protected void EOnEditorPreActivate()
235  {
236  if (!m_CameraManager)
237  return;
238 
239  CameraBase currentCamera = m_CameraManager.CurrentCamera();
240  m_bIsReplacingCamera = currentCamera && currentCamera.IsInherited(SCR_ManualCamera);
241  m_PreActivateControlledEntity = SCR_PlayerController.GetLocalControlledEntity();
242  GetGame().GetWorld().GetCurrentCamera(m_vPreActivateCameraTransform);
243  }
244  override protected void EOnEditorPostActivate()
245  {
246  SetEventMask(GetOwner(), EntityEvent.FRAME);
247  //TryCreateCamera(); //--- Don't try to create camera just yet, wait for GUI to initialize in its own EOnEditorPostActivate
248  }
249  override void EOnFrame(IEntity owner, float timeSlice)
250  {
251  if (!m_Camera)
252  TryCreateCamera();
253 
254  TryForceCamera();
255  }
256  override protected void EOnEditorDeactivate()
257  {
258  if (m_CameraData)
259  m_CameraData.SaveComponents(m_Camera);
260 
261  if (m_Camera)
262  m_Camera.Terminate();
263  }
264  override protected void EOnEditorPostDeactivate()
265  {
266  if (GetOwner())
267  ClearEventMask(GetOwner(), EntityEvent.FRAME);
268 
269  if (m_Camera)
270  {
271  m_Camera.TrySwitchToControlledEntityCamera();
272  delete m_Camera;
273  }
274  }
275 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SpawnEntity
protected IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition: SCR_CatalogEntitySpawnerComponent.c:1008
SCR_ManualCamera
Definition: SCR_ManualCamera.c:16
m_fDistance
float m_fDistance
Definition: SCR_AIGroupTargetCluster.c:38
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CameraEditorComponent
Definition: SCR_CameraEditorComponent.c:13
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
func
func
Definition: SCR_AIThreatSystem.c:5
m_Camera
protected SCR_ManualCamera m_Camera
Definition: SCR_BaseManualCameraComponent.c:14
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
SCR_CameraEditorComponent_OnCameraCreated
func SCR_CameraEditorComponent_OnCameraCreated
Definition: SCR_CameraEditorComponent.c:8
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_CameraDataEditorComponent
Definition: SCR_CameraDataEditorComponent.c:8
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditorCameraDefaultsComponent
Definition: SCR_EditorCameraDefaultsComponent.c:12
SCR_TeleportToCursorManualCameraComponent
Teleport the camera to the cursor's world position.
Definition: SCR_TeleportToCursorManualCameraComponent.c:5
SCR_CameraEditorComponentClass
Definition: SCR_CameraEditorComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180