Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
5
6//~ Script Invokers
9
10
14{
15 [Attribute("", UIWidgets.ResourceNamePicker, "Prefab of class SCR_ManualCamera", "et", category: "Camera")]
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")]
26
27 [Attribute(defvalue: "0 -45 0")]
29
30 protected CameraManager m_CameraManager;
36 protected bool m_bIsReplacingCamera;
37 protected ref ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated> m_OnCameraCreate = new ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated>();
38// private SCR_EditorManagerEntity editorManagerEntity;
39
41 //--- Public Functions
47 {
48 return m_Camera;
49 }
50
55 bool GetCamera(out SCR_ManualCamera camera)
56 {
57 if (!m_Camera) return false;
58 camera = m_Camera;
59 return true;
60 }
61
66 {
68 if (cameraManager) return cameraManager.GetCamera();
69 return null;
70 }
71
75 ScriptInvokerBase<SCR_CameraEditorComponent_OnCameraCreated> GetOnCameraCreate()
76 {
77 return m_OnCameraCreate;
78 }
79
84 void SetInitTransform(vector transform[4])
85 {
86 m_vInitCameraTransform = transform;
87 }
88
90 //--- Protected Functions
91 protected void InitCameraTransform()
92 {
93 if (!m_CameraManager)
94 return;
95
96 //--- If a camera exists, base the view on it. If there is no camera, use terrain default.
97 CameraBase currentCamera = m_CameraManager.CurrentCamera();
98 if (!currentCamera)
99 {
100 //--- Use one of pre-defined defaults (if available)
102 if (cameraDefaults)
103 {
104 if (cameraDefaults.GetRandomPosition(m_vInitCameraTransform))
105 return;
106 }
107
108 //--- Use world center
109 BaseWorld world = GetGame().GetWorld();
110 if (!world) return;
111
112 vector mins, maxs;
113 world.GetBoundBox(mins, maxs);
114 vector center = mins + (maxs - mins) / 2;
115 center[1] = world.GetSurfaceY(center[0], center[2]);
116 center += m_vDefaultOffset;
117 m_vInitCameraTransform[3] = center;
119 return;
120 }
121
122 if (m_PreActivateControlledEntity && PlayerCamera.Cast(currentCamera) && !currentCamera.GetParent())
123 return; // Wait for player camera to be assigned to inital entity before grabbing the transform
124
125 currentCamera.GetWorldTransform(m_vInitCameraTransform);
126 }
127
128 protected void TryCreateCamera()
129 {
130 if ((!m_CameraData || !m_CameraData.IsSave()) && m_vInitCameraTransform[3] == vector.Zero)
131 {
133 }
134 else
135 {
136 CreateCamera();
137 }
138 }
139 protected bool TryForceCamera()
140 {
141 if (!m_Camera || !m_CameraManager)
142 return false;
143
144 if (m_Camera != m_CameraManager.CurrentCamera())
145 {
146 array<CameraBase> cameras = {};
147 m_CameraManager.GetCamerasList(cameras);
148 if (cameras.Contains(m_Camera))
149 m_CameraManager.SetCamera(m_Camera);
150 }
151
152 return true;
153 }
154 protected void ReplaceCamera()
155 {
157 if (m_CameraData)
158 m_CameraData.SaveComponents(m_Camera);
159 CreateCamera();
160 }
161 protected void CreateCamera()
162 {
163 delete m_Camera;
164
165 if (GetOwner().IsDeleted())
166 return;
167
168 EntitySpawnParams spawnParams = new EntitySpawnParams();
169 spawnParams.Transform = m_vInitCameraTransform;
170
171 ResourceName prefab = GetCameraPrefab();
172 if (prefab.IsEmpty())
173 {
174 m_Camera = SCR_ManualCamera.Cast(GetGame().SpawnEntity(SCR_ManualCamera, GetGame().GetWorld(), spawnParams));
175 }
176 else
177 {
178 m_Camera = SCR_ManualCamera.Cast(GetGame().SpawnEntityPrefab(Resource.Load(prefab), GetGame().GetWorld(), spawnParams));
179 }
180
181 m_Camera.GetOnCameraDeactivate().Insert(OnCameraDectivate);
182 Math3D.MatrixIdentity4(m_vInitCameraTransform);
183
184 if (m_CameraData)
185 m_CameraData.LoadComponents(m_Camera);
186
188
189 //--- When opening the editor, move the camera above player
191 {
193 {
195 if (teleportComponent)
196 {
198 m_Camera.GetWorldTransform(m_vPreActivateCameraTransform);
199
200 //--- Reset roll
202 angles[2] = 0;
204
206 bool disableInterruption = !GetGame().GetInputManager().IsUsingMouseAndKeyboard();
207 teleportComponent.TeleportCamera(m_vPreActivateCameraTransform[3], true, true, true, disableInterruption, m_fDistance, true);
208 }
209 }
210 }
211 m_bIsReplacingCamera = false;
213 }
214 protected void OnCameraDectivate()
215 {
216 //--- Force camera
218 }
220 {
221 return m_CameraPrefab;
222 }
223
225 {
226 SCR_EditorManagerEntity editorManagerEntity = SCR_EditorManagerEntity.Cast(GetOwner().GetParent());
227 //NOTE @JK: Maybe I could do SCR_EditorManagerEntity.GetInstance() but I'm not 100% sure if it would be the right thing to do.
228 return editorManagerEntity;
229 }
230
231 //------------------------------------------------------------------------------------------------
238
240 //--- Default functions
241 override void ResetEditorComponent()
242 {
243 if (m_Camera)
244 m_Camera.ResetComponents();
245 }
246 override protected void EOnEditorInit()
247 {
248 m_CameraManager = GetGame().GetCameraManager();
250
251 SCR_EditorManagerEntity editorManagerEntity = GetEditorManagerEntity();
252 if (editorManagerEntity)
253 editorManagerEntity.EnableCameraNwkSimulation(false);
254 }
255 override protected void EOnEditorPreActivate()
256 {
257 if (!m_CameraManager)
258 return;
259
260 CameraBase currentCamera = m_CameraManager.CurrentCamera();
261 m_bIsReplacingCamera = currentCamera && currentCamera.IsInherited(SCR_ManualCamera);
263 GetGame().GetWorld().GetCurrentCamera(m_vPreActivateCameraTransform);
264 }
265 override protected void EOnEditorPostActivate()
266 {
268
269// SCR_EditorManagerCore editorCore = SCR_EditorManagerCore.Cast(SCR_EditorManagerCore.GetInstance(SCR_EditorManagerCore));
270// if (editorCore)
271// editorManagerEntity = editorCore.GetEditorManager(GetGame().GetPlayerController().GetPlayerId());
272
273 SCR_EditorManagerEntity editorManagerEntity = GetEditorManagerEntity();
274 if (editorManagerEntity)
275 editorManagerEntity.EnableCameraNwkSimulation(true);
276
277 //TryCreateCamera(); //--- Don't try to create camera just yet, wait for GUI to initialize in its own EOnEditorPostActivate
278 }
279 override void EOnFrame(IEntity owner, float timeSlice)
280 {
281 // Tell server where camera is located by moving the EditorManagerEntity
282 SCR_EditorManagerEntity editorManagerEntity = GetEditorManagerEntity();
283 if(!editorManagerEntity)
284 return;
285
286 //if editor isn't open we shouldn't worry about it
287 if(!editorManagerEntity.IsOpened())
288 return;
289
290 //if(editorManagerEntity)
291 if (!m_Camera)
293
295
296 if (!m_Camera)
297 return;
298
299 vector mat[4];
300 m_Camera.GetWorldTransform(mat);
301 editorManagerEntity.SetWorldTransform(mat);
302 }
303 override protected void EOnEditorDeactivate()
304 {
305 if (m_CameraData)
306 m_CameraData.SaveComponents(m_Camera);
307
308 if (m_Camera)
309 m_Camera.Terminate();
310
311 SCR_EditorManagerEntity editorManagerEntity = GetEditorManagerEntity();
312 if (editorManagerEntity)
313 editorManagerEntity.EnableCameraNwkSimulation(false);
314 }
315 override protected void EOnEditorPostDeactivate()
316 {
317 if (GetOwner())
319
320 if (m_Camera)
321 {
322 m_Camera.TrySwitchToControlledEntityCamera();
323 delete m_Camera;
324 }
325 }
326};
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref array< string > angles
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
func SCR_CameraEditorComponent_OnCameraCreated
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
vector position
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
Faction GetParent()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int ClearEventMask(notnull IEntity owner, int mask)
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external BaseWorld GetWorld()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void SCR_BaseEditorComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
static Managed GetInstance(typename type, bool showError=false, bool modeFirst=false)
static SCR_ManualCamera GetCameraInstance()
void SetInitTransform(vector transform[4])
SCR_CameraDataEditorComponent m_CameraData
SCR_EditorManagerEntity GetEditorManagerEntity()
void SetPreActivateCameraPosition(vector position)
bool GetCamera(out SCR_ManualCamera camera)
override void EOnFrame(IEntity owner, float timeSlice)
ScriptInvokerBase< SCR_CameraEditorComponent_OnCameraCreated > GetOnCameraCreate()
ref ScriptInvokerBase< SCR_CameraEditorComponent_OnCameraCreated > m_OnCameraCreate
static SCR_EditorCameraDefaultsComponent GetInstance()
static IEntity GetLocalControlledEntity()
Teleport the camera to the cursor's world position.
proto external GenericEntity GetOwner()
Get owner entity.
void EntitySpawnParams()
Definition gameLib.c:130
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14