Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LayersEditorManager.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "Manager of current layer. Works only with SCR_EditorBaseEntity!", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 };
5 
12 {
13  [Attribute()]
14  protected ResourceName m_sNewLayerPrefab;
15  private SCR_EditableEntityComponent m_CurrentLayer;
16 
17  ref ScriptInvoker Event_OnCurrentLayerChange = new ScriptInvoker;
18 
19  protected bool m_bEditingLayersEnabled;
20  protected SCR_BaseEditableEntityFilter m_SelectionFilter;
21  protected SCR_EditableEntityCore m_Core;
22  protected ref set<SCR_EditableEntityComponent> m_EntitiesToSelectAfterMove = new set<SCR_EditableEntityComponent>();
23  protected SCR_EditableEntityComponent m_NewGroupLeader;
24  protected bool m_bSelectAfterMoveCanceled;
25  protected bool m_bSelectParentAfterMove;
26 
30  bool IsEditingLayersEnabled()
31  {
32  return m_bEditingLayersEnabled;
33  }
34 
40  void SetEditingLayersEnabled(bool enableLayerEditing)
41  {
42  if (m_bEditingLayersEnabled == enableLayerEditing)
43  return;
44 
45  SetCurrentLayer(null);
46  m_bEditingLayersEnabled = enableLayerEditing;
47  }
48 
53  ScriptInvoker GetOnCurrentLayerChange()
54  {
55  return Event_OnCurrentLayerChange;
56  }
57 
58  //On editor mode change set layer null
59  protected void OnEditorModeChanged(SCR_EditorModeEntity currentModeEntity, SCR_EditorModeEntity prevModeEntity)
60  {
61  if (prevModeEntity && prevModeEntity.GetModeType() == EEditorMode.EDIT)
62  SetCurrentLayer(null);
63  }
64 
70  void SetCurrentLayer(SCR_EditableEntityComponent entity)
71  {
72  //--- Only root is allowed when layer editing is disabled
73  if (!IsEditingLayersEnabled())
74  entity = null;
75 
76  if (entity == m_CurrentLayer || (entity && !entity.HasEntityFlag(EEditableEntityFlag.LAYER)))
77  return;
78 
79  SCR_EditableEntityComponent prevCurrentLayer = m_CurrentLayer;
80  m_CurrentLayer = entity;
81  Event_OnCurrentLayerChange.Invoke(m_CurrentLayer, prevCurrentLayer);
82  }
87  void SetCurrentLayerToParent()
88  {
89  SCR_EditableEntityComponent currentLayer = GetCurrentLayer();
90  if (!currentLayer) return;
91 
92  SetCurrentLayer(currentLayer.GetParentEntity());
93  }
99  void ToggleCurrentLayer(SCR_EditableEntityComponent entity)
100  {
101  if (entity == GetCurrentLayer())
102  {
103  //--- Entity under cursor is the current layer, move one layer up
104  if (entity) SetCurrentLayer(entity.GetParentEntity());
105  }
106  else
107  {
108  //--- Select entity's composition root
109  SCR_EditableEntityComponent parent = GetParentBelowCurrentLayer(entity);
110  if (!parent) parent = entity; //--- Entity from different layer used
111  SetCurrentLayer(parent);
112  }
113  }
114 
119  SCR_EditableEntityComponent GetCurrentLayer()
120  {
121  return m_CurrentLayer;
122  }
123 
127  void CreateNewLayerWithSelected(notnull set<SCR_EditableEntityComponent> entities, vector worldPosition)
128  {
129  array<RplId> entityIDs = new array<RplId>();
130  RplId entityID;
131 
132  vector transform[4];
133  entities[0].GetTransform(transform);
134  transform[3] = worldPosition;
135 
136  foreach (SCR_EditableEntityComponent entity: entities)
137  {
138  if (entity.IsReplicated(entityID))
139  entityIDs.Insert(entityID);
140  }
141 
142  Rpc(CreateNewLayerWithSelectedRpl, entityIDs, transform, Replication.FindId(m_CurrentLayer));
143  }
144 
145  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
146  protected void CreateNewLayerWithSelectedRpl(notnull array<RplId> entityIDs, vector transform[4], RplId currentLayerID)
147  {
148  EntitySpawnParams spawnParams = new EntitySpawnParams();
149  spawnParams.Transform = transform;
150 
151  IEntity layer = GetGame().SpawnEntityPrefab(Resource.Load(m_sNewLayerPrefab), GetGame().GetWorld(), spawnParams);
152  SCR_EditableEntityComponent editableLayer = SCR_EditableEntityComponent.GetEditableEntity(layer);
153  if (!editableLayer)
154  {
155  delete layer;
156  return;
157  }
158 
159  SCR_EditableEntityComponent currentLayer = SCR_EditableEntityComponent.Cast(Replication.FindItem(currentLayerID));
160  if (currentLayer)
161  editableLayer.SetParentEntity(currentLayer);
162 
163  MoveToLayerServer(entityIDs, Replication.FindId(editableLayer));
164  }
165 
166 
175  SCR_EditableEntityComponent GetParentBelowCurrentLayer(SCR_EditableEntityComponent entity)
176  {
177  if (!entity || entity == m_CurrentLayer || entity.HasEntityFlag(EEditableEntityFlag.IGNORE_LAYERS))
178  return entity;
179 
181  while (entity)
182  {
183  parent = entity.GetParentEntity();
184  if (parent == m_CurrentLayer || (parent && parent.HasEntityFlag(EEditableEntityFlag.INDIVIDUAL_CHILDREN))) return entity;
185  entity = parent;
186  }
187  return entity;
188  }
195  bool IsUnderCurrentLayer(SCR_EditableEntityComponent entity, bool onlyDirect = false, bool applyExceptions = false)
196  {
197  if (!entity)
198  return false;
199 
200  //--- Always true when queried entity is the current layer or when there is no current layer (everything is under root in one way or another)
201  //if (entity == m_CurrentLayer || (!onlyDirect && !m_CurrentLayer))
202  if (!onlyDirect && (entity == m_CurrentLayer || !m_CurrentLayer))
203  return true;
204 
205  if (applyExceptions)
206  {
207  //--- Root entities always visible, child entities only when their parent is
208  if (entity.HasEntityFlag(EEditableEntityFlag.IGNORE_LAYERS))
209  {
210  SCR_EditableEntityComponent parent = entity.GetParentEntity();
211  return !parent || IsUnderCurrentLayer(parent, onlyDirect);
212  }
213 
214  while (entity)
215  {
216  entity = entity.GetParentEntity();
217  if (entity == m_CurrentLayer)
218  return true;
219 
220  if (onlyDirect && (!entity || !entity.HasEntityFlag(EEditableEntityFlag.INDIVIDUAL_CHILDREN)))
221  return false;
222  }
223  }
224  else
225  {
226  while (entity)
227  {
228  entity = entity.GetParentEntity();
229  if (entity == m_CurrentLayer)
230  return true;
231 
232  if (onlyDirect)
233  return false;
234  }
235  }
236  return false;
237  }
243  void MoveToCurrentLayer(notnull set<SCR_EditableEntityComponent> entities)
244  {
245  MoveToLayer(entities, m_CurrentLayer);
246  }
253  void MoveToLayer(notnull set<SCR_EditableEntityComponent> entities, SCR_EditableEntityComponent layer)
254  {
255  array<RplId> entityIDs = new array<RplId>();
256  RplId entityID;
257  foreach (SCR_EditableEntityComponent entity: entities)
258  {
259  if (entity.IsReplicated(entityID))
260  entityIDs.Insert(entityID);
261  }
262 
263  Rpc(MoveToLayerServer, entityIDs, Replication.FindId(layer))
264  }
265 
272  void MoveToLayerAndSelect(notnull set<SCR_EditableEntityComponent> entities, SCR_EditableEntityComponent layer, bool selectParentAfterMove = false)
273  {
274  if (!m_SelectionFilter)
275  return;
276 
277  m_EntitiesToSelectAfterMove.Clear();
278 
279  selectParentAfterMove = (selectParentAfterMove && layer != null);
280 
281  foreach (SCR_EditableEntityComponent entity: entities)
282  {
283  m_EntitiesToSelectAfterMove.Insert(entity);
284  }
285 
286  m_bSelectAfterMoveCanceled = false;
287  m_Core.Event_OnParentEntityChanged.Insert(OnEditableParentChanged);
288  m_SelectionFilter.GetOnChanged().Insert(OnSelectionChanged);
289 
290  SetCurrentLayer(layer);
291  MoveToLayer(entities, layer);
292  }
293 
294  void SplitGroupAndAddCharacters(SCR_EditableCharacterComponent leader, notnull set<SCR_EditableEntityComponent> entities)
295  {
296  if (!leader)
297  return;
298 
299  m_EntitiesToSelectAfterMove.Clear();
300  m_NewGroupLeader = leader;
301  m_bSelectAfterMoveCanceled = false;
302  m_bSelectParentAfterMove = true;
303  m_Core.Event_OnParentEntityChanged.Insert(OnEditableParentChanged);
304  m_SelectionFilter.GetOnChanged().Insert(OnSelectionChanged);
305 
306  foreach (SCR_EditableEntityComponent entity: entities)
307  {
308  m_EntitiesToSelectAfterMove.Insert(entity);
309  }
310 
311 
312  set<SCR_EditableEntityComponent> leaderSet = new set<SCR_EditableEntityComponent>;
313  leaderSet.Insert(m_NewGroupLeader);
314  MoveToLayer(leaderSet, null);
315  }
316 
317  protected void AddCharactersToGroup(notnull set<SCR_EditableEntityComponent> entities, SCR_EditableEntityComponent group)
318  {
319  MoveToLayer(entities, group);
320  }
321 
322  //Checkes if parent changed of entity that needs to be selected after move
323  protected void OnEditableParentChanged(SCR_EditableEntityComponent entity, SCR_EditableEntityComponent newParent, SCR_EditableEntityComponent prevParent)
324  {
325  if (!entity)
326  return;
327 
328  if (m_EntitiesToSelectAfterMove.Contains(entity))
329  GetGame().GetCallqueue().CallLater(DelayedSelectMovedEntity, 1, false, entity);
330  else if (entity == m_NewGroupLeader)
331  {
332  if (m_EntitiesToSelectAfterMove.Count() > 0)
333  AddCharactersToGroup(m_EntitiesToSelectAfterMove, newParent);
334  else
335  EntitiesSelectAfterMoveDone(m_NewGroupLeader);
336  }
337  }
338 
339  //Delayed move so entity can be selected properly
340  protected void DelayedSelectMovedEntity(SCR_EditableEntityComponent entity)
341  {
342  if (m_bSelectAfterMoveCanceled)
343  return;
344 
345  if (!m_bSelectParentAfterMove && m_SelectionFilter)
346  m_SelectionFilter.Add(entity, true);
347 
348  int index = m_EntitiesToSelectAfterMove.Find(entity);
349 
350  if (index >= 0)
351  m_EntitiesToSelectAfterMove.Remove(index);
352 
353  //All entities have been selected after being moved
354  if (m_EntitiesToSelectAfterMove.IsEmpty())
355  EntitiesSelectAfterMoveDone(entity);
356  }
357 
358  //On selection changed
359  protected void OnSelectionChanged(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesSelected, set<SCR_EditableEntityComponent> entitiesDeselected)
360  {
361  if (entitiesSelected && !entitiesSelected.IsEmpty())
362  {
363  foreach (SCR_EditableEntityComponent entity: entitiesSelected)
364  {
365  if (!entity)
366  continue;
367 
368  if (!m_EntitiesToSelectAfterMove.Contains(entity) && entity != m_NewGroupLeader)
369  {
370  ClearEntitiesSelectAfterMove();
371  return;
372  }
373  }
374  }
375  if (entitiesDeselected && !entitiesDeselected.IsEmpty())
376  {
377  foreach (SCR_EditableEntityComponent entity: entitiesDeselected)
378  {
379  if (!entity)
380  continue;
381 
382  if (!m_EntitiesToSelectAfterMove.Contains(entity) && entity != m_NewGroupLeader)
383  {
384  ClearEntitiesSelectAfterMove();
385  return;
386  }
387  }
388  }
389  }
390 
391  //Clear all var and event listeners
392  protected void ClearEntitiesSelectAfterMove()
393  {
394  if (m_Core)
395  m_Core.Event_OnParentEntityChanged.Remove(OnEditableParentChanged);
396  if (m_SelectionFilter)
397  m_SelectionFilter.GetOnChanged().Remove(OnSelectionChanged);
398 
399  m_bSelectParentAfterMove = false;
400  m_bSelectAfterMoveCanceled = true;
401  m_NewGroupLeader = null;
402  m_EntitiesToSelectAfterMove.Clear();
403  }
404 
405  protected void EntitiesSelectAfterMoveDone(SCR_EditableEntityComponent lastEntity)
406  {
407  if (m_bSelectParentAfterMove && m_SelectionFilter)
408  {
409  m_SelectionFilter.Add(lastEntity.GetParentEntity(), true);
410  }
411 
412  ClearEntitiesSelectAfterMove();
413  }
414 
415 
416  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
417  protected void MoveToLayerServer(notnull array<RplId> entityIDs, RplId layerID)
418  {
419  //--- Deserialize
420  SCR_EditableEntityComponent layer = SCR_EditableEntityComponent.Cast(Replication.FindItem(layerID));
421 
422  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
423  SCR_EditableEntityComponent entityCandidate;
424  foreach (RplId entityID: entityIDs)
425  {
426  entityCandidate = SCR_EditableEntityComponent.Cast(Replication.FindItem(entityID));
427  if (entityCandidate)
428  entities.Insert(entityCandidate);
429  }
430 
431  //--- Move to target layer
432  foreach (SCR_EditableEntityComponent entity: entities)
433  {
434  bool parentInEntities = false;
435  SCR_EditableEntityComponent parent = entity.GetParentEntity();
436  while (parent)
437  {
438  if (entities.Find(parent) != -1)
439  {
440  parentInEntities = true;
441  break;
442  }
443  parent = parent.GetParentEntity();
444  }
445  if (!parentInEntities)
446  {
447  entity.SetParentEntity(layer, true);
448  }
449  }
450  }
451 
452  protected void OnUserSettingsChanged()
453  {
454  BaseContainer editorSettings = GetGame().GetGameUserSettings().GetModule("SCR_EditorSettings");
455  if (editorSettings)
456  {
457  bool state;
458  editorSettings.Get("m_bLayerEditing", state);
459  SetEditingLayersEnabled(state);
460  }
461  }
462 
463  protected void OnEntityUnregistered(SCR_EditableEntityComponent entity)
464  {
465  if (entity == m_CurrentLayer)
466  SetCurrentLayer(null);
467  }
468  protected void OnEntityAccessKeyChanged(SCR_EditableEntityComponent entity)
469  {
470  if (entity == m_CurrentLayer && !entity.HasAccessInHierarchy())
471  SetCurrentLayer(null);
472  }
473  protected void OnEntityVisibilityChanged(SCR_EditableEntityComponent entity)
474  {
475  if (entity == m_CurrentLayer && !entity.GetVisibleInHierarchy())
476  SetCurrentLayer(null);
477  }
478  protected void OnAccessKeysChanged()
479  {
480  if (m_CurrentLayer && !m_CurrentLayer.HasAccessInHierarchy())
481  SetCurrentLayer(null);
482  }
483  override void EOnEditorDebug(array<string> debugTexts)
484  {
485  if (!IsActive()) return;
486 
487  string currentLayerName = "/";
488  if (m_CurrentLayer)
489  {
490  SCR_EditableEntityComponent currentLayer = m_CurrentLayer;
491  while (currentLayer)
492  {
493  currentLayerName = "/" + currentLayer.GetDisplayName() + currentLayerName;
494  currentLayer = currentLayer.GetParentEntity();
495  }
496  }
497  debugTexts.Insert("Current Layer: Root:" + currentLayerName);
498  }
499  override void EOnEditorInit()
500  {
502  if (m_Core)
503  {
504  m_Core.Event_OnEntityUnregistered.Insert(OnEntityUnregistered);
505  m_Core.Event_OnEntityAccessKeyChanged.Insert(OnEntityAccessKeyChanged);
506  m_Core.Event_OnEntityVisibilityChanged.Insert(OnEntityVisibilityChanged);
507  }
508  SCR_AccessKeysEditorComponent accessKeysManager = SCR_AccessKeysEditorComponent.Cast(GetInstance(SCR_AccessKeysEditorComponent));
509  if (accessKeysManager)
510  {
511  accessKeysManager.Event_OnChanged.Insert(OnAccessKeysChanged);
512  }
513 
514  //Get layer enabled settings
515  OnUserSettingsChanged();
516  GetGame().OnUserSettingsChangedInvoker().Insert(OnUserSettingsChanged);
517  }
518 
519  override void EOnEditorDelete()
520  {
521  if (m_Core)
522  {
523  m_Core.Event_OnEntityUnregistered.Remove(OnEntityUnregistered);
524  m_Core.Event_OnEntityAccessKeyChanged.Remove(OnEntityAccessKeyChanged);
525  m_Core.Event_OnEntityVisibilityChanged.Remove(OnEntityVisibilityChanged);
526  }
527  SCR_AccessKeysEditorComponent accessKeysManager = SCR_AccessKeysEditorComponent.Cast(GetInstance(SCR_AccessKeysEditorComponent));
528  if (accessKeysManager)
529  {
530  accessKeysManager.Event_OnChanged.Remove(OnAccessKeysChanged);
531  }
532 
533  if (!m_EntitiesToSelectAfterMove.IsEmpty())
534  ClearEntitiesSelectAfterMove();
535  }
536 
537  override void EOnEditorOpen()
538  {
539  super.EOnEditorOpen();
540 
541  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
542  if (editorManager)
543  editorManager.GetOnModeChange().Insert(OnEditorModeChanged);
544 
545  //Get selection filter
546  if (!m_SelectionFilter)
547  m_SelectionFilter = SCR_BaseEditableEntityFilter.GetInstance(EEditableEntityState.SELECTED);
548  }
549 
550  override void EOnEditorClose()
551  {
552  super.EOnEditorClose();
553 
554  //Go out of editing layer
555  SetCurrentLayer(null);
556 
557  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
558  if (editorManager)
559  editorManager.GetOnModeChange().Remove(OnEditorModeChanged);
560  }
561 
562  override void OnDelete(IEntity owner)
563  {
564  if (GetGame())
565  GetGame().OnUserSettingsChangedInvoker().Remove(OnUserSettingsChanged);
566  }
567 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_LayersEditorComponentClass
Definition: SCR_LayersEditorManager.c:2
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
IsActive
bool IsActive()
Definition: SCR_LoadoutSaveBlackListHolder.c:82
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26