Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TransformingEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "Entity transformation (moving and rotating). Works only with SCR_EditorBaseEntity!", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4  [Attribute(category: "Effects")]
5  private ref array<ref SCR_BaseEditorEffect> m_EffectsTransforationStart;
6 
7  [Attribute(category: "Effects")]
8  private ref array<ref SCR_BaseEditorEffect> m_EffectsTransformationConfirm;
9 
10  [Attribute(category: "Effects")]
11  private ref array<ref SCR_BaseEditorEffect> m_EffectsTransformationCancel;
12 
13  array<ref SCR_BaseEditorEffect> GetEffectsTransforationStart()
14  {
15  return m_EffectsTransforationStart;
16  }
17  array<ref SCR_BaseEditorEffect> GetEffectsTransformationConfirm()
18  {
19  return m_EffectsTransformationConfirm;
20  }
21  array<ref SCR_BaseEditorEffect> GetEffectsTransformationCancel()
22  {
23  return m_EffectsTransformationCancel;
24  }
25 };
26 
34 {
35  protected ref set<SCR_EditableEntityComponent> m_aEditedEntities;
36  protected ref map<SCR_EditableEntityComponent, vector> m_mServerEntityStartingPosition = new map<SCR_EditableEntityComponent, vector>();
37  protected SCR_EditableEntityComponent m_EditedPivot;
38  protected SCR_EditableEntityComponent m_EditedLayer;
39  protected SCR_RefPreviewEntity m_RefEntity;
40  protected SCR_StatesEditorComponent m_StatesManager;
41  protected SCR_PreviewEntityEditorComponent m_PreviewManager;
42  protected bool m_bIsComposition;
43  protected bool m_bCanBeTransformed = true;
44 
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;
49 
50  //Server only script invokers
51  protected ref ScriptInvoker Event_OnTransformationConfirmServer = new ScriptInvoker;
52 
54  //--- Start
62  void StartEditing(SCR_EditableEntityComponent pivot, notnull set<SCR_EditableEntityComponent> entities, vector transform[4])
63  {
64  //--- Not an owner, ignore
65  if (!IsOwner() || entities.IsEmpty()) return;
66 
67  if (m_PreviewManager) m_PreviewManager.InitTransform(transform);
68 
69  m_bIsComposition = true;
70  int id = 0;
71  array<int> entityIds = new array<int>;
72  m_aEditedEntities = new set<SCR_EditableEntityComponent>;
73 
74 
75  //--- Connect to layer manager
77  SCR_EditableEntityComponent parentBelowCurrentLayer = null;
78  if (layersManager)
79  {
80  m_EditedLayer = layersManager.GetCurrentLayer();
81 
82  //--- Is composition root edited as well? If not, insert it.
83  parentBelowCurrentLayer = layersManager.GetParentBelowCurrentLayer(pivot);
84  if (entities.Find(parentBelowCurrentLayer) != -1 && parentBelowCurrentLayer.IsReplicated(id))
85  {
86  if (m_aEditedEntities.Insert(parentBelowCurrentLayer))
87  entityIds.Insert(id);
88  }
89  }
90 
91  //--- Add valid entities and check if they are all part of one composition
92  foreach (SCR_EditableEntityComponent entity: entities)
93  {
94  if (entity.IsReplicated(id) && m_aEditedEntities.Find(entity) == -1)
95  {
96  m_aEditedEntities.Insert(entity);
97  entityIds.Insert(id);
98 
99  if (entity != parentBelowCurrentLayer && !entity.IsChildOf(parentBelowCurrentLayer))
100  m_bIsComposition = false;
101  }
102  }
103 
104  //--- Not valid entities found, ignore
105  if (entityIds.IsEmpty())
106  {
107  Clean();
108  return;
109  }
110 
111  //--- All selected entities belong to one composition - use its rotation instead. so it can be snapped to slots
112  if (m_bIsComposition)
113  pivot = parentBelowCurrentLayer;
114 
115  //---- Validate pivot point
116  int pivotId;
117  if (!pivot.IsReplicated(pivotId))
118  {
119  Clean();
120  return;
121  }
122  m_EditedPivot = pivot;
123 
125  if (core)
126  {
127  core.Event_OnEntityUnregistered.Insert(OnEntityUnregistered);
128  core.Event_OnEntityVisibilityChanged.Insert(OnEntityVisibilityChanged);
129  core.Event_OnEntityAccessKeyChanged.Insert(OnEntityAccessKeyChanged);
130  }
131 
132  m_StatesManager.SetState(EEditorState.TRANSFORMING);
133  m_StatesManager.SetIsWaiting(true);
134  Event_OnTransformationRequest.Invoke(m_aEditedEntities);
135 
136  Rpc(StartEditingServer, pivotId, entityIds, vector.One, transform, m_PreviewManager.IsUnderwater(), m_PreviewManager.GetVerticalMode());
137  }
138 
139  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
140  protected void StartEditingServer(int pivotId, array<int> entityIds, vector dummyVector, vector transform[4], bool isUnderwater, EEditorTransformVertical verticalMode)
141  {
142  m_aEditedEntities = new set<SCR_EditableEntityComponent>;
143  m_mServerEntityStartingPosition.Clear();
144 
145  m_EditedPivot = SCR_EditableEntityComponent.Cast(Replication.FindItem(pivotId));
146 
147  foreach (int id: entityIds)
148  {
149  SCR_EditableEntityComponent entity = SCR_EditableEntityComponent.Cast(Replication.FindItem(id));
150  if (!entity) continue;
151 
152  GenericEntity owner = entity.GetOwner();
153  if (!owner) return;
154 
155  vector pos;
156  entity.GetPos(pos);
157 
158  m_aEditedEntities.Insert(entity);
159  m_mServerEntityStartingPosition.Insert(entity, pos);
160  }
161 
162  //--- Create reference entity
163  EntitySpawnParams spawnParams = new EntitySpawnParams();
164  spawnParams.Transform = transform;
165 
166  EPreviewEntityFlag flags = EPreviewEntityFlag.IGNORE_PREFAB | EPreviewEntityFlag.ONLY_EDITABLE;
167  if (isUnderwater)
168  flags |= EPreviewEntityFlag.UNDERWATER;
169 
170  if (verticalMode == EEditorTransformVertical.GEOMETRY)
171  flags |= EPreviewEntityFlag.GEOMETRY;
172 
173  ResourceName material;
174 #ifdef PREVIEW_ENTITY_SHOW_REFERENCE
175  material = "{D0126AF0E6A27141}Common/Materials/Colors/colorRed.emat";
176 #endif
177 
178  m_RefEntity = SCR_RefPreviewEntity.Cast(SCR_RefPreviewEntity.SpawnPreviewFromEditableEntities(m_aEditedEntities, "SCR_RefPreviewEntity", GetGame().GetWorld(), spawnParams, material, flags));
179 
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);
183  else
184  Rpc(StartEditingOwner);
185  //StartEditingOwner(result);
186  }
187  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
188  protected void StartEditingOwner()
189  {
190  if (!m_PreviewManager)
191  return;
192 
193  //--- Transforming was meanwhile canceled, ignore
194  if (!m_StatesManager.SetIsWaiting(false) || m_StatesManager.GetState() != EEditorState.TRANSFORMING)
195  {
196  CancelEditing();
197  return;
198  }
199 
200  //--- Create preview
201  m_PreviewManager.CreatePreview(m_EditedPivot, m_aEditedEntities);
202  Event_OnTransformationStart.Invoke(m_aEditedEntities);
203 
204  SCR_TransformingEditorComponentClass prefabData = SCR_TransformingEditorComponentClass.Cast(GetEditorComponentData());
205  if (prefabData) SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransforationStart(), this, entities: m_aEditedEntities);
206  }
207 
209  //--- Confirm
216  bool ConfirmEditing()
217  {
218  //--- No change or incorrect position
219  if (!m_PreviewManager || !m_PreviewManager.IsChange())
220  {
221  //CancelEditing();
222  if (m_PreviewManager.IsEditing())
223  SendNotification(ENotification.EDITOR_TRANSFORMING_INCORRECT_POSITION);
224 
225  return false;
226  }
227 
228  //--- Not an owner, ignore
229  if (!IsOwner()) return false;
230 
231  //--- Not editing, ignore
232  if (!m_aEditedEntities || !m_PreviewManager.IsEditing()) return false;
233 
234  //--- Check if the current layer changed during transformation
235  bool currentLayerChanged;
237  SCR_EditableEntityComponent currentLayer;
238  if (layersManager)
239  {
240  currentLayer = layersManager.GetCurrentLayer();
241  currentLayerChanged = m_EditedLayer != layersManager.GetCurrentLayer();
242  }
243 
244  //--- Create packet
245  SCR_EditorPreviewParams params = SCR_EditorPreviewParams.CreateParamsFromPreview(m_PreviewManager, currentLayer, currentLayerChanged);
246  if (!params) return false;
247 
248  //--- Send request to server
249  Rpc(ConfirmEditingServer, params);
250 
251  return true;
252  }
253  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
254  protected void ConfirmEditingServer(SCR_EditorPreviewParams params)
255  {
256  if (!params.Deserialize())
257  {
258  Rpc(CancelEditingServer);
259  return;
260  }
261 
262  bool result = false;
263  if (m_RefEntity)
264  {
265  m_RefEntity.ApplyReference(params);
266 
267  //--- Mark slot as occupied
268  if (params.m_Target)
269  {
270  SCR_SiteSlotEntity slotEntity = SCR_SiteSlotEntity.Cast(params.m_Target.GetOwner());
271  if (slotEntity) slotEntity.SetOccupant(m_EditedPivot.GetOwner());
272  }
273 
274  Event_OnTransformationConfirmServer.Invoke(m_aEditedEntities, m_mServerEntityStartingPosition);
275  result = true;
276  }
277 
278  Rpc(ConfirmEditingOwner, result);
279 
280  Clean();
281  }
282  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
283  protected void ConfirmEditingOwner(bool result)
284  {
285  if (result)
286  {
287  vector transform[4];
288  m_PreviewManager.GetPreviewTransform(transform);
289 
290  Event_OnTransformationConfirm.Invoke(m_aEditedEntities);
291  SCR_TransformingEditorComponentClass prefabData = SCR_TransformingEditorComponentClass.Cast(GetEditorComponentData());
292  if (prefabData) SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransformationConfirm(), this, transform[3], m_aEditedEntities);
293  }
294  else
295  {
296  //--- Evaluate failure when editing ends, not when it starts, as "empty drag" is more confusing for user
297  SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_TRANSFORMING_FAIL);
298  }
299 
300  Clean();
301  }
302 
304  //--- Cancel
309  void CancelEditing()
310  {
311  //--- Not an owner, ignore
312  if (!IsOwner()) return;
313 
314  //--- Not editing, ignore
315  if (!m_aEditedEntities) return;
316 
317  Event_OnTransformationCancel.Invoke(m_aEditedEntities);
318  SCR_TransformingEditorComponentClass prefabData = SCR_TransformingEditorComponentClass.Cast(GetEditorComponentData());
319  if (prefabData) SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransformationCancel(), this, entities: m_aEditedEntities);
320 
321  Rpc(CancelEditingServer);
322 
323  Clean();
324  }
325  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
326  protected void CancelEditingServer()
327  {
328  Clean();
329  }
330 
332  //--- Support Funcions
337  bool IsEditing()
338  {
339  return m_aEditedEntities != null;
340  }
345  bool IsEditing(SCR_EditableEntityComponent entity)
346  {
347  return m_aEditedEntities && m_aEditedEntities.Find(entity) != -1;
348  }
354  ScriptInvoker GetOnTransformationRequest()
355  {
356  return Event_OnTransformationRequest;
357  }
363  ScriptInvoker GetOnTransformationStart()
364  {
365  return Event_OnTransformationStart;
366  }
372  ScriptInvoker GetOnTransformationConfirm()
373  {
374  return Event_OnTransformationConfirm;
375  }
381  ScriptInvoker GetOnTransformationConfirmServer()
382  {
383  if (!Replication.IsServer())
384  return null;
385 
386  return Event_OnTransformationConfirmServer;
387  }
393  ScriptInvoker GetOnTransformationCancel()
394  {
395  return Event_OnTransformationCancel;
396  }
397  bool CanBeTransformed()
398  {
399  return m_bCanBeTransformed;
400  }
401  void SetCanBeTransformed(bool val)
402  {
403  m_bCanBeTransformed = val;
404  }
405  protected void Clean()
406  {
407  m_aEditedEntities = null;
408  m_EditedPivot = null;
409 #ifndef PREVIEW_ENTITY_SHOW_REFERENCE
410  delete m_RefEntity;
411 #endif
412  if (m_PreviewManager) m_PreviewManager.DeletePreview();
413 
414  if (m_StatesManager) m_StatesManager.UnsetState(EEditorState.TRANSFORMING);
415 
417  if (core)
418  {
419  core.Event_OnEntityUnregistered.Remove(OnEntityUnregistered);
420  core.Event_OnEntityVisibilityChanged.Remove(OnEntityVisibilityChanged);
421  core.Event_OnEntityAccessKeyChanged.Remove(OnEntityAccessKeyChanged);
422  }
423  }
424  protected void OnEntityUnregistered(SCR_EditableEntityComponent entity)
425  {
426  if (!m_aEditedEntities || m_aEditedEntities.Find(entity) == -1) return;
427 
428  CancelEditing();
429  SendNotification(ENotification.EDITOR_TRANSFORMING_LOST_ACCESS, Replication.FindId(entity));
430  }
431  protected void OnEntityVisibilityChanged(SCR_EditableEntityComponent entity)
432  {
433  if (!m_aEditedEntities || m_aEditedEntities.Find(entity) == -1) return;
434 
435  if (!entity.GetVisibleInHierarchy()) CancelEditing();
436  SendNotification(ENotification.EDITOR_TRANSFORMING_LOST_ACCESS, Replication.FindId(entity));
437  }
438  protected void OnEntityAccessKeyChanged(SCR_EditableEntityComponent entity)
439  {
440  if (!m_aEditedEntities || m_aEditedEntities.Find(entity) == -1) return;
441 
442  if (!entity.HasAccessInHierarchy()) CancelEditing();
443  SendNotification(ENotification.EDITOR_TRANSFORMING_LOST_ACCESS, Replication.FindId(entity));
444  }
445 
447  //--- Default Functions
448  override void EOnFrame(IEntity owner, float timeSlice)
449  {
450  /*
451  if (Debug.KeyState(KeyCode.KC_DELETE) && m_aEditedEntities)
452  {
453  Debug.ClearKey(KeyCode.KC_DELETE);
454 
455  SCR_EditableEntityComponent entity = m_aEditedEntities[m_aEditedEntities.Count() - 1];
456  if (entity) delete entity.GetOwner();
457  }
458  */
459 
460  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_START))
461  {
462  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_START, false);
463 
465  if (entitiesManager)
466  {
467  SCR_BaseEditableEntityFilter selectedFilter = entitiesManager.GetFilter(EEditableEntityState.SELECTED);
468  if (selectedFilter)
469  {
470  set<SCR_EditableEntityComponent> selected = new set<SCR_EditableEntityComponent>;
471  selectedFilter.GetEntities(selected);
472  if (!selected.IsEmpty())
473  {
474  vector transform[4];
475  selected[0].GetOwner().GetWorldTransform(transform);
476  StartEditing(selected[0], selected, transform);
477  }
478  }
479  }
480  }
481  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CONFIRM))
482  {
483  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CONFIRM, false);
484  ConfirmEditing();
485  }
486  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CANCEL))
487  {
488  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CANCEL, false);
489  CancelEditing();
490  }
491  }
492  override void EOnEditorActivate()
493  {
494  SetEventMask(GetOwner(), EntityEvent.FRAME);
495 
498 
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");
503  }
504  override void EOnEditorDeactivate()
505  {
506  Clean();
507 
508  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_START);
509  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CONFIRM);
510  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_CANCEL);
511  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_TRANSFORM_VERTICAL_MODE);
512  }
513 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
IsOwner
protected bool IsOwner()
Definition: SCR_SpawnRequestComponent.c:86
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
m_StatesManager
private SCR_StatesEditorComponent m_StatesManager
Definition: SCR_AttributesManagerEditorComponent.c:65
EEditorState
EEditorState
Unique editor state.
Definition: EEditorState.c:5
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_PreviewManager
private SCR_PreviewEntityEditorComponent m_PreviewManager
Definition: SCR_CursorEditorUIComponent.c:22
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
EPreviewEntityFlag
EPreviewEntityFlag
Definition: EPreviewEntityFlag.c:1
ENotification
ENotification
Definition: ENotification.c:4
EEditorTransformVertical
EEditorTransformVertical
Vertical transformation mode.
Definition: EEditorTransformVertical.c:5
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
SCR_TransformingEditorComponent
Definition: SCR_TransformingEditorComponent.c:33
Attribute
typedef Attribute
Post-process effect of scripted camera.
SendNotification
protected void SendNotification(int msgId, notnull IEntity user, int assetId=-1, int catalogType=-1)
Definition: SCR_CatalogEntitySpawnerComponent.c:819
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_TransformingEditorComponentClass
Definition: SCR_TransformingEditorComponent.c:2
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
SCR_SiteSlotEntity
Definition: SCR_SiteSlotEntity.c:26
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_StatesEditorComponent
Definition: SCR_StatesEditorComponent.c:9
SCR_RefPreviewEntity
Definition: SCR_RefPreviewEntity.c:10
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SCR_EditorPreviewParams
Network packet of variables for entity placing and transformation.
Definition: SCR_EditorPreviewParams.c:4
SCR_BaseEditorEffect
Definition: SCR_BaseEditorEffect.c:7
SCR_PreviewEntityEditorComponent
Definition: SCR_PreviewEntityEditorComponent.c:12
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180