Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CompositionValidationEntity.c
Go to the documentation of this file.
1//#define DEBUG_SHAPE
2[EntityEditorProps(category: "GameScripted/Editor", description: "Core Editor manager", color: "251 91 0 255", dynamicBox: true)]
6
7class SCR_CompositionValidationEntity : SCR_GenericBoxEntity
8{
9 [Attribute(category: "Slot")]
10 private vector m_vSlotSize;
11
12 [Attribute(category: "Slot")]
13 private bool m_bIsRectangle;
14
15 [Attribute(defvalue: "0.1")]
16 private float m_fRefreshRate;
17
18#ifdef WORKBENCH
19 private bool m_bCompositionSearched;
20 private IEntitySource m_CompositionSource;
21 private float m_fTime;
22 private ref DebugTextScreenSpace m_Title;
23 private ref DebugTextScreenSpace m_Text;
24#ifdef DEBUG_SHAPE
25 private ref Shape m_Shape;
26#endif
27
28 //------------------------------------------------------------------------------------------------
29 protected bool InArea(vector pos)
30 {
31 pos = CoordToLocal(pos);
32 float sizeX = m_vSlotSize[0];
33 float sizeY = m_vSlotSize[1];
34 float sizeZ = m_vSlotSize[2];
35
36 if (m_bIsRectangle)
37 {
38 return (pos[0] > -sizeX && pos[0] < sizeX) && (pos[2] > -sizeZ && pos[2] < sizeZ);
39 }
40 else
41 {
42 return Vector(pos[0], 0, pos[2]).Length() < sizeX;
43 }
44 }
45
46 //------------------------------------------------------------------------------------------------
47 protected bool FindComposition()
48 {
49 if (m_bCompositionSearched)
50 {
51 if (m_CompositionSource)
52 return true;
53 else
54 return false;
55 }
56
57 m_bCompositionSearched = true;
58
59 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
60 if (!worldEditor)
61 return false;
62
63 WorldEditorAPI worldEditorAPI = worldEditor.GetApi();
64 if (!worldEditorAPI)
65 return false;
66
67 for (int i = 0, containersCount = worldEditor.GetNumContainers(); i < containersCount; i++)
68 {
69 IEntitySource entitySource = IEntitySource.Cast(worldEditor.GetContainer(i));
70 if (!entitySource || entitySource.GetSubScene() != worldEditorAPI.GetCurrentSubScene() || entitySource.GetLayerID() != worldEditorAPI.GetCurrentEntityLayerId())
71 continue;
72
73 //--- Get composition prefab
74 m_CompositionSource = entitySource;
75 break;
76 }
77
78 if (!m_CompositionSource)
79 {
80 Print("Cannot find the composition, no entities are present in the current layer.", LogLevel.WARNING);
81 return false;
82 }
83
84 m_Title.SetText(m_CompositionSource.GetResourceName());
85
86 return true;
87 }
88
89 //------------------------------------------------------------------------------------------------
90 protected void ProcessEntities(IEntitySource entitySource, out int count)
91 {
92 IEntitySource childSource;
93 IEntity child;
94 vector boundMin, boundMax;
95 vector boundPoints[8];
96 WorldEditorAPI worldEditorAPI = ((WorldEditor)Workbench.GetModule(WorldEditor)).GetApi();
97 for (int i = 0, countChildren = entitySource.GetNumChildren(); i < countChildren; i++)
98 {
99 childSource = entitySource.GetChild(i);
100 child = worldEditorAPI.SourceToEntity(childSource);
101 if (!child)
102 continue;
103
104 //--- Check if it's inside slot area
105 child.GetBounds(boundMin, boundMax);
106 if (!InArea(child.CoordToParent(Vector(boundMin[0], boundMin[1], boundMin[2])))
107 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMin[1], boundMin[2])))
108 || !InArea(child.CoordToParent(Vector(boundMin[0], boundMax[1], boundMin[2])))
109 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMax[1], boundMin[2])))
110 || !InArea(child.CoordToParent(Vector(boundMin[0], boundMin[1], boundMax[2])))
111 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMin[1], boundMax[2])))
112 || !InArea(child.CoordToParent(Vector(boundMin[0], boundMax[1], boundMax[2])))
113 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMax[1], boundMax[2])))
114 )
115 {
116 vector pos = child.GetOrigin();
117 DebugTextWorldSpace.Create(GetWorld(), "!", DebugTextFlags.FACE_CAMERA | DebugTextFlags.CENTER | DebugTextFlags.ONCE, pos[0], pos[1], pos[2], 30, Color.WHITE, Color.RED);
118 }
119
120 //--- Check if it has replication component
121 /*if (child.FindComponent(RplComponent))
122 {
123 vector pos = child.GetOrigin();
124 DebugTextWorldSpace.Create(GetWorld(), "Rpl", DebugTextFlags.FACE_CAMERA | DebugTextFlags.CENTER | DebugTextFlags.ONCE, pos[0], pos[1], pos[2], 10, Color.WHITE, Color.ORANGE);
125 }*/
126
127 //--- Increase counter and go deeper
128 count += 1;
129 ProcessEntities(childSource, count);
130 }
131 }
132
133 //------------------------------------------------------------------------------------------------
134 override int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
135 {
136 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
137 }
138
139 //------------------------------------------------------------------------------------------------
140 override void _WB_AfterWorldUpdate(float timeSlice)
141 {
142 if (!FindComposition())
143 return;
144
145 //--- Save performance by not refreshing every frame
146 if (m_fTime < m_fRefreshRate)
147 {
148 m_fTime += timeSlice;
149 return;
150 }
151
152 //Print(worldEditorAPI.GetSelectedEntity(0));
153
154 int count = 1;
155 ProcessEntities(m_CompositionSource, count);
156 m_Text.SetText(string.Format("Entities: %1", count));
157 }
158
159 //------------------------------------------------------------------------------------------------
160 // constructor
163 void SCR_CompositionValidationEntity(IEntitySource src, IEntity parent)
164 {
165 m_Title = DebugTextScreenSpace.Create(GetWorld(), "", DebugTextFlags.FACE_CAMERA, 10, 10, 20, ARGBF(1, 1, 1, 1), ARGBF(1, 0, 0, 0));
166 m_Text = DebugTextScreenSpace.Create(GetWorld(), "", DebugTextFlags.FACE_CAMERA, 10, 33, 14, ARGBF(1, 1, 1, 1), ARGBF(1, 0, 0, 0));
167
168#ifdef DEBUG_SHAPE
169 if (m_bIsRectangle)
170 m_Shape = Shape.Create(ShapeType.BBOX, ARGBF(0.1, 1, 1, 1), ShapeFlags.VISIBLE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE | ShapeFlags.ADDITIVE | ShapeFlags.DOUBLESIDE, GetOrigin() - m_vSlotSize, GetOrigin() + m_vSlotSize);
171 else
172 m_Shape = Shape.CreateCylinder(ARGBF(0.1, 1, 1, 1), ShapeFlags.VISIBLE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE | ShapeFlags.ADDITIVE | ShapeFlags.DOUBLESIDE, GetOrigin(), m_vSlotSize[0], m_vSlotSize[2]);
173#endif
174 }
175
176 //------------------------------------------------------------------------------------------------
177 // destructor
178 void ~SCR_CompositionValidationEntity()
179 {
180#ifdef DEBUG_SHAPE
181 delete m_Shape;
182#endif
183 }
184#endif
185}
vector GetOrigin()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
enum EVehicleType IEntity
event void _WB_AfterWorldUpdate(float timeSlice)
Called after updating world in Workbench. The entity must be visible in frustum, selected or named....
event int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
Called after _WB_OnInit or also later when editor needs to know whether _WB_AfterWorldUpdate needs to...
proto external vector GetOrigin()
proto external void GetBounds(out vector mins, out vector maxs)
proto external BaseWorld GetWorld()
proto external vector CoordToParent(vector coord)
proto external vector CoordToLocal(vector coord)
Instance of created debug visualizer.
Definition Shape.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ShapeType
Definition ShapeType.c:13
DebugTextFlags
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
proto native vector Vector(float x, float y, float z)
proto int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.