Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBuildingTransformingEditorComponent.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 
5 }
6 
10 class SCR_CampaignBuildingTransformingEditorComponent : SCR_TransformingEditorComponent
11 {
13  protected SCR_CampaignBuildingPlacingObstructionEditorComponent m_ObstructionComponent;
16 
17  //------------------------------------------------------------------------------------------------
19  {
20  m_PreviewEntity = previewEnt;
21  m_ObstructionComponent.OnPreviewCreated(m_PreviewEntity);
22  m_PreviewManager.GetOnPreviewCreate().Remove(OnPreviewCreated);
23  }
24 
25  //------------------------------------------------------------------------------------------------
27  {
28  m_PreviewManager.GetOnPreviewDelete().Remove(OnPreviewDeleted);
29  }
30  //------------------------------------------------------------------------------------------------
31  override void StartEditing(SCR_EditableEntityComponent pivot, notnull set<SCR_EditableEntityComponent> entities, vector transform[4])
32  {
33  if (!pivot || IsEditing(pivot) || m_LastRejectedPivot == pivot)
34  return;
35 
36  SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(pivot.GetOwner().FindComponent(SCR_CampaignBuildingCompositionComponent));
37  if (!compositionComponent)
38  return;
39 
40  if (compositionComponent.IsInteractionLocked())
41  {
42  SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_COMPOSITION_UNDER_CONSTRUCTION);
43  m_LastRejectedPivot = pivot;
44  return;
45  }
46 
47  m_LastRejectedPivot = null;
48 
49  m_PreviewManager.GetOnPreviewCreate().Insert(OnPreviewCreated);
50  m_PreviewManager.GetOnPreviewDelete().Insert(OnPreviewDeleted);
51 
52  super.StartEditing(pivot, entities, transform);
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
57  override void StartEditingServer(int pivotId, array<int> entityIds, vector dummyVector, vector transform[4], bool isUnderwater, EEditorTransformVertical verticalMode)
58  {
59  super.StartEditingServer(pivotId, entityIds, dummyVector, transform, isUnderwater, verticalMode);
60 
61  IEntity child = m_EditedPivot.GetOwner().GetChildren();
62  SCR_CampaignBuildingLayoutComponent layoutComponent;
63 
64  while (child && !layoutComponent)
65  {
66  layoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(child.FindComponent(SCR_CampaignBuildingLayoutComponent));
67 
68  if (!layoutComponent)
69  child = child.GetSibling();
70  }
71 
72  if (layoutComponent)
73  {
74  layoutComponent.LockCompositionInteraction();
75  layoutComponent.DeletePreview();
76  SCR_EntityHelper.DeleteEntityAndChildren(layoutComponent.GetOwner());
77  }
78  }
79 
80  //------------------------------------------------------------------------------------------------
81  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
82  override void StartEditingOwner()
83  {
84  if (!m_PreviewManager)
85  return;
86 
87  //--- Transforming was meanwhile canceled, ignore
88  if (!m_StatesManager.SetIsWaiting(false) || m_StatesManager.GetState() != EEditorState.TRANSFORMING)
89  {
90  CancelEditing();
91  return;
92  }
93 
94  IEntity owner = m_EditedPivot.GetOwner();
95  if (!owner)
96  return;
97 
98  vector transform[4];
99  owner.GetWorldTransform(transform);
100 
101  array<vector> offsets = {};
102  ResourceName resName = owner.GetPrefabData().GetPrefabName();
103  //--- Create preview
104  SCR_BasePreviewEntity previewEntity = m_PreviewManager.CreatePreview(resName, offsets, transform);
105 
106  Event_OnTransformationStart.Invoke(m_aEditedEntities);
107 
108  SCR_TransformingEditorComponentClass prefabData = SCR_TransformingEditorComponentClass.Cast(GetEditorComponentData());
109  if (prefabData)
110  SCR_BaseEditorEffect.Activate(prefabData.GetEffectsTransforationStart(), this, entities: m_aEditedEntities);
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override void EOnEditorActivate()
115  {
116  super.EOnEditorActivate();
117 
119  GetOnTransformationConfirm().Insert(IsInBuildingRadius);
120 
121  m_ObstructionComponent = SCR_CampaignBuildingPlacingObstructionEditorComponent.Cast(FindEditorComponent(SCR_CampaignBuildingPlacingObstructionEditorComponent, true, true));
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  override void EOnEditorDeactivate()
126  {
127  super.EOnEditorDeactivate();
128  GetOnTransformationConfirm().Remove(IsInBuildingRadius);
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  bool IsInBuildingRadius(set<SCR_EditableEntityComponent> editedEntities)
133  {
134  if (editedEntities.IsEmpty())
135  return false;
136 
137  return (IsInBuildingRadiusVector(editedEntities[0].GetOwner().GetOrigin()));
138  }
139 
140  //------------------------------------------------------------------------------------------------
142  bool IsInBuildingRadiusVector(vector previewOrigin)
143  {
144  SCR_CampaignBuildingEditorComponent editorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent, true));
145  if (!editorComponent)
146  return false;
147 
148  SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(editorComponent.GetProviderComponent());
149  if (!providerComponent)
150  return false;
151 
152  if (vector.Distance(previewOrigin, providerComponent.GetOwner().GetOrigin()) > providerComponent.GetBuildingRadius())
153  return false;
154  return true;
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  override bool ConfirmEditing()
159  {
160  vector transform[4];
161  m_PreviewManager.GetPreviewTransform(transform);
162 
163  if (!m_ObstructionComponent.CanCreate() || !IsInBuildingRadiusVector(transform[3]))
164  {
165  CancelEditing();
166  return false;
167  }
168 
169  super.ConfirmEditing();
170 
171  return true;
172  }
173 
174  //------------------------------------------------------------------------------------------------
177  {
178  m_LastRejectedPivot = null;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
184  {
185  IEntity composition = m_EditedPivot.GetOwner();
186 
187  super.ConfirmEditingServer(params);
188 
189  SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(composition.FindComponent(SCR_CampaignBuildingCompositionComponent));
190  if (!compositionComponent)
191  return;
192 
193  // m_EditedPivot can't be used as it's set to null after super. is called. However this code can't be call before.
194  SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(composition.FindComponent(SCR_EditableEntityComponent));
195  if (!editableEntity)
196  return;
197 
198  compositionComponent.SpawnCompositionLayout(compositionComponent.GetPrefabId(), editableEntity);
199  compositionComponent.SetInteractionLockServer(false);
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
204  override void CancelEditingServer()
205  {
206  SCR_CampaignBuildingLayoutComponent layoutComponent;
207 
208  if (m_EditedPivot)
209  {
210  IEntity composition = m_EditedPivot.GetOwner();
211  SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(composition.FindComponent(SCR_CampaignBuildingCompositionComponent));
212  if (!compositionComponent)
213  return;
214 
215  compositionComponent.SpawnCompositionLayout(compositionComponent.GetPrefabId(), m_EditedPivot);
216  compositionComponent.SetInteractionLockServer(false);
217  }
218 
219  super.CancelEditingServer();
220  }
221 }
m_ObstructionComponent
protected SCR_CampaignBuildingPlacingObstructionEditorComponent m_ObstructionComponent
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:13
OnPreviewCreated
void OnPreviewCreated(SCR_EditablePreviewEntity previewEnt)
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:18
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EOnEditorActivate
override void EOnEditorActivate()
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:114
SCR_CampaignBuildingTransformingEditorComponentClass
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:2
IsInBuildingRadiusVector
bool IsInBuildingRadiusVector(vector previewOrigin)
Test if the composition is moved out of the building mode and if so, deny the transfer.
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:142
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
ConfirmEditingServer
override void ConfirmEditingServer(SCR_EditorPreviewParams params)
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:183
m_StatesManager
private SCR_StatesEditorComponent m_StatesManager
Definition: SCR_AttributesManagerEditorComponent.c:65
SCR_EditablePreviewEntity
Definition: SCR_EditablePreviewEntity.c:8
CancelEditingServer
override void CancelEditingServer()
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:204
EEditorState
EEditorState
Unique editor state.
Definition: EEditorState.c:5
m_LastRejectedPivot
SCR_CampaignBuildingTransformingEditorComponentClass m_LastRejectedPivot
m_PreviewManager
private SCR_PreviewEntityEditorComponent m_PreviewManager
Definition: SCR_CursorEditorUIComponent.c:22
SCR_BasePreviewEntity
Definition: SCR_BasePreviewEntity.c:9
EOnEditorDeactivate
override void EOnEditorDeactivate()
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:125
StartEditing
override void StartEditing(SCR_EditableEntityComponent pivot, notnull set< SCR_EditableEntityComponent > entities, vector transform[4])
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:31
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
ENotification
ENotification
Definition: ENotification.c:4
EEditorTransformVertical
EEditorTransformVertical
Vertical transformation mode.
Definition: EEditorTransformVertical.c:5
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
SCR_TransformingEditorComponent
Definition: SCR_TransformingEditorComponent.c:33
StartEditingOwner
override void StartEditingOwner()
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:82
m_PreviewEntity
protected SCR_EditablePreviewEntity m_PreviewEntity
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:14
OnPreviewDeleted
void OnPreviewDeleted()
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:26
m_PreviewEntityEditorComponent
protected SCR_PreviewEntityEditorComponent m_PreviewEntityEditorComponent
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:15
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_TransformingEditorComponentClass
Definition: SCR_TransformingEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
StartEditingServer
override void StartEditingServer(int pivotId, array< int > entityIds, vector dummyVector, vector transform[4], bool isUnderwater, EEditorTransformVertical verticalMode)
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:57
IsInBuildingRadius
bool IsInBuildingRadius(set< SCR_EditableEntityComponent > editedEntities)
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:132
ReleaseLastRejectedPivot
void ReleaseLastRejectedPivot()
The variable has to be set to null if the editing was blocked because of the temporary move of the co...
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:176
CancelEditing
void CancelEditing()
Definition: SCR_AttributesManagerEditorComponent.c:417
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
ConfirmEditing
override bool ConfirmEditing()
Definition: SCR_CampaignBuildingTransformingEditorComponent.c:158
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