Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RefPreviewEntity.c
Go to the documentation of this file.
1//#define PREVIEW_ENTITY_SHOW_REFERENCE //--- Don't delete reference entity after transformation ended, to show how it looked like.
2
3[EntityEditorProps(category: "GameScripted/Preview", description: "")]
7
9class SCR_RefPreviewEntity: SCR_EditablePreviewEntity
10{
11 protected ref set<SCR_EditableEntityComponent> m_aEditedEntities;
12 protected bool m_bIsInstant;
13
14 //------------------------------------------------------------------------------------------------
18 static void SpawnAndApplyReference(SCR_EditableEntityComponent entity, SCR_EditorPreviewParams param)
19 {
20#ifdef PREVIEW_ENTITY_SHOW_REFERENCE
21 const ResourceName material = "{D0126AF0E6A27141}Common/Materials/Colors/colorRed.emat";
22#else
23 const ResourceName material;
24#endif
25 EPreviewEntityFlag flags = EPreviewEntityFlag.IGNORE_TERRAIN | EPreviewEntityFlag.IGNORE_PREFAB | EPreviewEntityFlag.ONLY_EDITABLE;
26
27 SCR_RefPreviewEntity refEntity = SCR_RefPreviewEntity.Cast(SCR_RefPreviewEntity.SpawnPreviewFromEditableEntity(entity, "SCR_RefPreviewEntity", GetGame().GetWorld(), null, material, flags));
28 if (!refEntity)
29 {
30 Print("SCR_RefPreviewEntity:: refEntity was not spawned!", LogLevel.WARNING);
31 return;
32 }
33
34 refEntity.m_EditableEntity = entity;
35 refEntity.SetAsInstant();
36 refEntity.ApplyReference(param);
37
38#ifndef PREVIEW_ENTITY_SHOW_REFERENCE
39 delete refEntity;
40#endif
41 }
42
43 //------------------------------------------------------------------------------------------------
47 {
48 //--- Get navmesh rebuild areas *BEFORE* the change
49 SCR_AIWorld aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
50 array<ref Tuple2<vector, vector>> areas = {}; //--- Min, max
51 array<bool> redoAreas = {};
52 if (aiWorld)
53 {
54 foreach (SCR_BasePreviewEntity child: m_aChildren)
55 {
56 if (child.m_Entity)
57 aiWorld.GetNavmeshRebuildAreas(child.m_Entity, areas, redoAreas);
58 }
59 }
60
61 //--- Update reference (ToDo: Do it only when needed)
62 vector transform[4];
63 param.GetWorldTransform(transform);
64 UpdateReference(transform, param.m_VerticalMode, param.m_bIsUnderwater);
65
66 //--- Apply changes on all children, and get navmesh areas *AFTER* the change
67 SCR_RefPreviewEntity childRef;
68 if (aiWorld)
69 {
70 if (m_aChildren)
71 {
72 foreach (SCR_BasePreviewEntity child: m_aChildren)
73 {
74 childRef = SCR_RefPreviewEntity.Cast(child);
75 if (childRef)
76 {
77 childRef.ApplyChild(param, true, m_aEditedEntities, m_bIsInstant);
78 if (child.m_Entity)
79 aiWorld.GetNavmeshRebuildAreas(child.m_Entity, areas, redoAreas);
80 }
81 }
82 }
83 aiWorld.RequestNavmeshRebuildAreas(areas, redoAreas);
84 }
85 else
86 {
87 if (m_aChildren)
88 {
89 foreach (SCR_BasePreviewEntity child: m_aChildren)
90 {
91 childRef = SCR_RefPreviewEntity.Cast(child);
92 if (childRef)
93 childRef.ApplyChild(param, true, m_aEditedEntities, m_bIsInstant);
94 }
95 }
96 }
97 }
98
99 //------------------------------------------------------------------------------------------------
102 {
103 m_bIsInstant = true;
104 }
105
106 //------------------------------------------------------------------------------------------------
107 protected bool ApplyChild(SCR_EditorPreviewParams param, bool isDirectChild, set<SCR_EditableEntityComponent> editedEntities, bool isInstant)
108 {
109 if (!m_EditableEntity)
110 return false;
111
112 vector transform[4];
113 GetWorldTransform(transform);
114
115 bool changeTransformation = true;
116 if (isDirectChild)
117 {
118 SCR_EditableEntityComponent currentParent = m_EditableEntity.GetParentEntity();
120 bool changeParent = false;
121
122 if (param.m_Target && (param.m_TargetInteraction == EEditableEntityInteraction.LAYER || param.m_TargetInteraction == EEditableEntityInteraction.PASSENGER))
123 {
124 //--- Hovering over target layer
125 newParent = param.m_Target;
126 changeParent = true;
127 changeTransformation = false;
128 }
129 else if (param.m_Parent != currentParent && param.m_Parent != m_EditableEntity && (param.m_bParentChanged || !currentParent || !currentParent.HasEntityFlag(EEditableEntityFlag.INDIVIDUAL_CHILDREN)))
130 {
131 //--- Entered target layer (and the target is not the entity itself)
132 newParent = param.m_Parent;
133 changeParent = true;
134 }
135 if (changeParent)
136 {
137 //--- Don't change parent of group members when their group is also being edited
138 SCR_EditableEntityComponent editableGroup = m_EditableEntity.GetAIGroup();
139 if (m_EditableEntity == editableGroup || !editableGroup || editedEntities.Find(editableGroup) == -1)
140 {
141 //--- Set the parent, and update the reference so all other entities use it as well (in case it changed, like when moving character to root)
142 param.m_Parent = m_EditableEntity.SetParentEntity(newParent, true);
143 }
144 }
145 }
146
147 if (changeTransformation)
148 {
149 //--- Don't transform vehicle crew when the vehicle is also being edited
150 SCR_EditableEntityComponent editableVehicle = m_EditableEntity.GetVehicle();
151 if (!editableVehicle || editedEntities.Find(editableVehicle) == -1)
152 {
153 if (isInstant)
154 {
155 vector localPos = m_EditableEntity.GetOwner().CoordToLocal(transform[3]);
156 localPos -= m_EditableEntity.GetIconPos();
157 transform[3] = m_EditableEntity.GetOwner().CoordToParent(localPos);
158 }
159
160 if (!m_EditableEntity.SetTransform(transform, isDirectChild && !isInstant))
161 return false;
162 }
163
164 if (m_aChildren)
165 {
166 SCR_RefPreviewEntity childRef;
167 foreach (SCR_BasePreviewEntity child: m_aChildren)
168 {
169 childRef = SCR_RefPreviewEntity.Cast(child);
170 if (childRef)
171 childRef.ApplyChild(param, false, editedEntities, isInstant);
172 }
173 }
174 }
175
176 return true;
177 }
178
179 //------------------------------------------------------------------------------------------------
180 protected void UpdateReference(vector transform[4], EEditorTransformVertical verticalMode, bool isUnderwater)
181 {
182 TraceParam trace;
183 if (verticalMode == EEditorTransformVertical.GEOMETRY)
184 {
185 trace = new TraceParam();
186 trace.ExcludeArray = m_aExcludeArray;
187 }
188
189 float currentHeight;
190 if (!SCR_Enum.HasFlag(m_Flags, EPreviewEntityFlag.IGNORE_TERRAIN))
191 {
192 vector currentPos = GetWorldTransformAxis(3);
193 currentHeight = currentPos[1] - SCR_TerrainHelper.GetTerrainY(currentPos, GetWorld(), !SCR_Enum.HasFlag(m_Flags, EPreviewEntityFlag.UNDERWATER), trace);
194 }
195
196 float terrainY = SCR_TerrainHelper.GetTerrainY(transform[3], GetWorld(), !isUnderwater, trace);
197 float height = transform[3][1] - terrainY;
198
199 m_fHeightTerrain = 0;
200 SetPreviewTransform(transform, verticalMode, height - currentHeight, isUnderwater, trace);
201 }
202
203 //------------------------------------------------------------------------------------------------
204 override protected void EOnPreviewInit(SCR_BasePreviewEntry entry, SCR_BasePreviewEntity root)
205 {
206 super.EOnPreviewInit(entry, root);
207
208 SCR_RefPreviewEntity refRoot = SCR_RefPreviewEntity.Cast(root);
209 if (refRoot)
210 {
211 if (!refRoot.m_aEditedEntities)
212 refRoot.m_aEditedEntities = new set<SCR_EditableEntityComponent>();
213
214 refRoot.m_aEditedEntities.Insert(m_EditableEntity);
215 }
216 }
217}
SCR_EAIThreatSectorFlags flags
EPreviewEntityFlag
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void ApplyReference(SCR_EditorPreviewParams param)
SCR_RefPreviewEntityClass m_aEditedEntities
Reference entity used to position edited entities according to preview.
bool ApplyChild(SCR_EditorPreviewParams param, bool isDirectChild, set< SCR_EditableEntityComponent > editedEntities, bool isInstant)
void EOnPreviewInit(SCR_BasePreviewEntry entry, SCR_BasePreviewEntity root)
bool m_bIsInstant
void UpdateReference(vector transform[4], EEditorTransformVertical verticalMode, bool isUnderwater)
void SetAsInstant()
Mark the reference entity as applied at the same time as it's created.
ref array< SCR_ScenarioFrameworkLayerBase > m_aChildren
void GetNavmeshRebuildAreas(IEntity entity, out notnull array< ref Tuple2< vector, vector > > outAreas, out notnull array< bool > redoRoads)
void RequestNavmeshRebuildAreas(notnull array< ref Tuple2< vector, vector > > areas, notnull array< bool > redoRoads)
bool HasEntityFlag(EEditableEntityFlag flag)
SCR_EditableEntityComponent GetVehicle()
SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser=false)
SCR_EditableEntityComponent GetParentEntity()
SCR_EditableEntityComponent GetAIGroup()
Network packet of variables for entity placing and transformation.
void GetWorldTransform(out vector outTransform[4])
static float GetTerrainY(vector pos, BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EEditableEntityFlag
Unique flags of the entity.
EEditorTransformVertical
Vertical transformation mode.
EEditableEntityInteraction
Type of suggested interaction when hovering edited entity on top of another entity.