1 [
ComponentEditorProps(
category:
"GameScripted/Editor", description:
"Entity transformation (moving and rotating). Works only with SCR_EditorBaseEntity!", icon:
"WBData/ComponentEditorProps/componentEditor.png")]
5 private ref array<ref SCR_BaseEditorEffect> m_EffectsTransforationStart;
8 private ref array<ref SCR_BaseEditorEffect> m_EffectsTransformationConfirm;
11 private ref array<ref SCR_BaseEditorEffect> m_EffectsTransformationCancel;
13 array<ref SCR_BaseEditorEffect> GetEffectsTransforationStart()
15 return m_EffectsTransforationStart;
17 array<ref SCR_BaseEditorEffect> GetEffectsTransformationConfirm()
19 return m_EffectsTransformationConfirm;
21 array<ref SCR_BaseEditorEffect> GetEffectsTransformationCancel()
23 return m_EffectsTransformationCancel;
35 protected ref set<SCR_EditableEntityComponent> m_aEditedEntities;
36 protected ref map<SCR_EditableEntityComponent, vector> m_mServerEntityStartingPosition =
new map<SCR_EditableEntityComponent, vector>();
42 protected bool m_bIsComposition;
43 protected bool m_bCanBeTransformed =
true;
45 protected ref ScriptInvoker Event_OnTransformationRequest =
new ScriptInvoker;
46 protected ref ScriptInvoker Event_OnTransformationStart =
new ScriptInvoker;
47 protected ref ScriptInvoker Event_OnTransformationConfirm =
new ScriptInvoker;
48 protected ref ScriptInvoker Event_OnTransformationCancel =
new ScriptInvoker;
51 protected ref ScriptInvoker Event_OnTransformationConfirmServer =
new ScriptInvoker;
65 if (!
IsOwner() || entities.IsEmpty())
return;
69 m_bIsComposition =
true;
71 array<int> entityIds =
new array<int>;
72 m_aEditedEntities =
new set<SCR_EditableEntityComponent>;
80 m_EditedLayer = layersManager.GetCurrentLayer();
83 parentBelowCurrentLayer = layersManager.GetParentBelowCurrentLayer(pivot);
84 if (entities.Find(parentBelowCurrentLayer) != -1 && parentBelowCurrentLayer.IsReplicated(
id))
86 if (m_aEditedEntities.Insert(parentBelowCurrentLayer))
94 if (entity.IsReplicated(
id) && m_aEditedEntities.Find(entity) == -1)
96 m_aEditedEntities.Insert(entity);
99 if (entity != parentBelowCurrentLayer && !entity.IsChildOf(parentBelowCurrentLayer))
100 m_bIsComposition =
false;
105 if (entityIds.IsEmpty())
112 if (m_bIsComposition)
113 pivot = parentBelowCurrentLayer;
117 if (!pivot.IsReplicated(pivotId))
122 m_EditedPivot = pivot;
127 core.Event_OnEntityUnregistered.Insert(OnEntityUnregistered);
128 core.Event_OnEntityVisibilityChanged.Insert(OnEntityVisibilityChanged);
129 core.Event_OnEntityAccessKeyChanged.Insert(OnEntityAccessKeyChanged);
134 Event_OnTransformationRequest.Invoke(m_aEditedEntities);
139 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
140 protected void StartEditingServer(
int pivotId, array<int> entityIds, vector dummyVector, vector transform[4],
bool isUnderwater,
EEditorTransformVertical verticalMode)
142 m_aEditedEntities =
new set<SCR_EditableEntityComponent>;
143 m_mServerEntityStartingPosition.Clear();
147 foreach (
int id: entityIds)
150 if (!entity)
continue;
158 m_aEditedEntities.Insert(entity);
159 m_mServerEntityStartingPosition.Insert(entity, pos);
163 EntitySpawnParams spawnParams =
new EntitySpawnParams();
164 spawnParams.Transform = transform;
173 ResourceName material;
174 #ifdef PREVIEW_ENTITY_SHOW_REFERENCE
175 material =
"{D0126AF0E6A27141}Common/Materials/Colors/colorRed.emat";
180 int simulatedDelay = DiagMenu.GetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_NETWORK_DELAY) * 100;
181 if (simulatedDelay > 0 && !Replication.IsRunning())
182 GetGame().GetCallqueue().CallLater(StartEditingOwner, simulatedDelay,
false);
184 Rpc(StartEditingOwner);
187 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
188 protected void StartEditingOwner()
202 Event_OnTransformationStart.Invoke(m_aEditedEntities);
205 if (prefabData)
SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransforationStart(),
this, entities: m_aEditedEntities);
216 bool ConfirmEditing()
235 bool currentLayerChanged;
240 currentLayer = layersManager.GetCurrentLayer();
241 currentLayerChanged = m_EditedLayer != layersManager.GetCurrentLayer();
246 if (!
params)
return false;
249 Rpc(ConfirmEditingServer,
params);
253 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
256 if (!
params.Deserialize())
258 Rpc(CancelEditingServer);
265 m_RefEntity.ApplyReference(
params);
271 if (slotEntity) slotEntity.SetOccupant(m_EditedPivot.GetOwner());
274 Event_OnTransformationConfirmServer.Invoke(m_aEditedEntities, m_mServerEntityStartingPosition);
278 Rpc(ConfirmEditingOwner, result);
282 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
283 protected void ConfirmEditingOwner(
bool result)
290 Event_OnTransformationConfirm.Invoke(m_aEditedEntities);
292 if (prefabData)
SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransformationConfirm(),
this, transform[3], m_aEditedEntities);
297 SCR_NotificationsComponent.SendLocal(
ENotification.EDITOR_TRANSFORMING_FAIL);
315 if (!m_aEditedEntities)
return;
317 Event_OnTransformationCancel.Invoke(m_aEditedEntities);
319 if (prefabData)
SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransformationCancel(),
this, entities: m_aEditedEntities);
321 Rpc(CancelEditingServer);
325 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
326 protected void CancelEditingServer()
339 return m_aEditedEntities !=
null;
347 return m_aEditedEntities && m_aEditedEntities.Find(entity) != -1;
354 ScriptInvoker GetOnTransformationRequest()
356 return Event_OnTransformationRequest;
363 ScriptInvoker GetOnTransformationStart()
365 return Event_OnTransformationStart;
372 ScriptInvoker GetOnTransformationConfirm()
374 return Event_OnTransformationConfirm;
381 ScriptInvoker GetOnTransformationConfirmServer()
383 if (!Replication.IsServer())
386 return Event_OnTransformationConfirmServer;
393 ScriptInvoker GetOnTransformationCancel()
395 return Event_OnTransformationCancel;
397 bool CanBeTransformed()
399 return m_bCanBeTransformed;
401 void SetCanBeTransformed(
bool val)
403 m_bCanBeTransformed = val;
405 protected void Clean()
407 m_aEditedEntities =
null;
408 m_EditedPivot =
null;
409 #ifndef PREVIEW_ENTITY_SHOW_REFERENCE
419 core.Event_OnEntityUnregistered.Remove(OnEntityUnregistered);
420 core.Event_OnEntityVisibilityChanged.Remove(OnEntityVisibilityChanged);
421 core.Event_OnEntityAccessKeyChanged.Remove(OnEntityAccessKeyChanged);
426 if (!m_aEditedEntities || m_aEditedEntities.Find(entity) == -1)
return;
433 if (!m_aEditedEntities || m_aEditedEntities.Find(entity) == -1)
return;
435 if (!entity.GetVisibleInHierarchy()) CancelEditing();
440 if (!m_aEditedEntities || m_aEditedEntities.Find(entity) == -1)
return;
442 if (!entity.HasAccessInHierarchy()) CancelEditing();
448 override void EOnFrame(IEntity owner,
float timeSlice)
462 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_START,
false);
470 set<SCR_EditableEntityComponent> selected =
new set<SCR_EditableEntityComponent>;
471 selectedFilter.GetEntities(selected);
472 if (!selected.IsEmpty())
475 selected[0].GetOwner().GetWorldTransform(transform);
476 StartEditing(selected[0], selected, transform);
481 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CONFIRM))
483 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CONFIRM,
false);
488 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CANCEL,
false);
492 override void EOnEditorActivate()
494 SetEventMask(
GetOwner(), EntityEvent.FRAME);
499 DiagMenu.RegisterMenu(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM,
"Transforming",
"Editor");
500 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_START,
"",
"Start Transforming",
"Transforming");
501 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CONFIRM,
"",
"Confirm Transforming",
"Transforming");
502 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CANCEL,
"",
"Cancel Transforming",
"Transforming");
504 override void EOnEditorDeactivate()
511 DiagMenu.Unregister(
SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_VERTICAL_MODE);