1 [
ComponentEditorProps(
category:
"GameScripted/Editor", description:
"Manager of current layer. Works only with SCR_EditorBaseEntity!", icon:
"WBData/ComponentEditorProps/componentEditor.png")]
14 protected ResourceName m_sNewLayerPrefab;
17 ref ScriptInvoker Event_OnCurrentLayerChange =
new ScriptInvoker;
19 protected bool m_bEditingLayersEnabled;
22 protected ref set<SCR_EditableEntityComponent> m_EntitiesToSelectAfterMove =
new set<SCR_EditableEntityComponent>();
24 protected bool m_bSelectAfterMoveCanceled;
25 protected bool m_bSelectParentAfterMove;
30 bool IsEditingLayersEnabled()
32 return m_bEditingLayersEnabled;
40 void SetEditingLayersEnabled(
bool enableLayerEditing)
42 if (m_bEditingLayersEnabled == enableLayerEditing)
45 SetCurrentLayer(
null);
46 m_bEditingLayersEnabled = enableLayerEditing;
53 ScriptInvoker GetOnCurrentLayerChange()
55 return Event_OnCurrentLayerChange;
61 if (prevModeEntity && prevModeEntity.GetModeType() ==
EEditorMode.EDIT)
62 SetCurrentLayer(
null);
73 if (!IsEditingLayersEnabled())
76 if (entity == m_CurrentLayer || (entity && !entity.HasEntityFlag(
EEditableEntityFlag.LAYER)))
80 m_CurrentLayer = entity;
81 Event_OnCurrentLayerChange.Invoke(m_CurrentLayer, prevCurrentLayer);
87 void SetCurrentLayerToParent()
90 if (!currentLayer)
return;
92 SetCurrentLayer(currentLayer.GetParentEntity());
101 if (entity == GetCurrentLayer())
104 if (entity) SetCurrentLayer(entity.GetParentEntity());
110 if (!parent) parent = entity;
111 SetCurrentLayer(parent);
121 return m_CurrentLayer;
127 void CreateNewLayerWithSelected(notnull set<SCR_EditableEntityComponent> entities, vector worldPosition)
129 array<RplId> entityIDs =
new array<RplId>();
133 entities[0].GetTransform(transform);
134 transform[3] = worldPosition;
138 if (entity.IsReplicated(entityID))
139 entityIDs.Insert(entityID);
142 Rpc(CreateNewLayerWithSelectedRpl, entityIDs, transform, Replication.FindId(m_CurrentLayer));
145 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
146 protected void CreateNewLayerWithSelectedRpl(notnull array<RplId> entityIDs, vector transform[4], RplId currentLayerID)
148 EntitySpawnParams spawnParams =
new EntitySpawnParams();
149 spawnParams.Transform = transform;
151 IEntity layer =
GetGame().SpawnEntityPrefab(Resource.Load(m_sNewLayerPrefab),
GetGame().GetWorld(), spawnParams);
161 editableLayer.SetParentEntity(currentLayer);
163 MoveToLayerServer(entityIDs, Replication.FindId(editableLayer));
177 if (!entity || entity == m_CurrentLayer || entity.HasEntityFlag(
EEditableEntityFlag.IGNORE_LAYERS))
183 parent = entity.GetParentEntity();
184 if (parent == m_CurrentLayer || (parent && parent.HasEntityFlag(
EEditableEntityFlag.INDIVIDUAL_CHILDREN)))
return entity;
202 if (!onlyDirect && (entity == m_CurrentLayer || !m_CurrentLayer))
211 return !parent || IsUnderCurrentLayer(parent, onlyDirect);
216 entity = entity.GetParentEntity();
217 if (entity == m_CurrentLayer)
220 if (onlyDirect && (!entity || !entity.HasEntityFlag(
EEditableEntityFlag.INDIVIDUAL_CHILDREN)))
228 entity = entity.GetParentEntity();
229 if (entity == m_CurrentLayer)
243 void MoveToCurrentLayer(notnull set<SCR_EditableEntityComponent> entities)
245 MoveToLayer(entities, m_CurrentLayer);
255 array<RplId> entityIDs =
new array<RplId>();
259 if (entity.IsReplicated(entityID))
260 entityIDs.Insert(entityID);
263 Rpc(MoveToLayerServer, entityIDs, Replication.FindId(layer))
272 void MoveToLayerAndSelect(notnull set<SCR_EditableEntityComponent> entities,
SCR_EditableEntityComponent layer,
bool selectParentAfterMove =
false)
274 if (!m_SelectionFilter)
277 m_EntitiesToSelectAfterMove.Clear();
279 selectParentAfterMove = (selectParentAfterMove && layer !=
null);
283 m_EntitiesToSelectAfterMove.Insert(entity);
286 m_bSelectAfterMoveCanceled =
false;
287 m_Core.Event_OnParentEntityChanged.Insert(OnEditableParentChanged);
288 m_SelectionFilter.GetOnChanged().Insert(OnSelectionChanged);
290 SetCurrentLayer(layer);
291 MoveToLayer(entities, layer);
294 void SplitGroupAndAddCharacters(SCR_EditableCharacterComponent leader, notnull set<SCR_EditableEntityComponent> entities)
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);
308 m_EntitiesToSelectAfterMove.Insert(entity);
312 set<SCR_EditableEntityComponent> leaderSet =
new set<SCR_EditableEntityComponent>;
313 leaderSet.Insert(m_NewGroupLeader);
314 MoveToLayer(leaderSet,
null);
319 MoveToLayer(entities, group);
328 if (m_EntitiesToSelectAfterMove.Contains(entity))
329 GetGame().GetCallqueue().CallLater(DelayedSelectMovedEntity, 1,
false, entity);
330 else if (entity == m_NewGroupLeader)
332 if (m_EntitiesToSelectAfterMove.Count() > 0)
333 AddCharactersToGroup(m_EntitiesToSelectAfterMove, newParent);
335 EntitiesSelectAfterMoveDone(m_NewGroupLeader);
342 if (m_bSelectAfterMoveCanceled)
345 if (!m_bSelectParentAfterMove && m_SelectionFilter)
346 m_SelectionFilter.Add(entity,
true);
348 int index = m_EntitiesToSelectAfterMove.Find(entity);
351 m_EntitiesToSelectAfterMove.Remove(
index);
354 if (m_EntitiesToSelectAfterMove.IsEmpty())
355 EntitiesSelectAfterMoveDone(entity);
359 protected void OnSelectionChanged(
EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesSelected, set<SCR_EditableEntityComponent> entitiesDeselected)
361 if (entitiesSelected && !entitiesSelected.IsEmpty())
368 if (!m_EntitiesToSelectAfterMove.Contains(entity) && entity != m_NewGroupLeader)
370 ClearEntitiesSelectAfterMove();
375 if (entitiesDeselected && !entitiesDeselected.IsEmpty())
382 if (!m_EntitiesToSelectAfterMove.Contains(entity) && entity != m_NewGroupLeader)
384 ClearEntitiesSelectAfterMove();
392 protected void ClearEntitiesSelectAfterMove()
395 m_Core.Event_OnParentEntityChanged.Remove(OnEditableParentChanged);
396 if (m_SelectionFilter)
397 m_SelectionFilter.GetOnChanged().Remove(OnSelectionChanged);
399 m_bSelectParentAfterMove =
false;
400 m_bSelectAfterMoveCanceled =
true;
401 m_NewGroupLeader =
null;
402 m_EntitiesToSelectAfterMove.Clear();
407 if (m_bSelectParentAfterMove && m_SelectionFilter)
409 m_SelectionFilter.Add(lastEntity.GetParentEntity(),
true);
412 ClearEntitiesSelectAfterMove();
416 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
417 protected void MoveToLayerServer(notnull array<RplId> entityIDs, RplId layerID)
422 set<SCR_EditableEntityComponent> entities =
new set<SCR_EditableEntityComponent>();
424 foreach (RplId entityID: entityIDs)
428 entities.Insert(entityCandidate);
434 bool parentInEntities =
false;
438 if (entities.Find(parent) != -1)
440 parentInEntities =
true;
443 parent = parent.GetParentEntity();
445 if (!parentInEntities)
447 entity.SetParentEntity(layer,
true);
452 protected void OnUserSettingsChanged()
454 BaseContainer editorSettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_EditorSettings");
458 editorSettings.Get(
"m_bLayerEditing", state);
459 SetEditingLayersEnabled(state);
465 if (entity == m_CurrentLayer)
466 SetCurrentLayer(
null);
470 if (entity == m_CurrentLayer && !entity.HasAccessInHierarchy())
471 SetCurrentLayer(
null);
475 if (entity == m_CurrentLayer && !entity.GetVisibleInHierarchy())
476 SetCurrentLayer(
null);
478 protected void OnAccessKeysChanged()
480 if (m_CurrentLayer && !m_CurrentLayer.HasAccessInHierarchy())
481 SetCurrentLayer(
null);
483 override void EOnEditorDebug(array<string> debugTexts)
487 string currentLayerName =
"/";
493 currentLayerName =
"/" + currentLayer.GetDisplayName() + currentLayerName;
494 currentLayer = currentLayer.GetParentEntity();
497 debugTexts.Insert(
"Current Layer: Root:" + currentLayerName);
499 override void EOnEditorInit()
504 m_Core.Event_OnEntityUnregistered.Insert(OnEntityUnregistered);
505 m_Core.Event_OnEntityAccessKeyChanged.Insert(OnEntityAccessKeyChanged);
506 m_Core.Event_OnEntityVisibilityChanged.Insert(OnEntityVisibilityChanged);
508 SCR_AccessKeysEditorComponent accessKeysManager = SCR_AccessKeysEditorComponent.Cast(
GetInstance(SCR_AccessKeysEditorComponent));
509 if (accessKeysManager)
511 accessKeysManager.Event_OnChanged.Insert(OnAccessKeysChanged);
515 OnUserSettingsChanged();
516 GetGame().OnUserSettingsChangedInvoker().Insert(OnUserSettingsChanged);
519 override void EOnEditorDelete()
523 m_Core.Event_OnEntityUnregistered.Remove(OnEntityUnregistered);
524 m_Core.Event_OnEntityAccessKeyChanged.Remove(OnEntityAccessKeyChanged);
525 m_Core.Event_OnEntityVisibilityChanged.Remove(OnEntityVisibilityChanged);
527 SCR_AccessKeysEditorComponent accessKeysManager = SCR_AccessKeysEditorComponent.Cast(
GetInstance(SCR_AccessKeysEditorComponent));
528 if (accessKeysManager)
530 accessKeysManager.Event_OnChanged.Remove(OnAccessKeysChanged);
533 if (!m_EntitiesToSelectAfterMove.IsEmpty())
534 ClearEntitiesSelectAfterMove();
537 override void EOnEditorOpen()
539 super.EOnEditorOpen();
543 editorManager.GetOnModeChange().Insert(OnEditorModeChanged);
546 if (!m_SelectionFilter)
550 override void EOnEditorClose()
552 super.EOnEditorClose();
555 SetCurrentLayer(
null);
559 editorManager.GetOnModeChange().Remove(OnEditorModeChanged);
562 override void OnDelete(IEntity owner)
565 GetGame().OnUserSettingsChangedInvoker().Remove(OnUserSettingsChanged);