Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SlotCompositionComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "")]
3{
4 [Attribute(params: "et", category: "Composition", desc: "Slot this composition fits into.")]
6
7 [Attribute(defvalue: "1", category: "Composition", desc: "When enabled, children will be snapped and oriented to terrain when the composition is transformed.")]
9
10 [Attribute(defvalue: "1", category: "Composition", desc: "When enabled, children will not be turned into editable entities. The composition will appear as a single entity in in-game editor.")]
11 protected bool m_bEditableChildren; //--- Not read in the script, but accessed by EditablePrefabsConfig when generating editable prefabs
12
13 //------------------------------------------------------------------------------------------------
16 {
17 return m_SlotPrefab;
18 }
19
20 //------------------------------------------------------------------------------------------------
27
28 //------------------------------------------------------------------------------------------------
34 {
35 ResourceName slotPrefab;
36 componentSource.Get("m_SlotPrefab", slotPrefab);
37 return slotPrefab;
38 }
39};
40
42
45{
47 protected static bool m_bIgnoreOrientChildrenToTerrain;
48
49 //------------------------------------------------------------------------------------------------
53 {
55 if (prefabData)
56 return prefabData.GetSlotPrefab();
57 else
58 return ResourceName.Empty;
59 }
60
61 //------------------------------------------------------------------------------------------------
65 {
67 if (prefabData)
68 return prefabData.CanOrientChildrenToTerrain();
69 else
70 return false;
71 }
72
73 //------------------------------------------------------------------------------------------------
79
80 //------------------------------------------------------------------------------------------------
84 {
85 //--- Don't initialize child compositions (they will be initialized as part of parent's init)
86 if (!CanOrientChildrenToTerrain() || m_Owner.GetParent())
87 return;
88
89 BaseWorld world = m_Owner.GetWorld();
91 m_Owner.Update();
92 }
93
94 //------------------------------------------------------------------------------------------------
95 protected void SetChildTransform(IEntity owner, BaseWorld world)
96 {
97 //--- Find entity's height
98 float height = 0;
99 if (owner.GetParent())
100 {
101 //--- Use original local height (used only during initial transformation)
102 height = owner.GetLocalTransformAxis(3)[1];
103 }
104 else
105 {
106 //--- Maintain existing height ATL
107 height = SCR_TerrainHelper.GetHeightAboveTerrain(owner.GetOrigin(), world);
108 }
109
110 //--- Apply transformation
111 vector transform[4];
112 owner.GetWorldTransform(transform);
113 if (owner == m_Owner)
114 SCR_TerrainHelper.SnapToTerrain(transform, world); //--- Don't rotate root entity. Its transformation is broadcasted to clients, who would then think the rotated state is default
115 else
117
118 transform[3] = transform[3] + Vector(0, height, 0);
119
120 //If entity should be horizontally aligned rather then aligned to terrain
121 SCR_HorizontalAlignComponent horizontalAlignComponent = SCR_HorizontalAlignComponent.Cast(owner.FindComponent(SCR_HorizontalAlignComponent));
122 if (horizontalAlignComponent)
123 {
124 vector angles = Math3D.MatrixToAngles(transform);
125 angles[1] = 0;
126 angles[2] = 0;
127 Math3D.AnglesToMatrix(angles, transform);
128 }
129
130#ifdef WORKBENCH
131 //--- When in World Editor, apply changes to attributes directly
132 if (SCR_Global.IsEditMode(owner))
133 {
135 IEntity parent = owner.GetParent();
136 vector pos = transform[3];
137 if (parent)
138 {
139 vector parentTransform[3];
140 parent.GetWorldTransform(parentTransform);
141 Math3D.MatrixInvMultiply3(parentTransform, transform, transform);
142 pos = parent.CoordToLocal(pos);
143 }
144 vector angles = Math3D.MatrixToAngles(transform);
145 IEntitySource ownerSrc = api.EntityToSource(owner);
146 api.SetVariableValue(ownerSrc, null, "coords", pos.ToString(false));
147 api.SetVariableValue(ownerSrc, null, "angles", string.Format("%1 %2 %3", angles[1], angles[0], angles[2]));
148 }
149 else
150 {
151 owner.SetWorldTransform(transform);
152 }
153#else
154 owner.SetWorldTransform(transform);
155#endif
156
157 //--- Process children recursively
159 if (composition && composition.CanOrientChildrenToTerrain())
160 {
161 IEntity child = owner.GetChildren();
162 while (child)
163 {
164 SetChildTransform(child, world);
165 child = child.GetSibling();
166 }
167 }
168 }
169
170 //------------------------------------------------------------------------------------------------
171 override void EOnInit(IEntity owner)
172 {
173 if (SCR_Global.IsEditMode(owner))
174 return;
175
177 {
179 return;
180 }
181
182 //--- Initialize transform on every machine (ToDo: Remove SCR_EditableEntityComponent check; rather, have editable entities suppress this functionality)
185 }
186
187 //------------------------------------------------------------------------------------------------
188 override void OnPostInit(IEntity owner)
189 {
190 m_Owner = GenericEntity.Cast(owner);
191
192 SetEventMask(owner, EntityEvent.INIT);
193 }
194
195#ifdef WORKBENCH
196 //------------------------------------------------------------------------------------------------
203 static bool _WB_ConfigureComposition(WorldEditorAPI api, IEntitySource entitySource, bool isRoot = true, bool delayed = false)
204 {
205 //--- Skip sub-compositions
206 if (!isRoot && SCR_BaseContainerTools.FindComponentSource(entitySource, SCR_SlotCompositionComponent))
207 return false;
208
209 bool isChange;
210 IEntityComponentSource hierarchySource = SCR_BaseContainerTools.FindComponentSource(entitySource, "Hierarchy");
211 if (hierarchySource)
212 {
213 //--- Has hierarchy, make sure it's enabled
214 hierarchySource.Set("Enabled", true);
215 }
216 else
217 {
218 //--- Doesn't have hierarchy, add one
219 isChange = true;
220 if (delayed)
221 SCR_SlotCompositionHelperEntity.CreateHierarchy(api, entitySource);
222 else
223 api.CreateComponent(entitySource, "Hierarchy");
224 }
225
226 //--- Process children recursively
227 for (int i = 0, count = entitySource.GetNumChildren(); i < count; i++)
228 {
229 isChange |= _WB_ConfigureComposition(api, entitySource.GetChild(i), false);
230 }
231
232 return isChange;
233 }
234
235 //------------------------------------------------------------------------------------------------
236 override array<ref WB_UIMenuItem> _WB_GetContextMenuItems(IEntity owner)
237 {
238 return {
239 new WB_UIMenuItem("Configure composition", 0),
240 new WB_UIMenuItem("Orient to terrain", 1)
241 };
242 }
243
244 //------------------------------------------------------------------------------------------------
245 override void _WB_OnContextMenu(IEntity owner, int id)
246 {
247 WorldEditorAPI api = GenericEntity.Cast(owner)._WB_GetEditorAPI();
248 switch (id)
249 {
250 case 0:
251
252 //--- Gen entity instance
253 IEntitySource entitySource = api.EntityToSource(owner);
254 if (!entitySource) break;
255
256 //--- Get entity prefab
257 entitySource = entitySource.GetAncestor();
258 if (!entitySource) break;
259
260 //--- Process the prefab
261 api.BeginEntityAction();
262 _WB_ConfigureComposition(api, entitySource, true, true);
263 api.EndEntityAction();
264 break;
265 case 1:
266 api.BeginEntityAction();
268 api.EndEntityAction();
269 break;
270 }
271 }
272#endif
273}
274
275#ifdef WORKBENCH
276//--- Adding a component from inside a context action causes error, this is a hotfix
277class SCR_SlotCompositionHelperEntityClass : GenericEntityClass {}
278class SCR_SlotCompositionHelperEntity : GenericEntity
279{
280 protected IEntitySource m_EntitySource;
281
282 //------------------------------------------------------------------------------------------------
286 static void CreateHierarchy(WorldEditorAPI api, IEntitySource entitySource)
287 {
288 IEntitySource src = api.CreateEntity("SCR_SlotCompositionHelperEntity", "SCR_SlotCompositionHelperEntity", 0, null, vector.Zero, vector.Zero);
289 SCR_SlotCompositionHelperEntity helper = SCR_SlotCompositionHelperEntity.Cast(api.SourceToEntity(src));
290 helper.m_EntitySource = src;
291 }
292
293//------------------------------------------------------------------------------------------------
294 override int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
295 {
296 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
297 }
298
299 //------------------------------------------------------------------------------------------------
300 override void _WB_AfterWorldUpdate(float timeSlice)
301 {
302 if (!m_EntitySource)
303 return;
304
305 WorldEditorAPI api = _WB_GetEditorAPI();
306 api.BeginEntityAction();
307 api.CreateComponent(m_EntitySource, "Hierarchy");
308 api.DeleteEntity(m_EntitySource);
309 api.EndEntityAction();
310 }
311}
312#endif
ref array< string > angles
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_CharacterSoundComponentClass GetComponentData()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
proto external int SetEventMask(notnull IEntity owner, int mask)
event void _WB_OnContextMenu(IEntity owner, int id)
User has chosen any of your menu item from editor's "Component" menu which you have recently provided...
event array< ref WB_UIMenuItem > _WB_GetContextMenuItems(IEntity owner)
An opportunity to append items into editor's "Component" context menu. Do not call editor API here!
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
proto external vector GetLocalTransformAxis(int axis)
See IEntity::GetTransformAxis.
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external IEntity GetChildren()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external bool SetWorldTransform(vector mat[4])
See IEntity::SetTransform. Returns false, if there is no change in transformation.
proto external IEntity GetParent()
proto external IEntity GetSibling()
proto external vector CoordToLocal(vector coord)
static bool IsEditMode()
Definition Functions.c:1566
static ResourceName GetSlotPrefab(IEntityComponentSource componentSource)
Entity composition which is supposed to fit into a slot.
void SetChildTransform(IEntity owner, BaseWorld world)
override void OnPostInit(IEntity owner)
static void IgnoreOrientChildrenToTerrain()
Bool to disable the terrain snapping for next spawned composition.
static float GetHeightAboveTerrain(vector pos, BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
static bool SnapToTerrain(out vector transform[4], BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
static bool SnapAndOrientToTerrain(out vector transform[4], BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto native vector Vector(float x, float y, float z)