Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EntitiesEditorUIComponent.c
Go to the documentation of this file.
2{
3 [Attribute()]
4 protected ref array<ref SCR_BaseEntitiesEditorUIEffect> m_aEffects;
5
6 [Attribute()]
7 protected ref array<ref SCR_EditableEntityUISlotSize> m_aSlotSizes;
8
9 [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
21
23 //--- Registration
24 ////////////////////////////////////////////////////////////////////////////////////////////////
25
26 //------------------------------------------------------------------------------------------------
28 {
29 SCR_EditableEntityBaseSlotUIComponent slot = super.FindSlot(entity, createIfNull);
30 if (slot || !createIfNull)
31 return slot;
32
33 //--- Create slot from prefab
35 Widget slotWidget = GetGame().GetWorkspace().CreateWidgets(m_SlotPrefab, GetWidget());
36 if (slotWidget)
37 {
39 }
40
41 //--- No prefab found, create object directly
42 if (!sceneSlot)
43 {
44 if (slotWidget)
45 slotWidget.RemoveFromHierarchy();
46
47 slotWidget = GetGame().GetWorkspace().CreateWidget(WidgetType.FrameWidgetTypeID, WidgetFlags.VISIBLE, new Color(1, 1, 1, 1), 0, GetWidget());
49 slotWidget.AddHandler(sceneSlot);
50 }
51 slot = sceneSlot;
52
53 //--- Set slot size
54 int slotSize = -1;
55 EEditableEntityType entityType = entity.GetEntityType();
56 foreach (SCR_EditableEntityUISlotSize slotSizeStruct: m_aSlotSizes)
57 {
58 if (slotSizeStruct.GetType() == entityType)
59 {
60 slotSize = slotSizeStruct.GetSize();
61 break;
62 }
63 else if (slotSizeStruct.GetType() == EEditableEntityType.GENERIC)
64 {
65 slotSize = slotSizeStruct.GetSize();
66 }
67 }
68
69 if (slotSize != -1)
70 FrameSlot.SetSize(slotWidget, slotSize, slotSize);
71
72 InsertSlot(entity, slot);
73 ApplyAutoEffect(entity, sceneSlot);
74
75 //--- Add existing dependent icons
77 {
78 if (ruleTracker.GetRule().IsDependent())
79 ruleTracker.AddEntity(entity);
80 }
81
82 return slot;
83 }
84
85 //------------------------------------------------------------------------------------------------
86 override bool DeleteSlot(SCR_EditableEntityComponent entity, bool forced = false)
87 {
88 bool deleted = super.DeleteSlot(entity, forced);
89 if (deleted && entity == m_EntityUnderCursor)
91
92 return deleted;
93 }
94
96 //--- Mouse interaction
97 ////////////////////////////////////////////////////////////////////////////////////////////////
98
99 //------------------------------------------------------------------------------------------------
100 override bool OnMouseEnter(Widget w, int x, int y)
101 {
103 if (entitySlot)
104 m_EntityUnderCursor = entitySlot.GetEntity();
105
106 return false;
108
109 //------------------------------------------------------------------------------------------------
110 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
111 {
113 if (entitySlot)
114 m_EntityUnderCursor = null;
115
116 return false;
118
119 //------------------------------------------------------------------------------------------------
120 protected void OnInputDeviceIsGamepad(bool isGamepad)
121 {
122 //--- Reset the value, otherwise it would linger on after switching from gamepad to mouse&keyboard
123 m_EntityUnderCursor = null;
125
126 //------------------------------------------------------------------------------------------------
127 protected void OnEffect(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
128 {
130 if (entitiesRemove)
131 {
132 foreach (SCR_EditableEntityComponent entity: entitiesRemove)
133 {
134 if (!m_mEntitySlots.Find(entity, slot))
135 continue;
136
137 ApplyAutoEffect(entity, slot);
138 }
139 }
140
141 if (entitiesInsert)
142 {
143 SCR_BaseEntitiesEditorUIEffect effect = null;
144 m_aEffectsMap.Find(state, effect);
145 if (!effect)
146 return;
147
148 foreach (SCR_EditableEntityComponent entity: entitiesInsert)
149 {
150 if (!m_mEntitySlots.Find(entity, slot))
151 continue;
152
153 effect.ApplyOn(slot.GetWidget());
154 }
155 }
156 }
157
158 //------------------------------------------------------------------------------------------------
159 //!
160 //! \param[in] entity
161 //! \param[in] slot
163 {
165 {
166 if (entity.HasEntityState(effectState))
167 {
168 effect.ApplyOn(slot.GetWidget());
169 break;
170 }
171 }
172 }
173
175 //--- Update
177
178 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
179 //------------------------------------------------------------------------------------------------
181 void OnMenuUpdate(float tDelta)
182 {
183 //--- No scene interaction when the map is opened
184 bool isMapOpen = m_MapEntity && m_MapEntity.IsOpen();
185 GetWidget().SetVisible(!isMapOpen);
186 if (isMapOpen)
187 return;
188
189 int screenW = m_Workspace.GetWidth();
190 int screenH = m_Workspace.GetHeight();
191 screenW = m_Workspace.DPIUnscale(screenW);
192 screenH = m_Workspace.DPIUnscale(screenH);
193 vector posCenter = Vector(screenW / 2, screenH / 2, 0);
194
195 vector transformCam[4];
196 GetGame().GetWorld().GetCurrentCamera(transformCam);
197 vector posCam = transformCam[3];
198
199 if (!m_bInteractive || !m_CursorComponent || (m_InputManager && m_InputManager.IsUsingMouseAndKeyboard()))
200 {
201 //--- Mouse & keyboard (or non-interactive)
203 {
204 //--- If it is an attached entity, position it only if the parent entity slot is not found
205 //--- An example of this is when it is attached to a character of a group, and the character slot gets hidden in the distance
207 if (entitySlot.GetEntity() && entitySlot.GetEntity().IsAttached() && entitySlot.GetEntity().GetAttachedTo() && m_mEntitySlots.Find(entitySlot.GetEntity().GetAttachedTo(), parentSlot))
208 continue;
209
210 vector position = entitySlot.UpdateSlot(screenW, screenH, posCenter, posCam);
211 PlaceAttachedSlots(entitySlot, position);
212 }
213 }
214 else
215 {
216 //--- Gamepad (check for icon distances)
217 float distanceSq;
218 float nearestDis = m_CursorComponent.GetCursorRadiusSq();
219 vector cursorPos = m_CursorComponent.GetCursorPos();
223 {
224 //--- If it is an attached entity, position it only if the parent entity slot is not found
225 //--- An example of this is when it is attached to a character of a group, and the character slot gets hidden in the distance
227 if (entitySlot.GetEntity() && entitySlot.GetEntity().IsAttached() && entitySlot.GetEntity().GetAttachedTo() && m_mEntitySlots.Find(entitySlot.GetEntity().GetAttachedTo(), parentSlot))
228 continue;
229
230 position = entitySlot.UpdateSlot(screenW, screenH, posCenter, posCam);
231 distanceSq = vector.DistanceSq(cursorPos, position);
232 if (distanceSq < nearestDis && !entitySlot.IsPreview()) //--- Ignore preview entity, it's snapped cursor and would block actual entities under cursor
233 {
234 nearestDis = distanceSq;
235 nearestSlot = entitySlot;
236 }
237
238 PlaceAttachedSlots(entitySlot, position);
239 }
240 if (nearestSlot)
241 m_EntityUnderCursor = nearestSlot.GetEntity();
242 else
243 m_EntityUnderCursor = null;
244 }
245
246 if (m_HoverManager && m_MouseArea.IsMouseOn())
247 m_HoverManager.SetEntityUnderCursor(m_EntityUnderCursor, true);
248 }
249 //---- REFACTOR NOTE END ----
250
251 //------------------------------------------------------------------------------------------------
253 //! \param[in] entitySlot is the child (current) slot
254 //! \param[in] vector position of current slot
255 //! \param[in] offset offset to add to each slot
256 protected void PlaceAttachedSlots(SCR_EditableEntityBaseSlotUIComponent entitySlot, vector position, float offset = 32)
257 {
258 SCR_EditableEntityComponent entity = entitySlot.GetEntity();
259 if (!entity)
260 return;
261
262 set<SCR_EditableEntityComponent> attached = entity.GetAttachedEntities();
263
264 foreach (int i, SCR_EditableEntityComponent attachment : attached)
265 {
266 if (!attachment || !attachment.IsAttached())
267 continue;
268
270 if (!m_mEntitySlots.Find(attachment, attachmentSlot))
271 continue;
272
273 FrameSlot.SetPos(attachmentSlot.GetWidget(), position[0], (position[1] - (i + 1) * offset));
274 }
276
277 //------------------------------------------------------------------------------------------------
278 protected void OnMenuFocusLost()
279 {
280 //--- When menu focus is lost, OnMenuUpdate is not called anymore. Keep it updating with low frequency.
281 GetGame().GetCallqueue().CallLater(OnMenuUpdate, 10, true, 0);
283
284 //------------------------------------------------------------------------------------------------
285 protected void OnMenuFocusGained()
286 {
287 GetGame().GetCallqueue().Remove(OnMenuUpdate);
288 }
289
291 //--- Default functions
292 ////////////////////////////////////////////////////////////////////////////////////////////////
293
294 //------------------------------------------------------------------------------------------------
296 {
298 return; //--- Run-time only
299
301 if (!entityManager)
302 return;
303
304 MenuRootBase menu = GetMenu();
305 if (!menu)
306 return;
307
308 menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
309 menu.GetOnMenuFocusLost().Insert(OnMenuFocusLost);
311
312 if (!menu.IsFocused())
314
315 m_Workspace = w.GetWorkspace();
316 if (!m_Workspace)
317 return;
318
319 m_InputManager = GetGame().GetInputManager();
321
322 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
323
324 MenuRootComponent root = GetRootComponent();
325 if (root)
326 {
329 }
330
331 //--- Init effects
333 {
334 EEditableEntityState state = effect.GetState();
335 if (state == 0)
336 continue;
337
338 SCR_BaseEditableEntityFilter stateManager = entityManager.GetFilter(state);
339 if (!stateManager)
340 continue;
341
342 stateManager.GetOnChanged().Insert(OnEffect);
343 m_aEffectsMap.Insert(state, effect);
344 }
345
347
348 super.HandlerAttachedScripted(w);
350
351 //------------------------------------------------------------------------------------------------
352 override void HandlerDeattached(Widget w)
353 {
354 super.HandlerDeattached(w);
356 return; //--- Run-time only
357
358 MenuRootBase menu = GetMenu();
359 if (menu)
360 {
361 menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
362 menu.GetOnMenuFocusLost().Remove(OnMenuFocusLost);
364 }
365
366 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
367
369 {
371 foreach (SCR_EntitiesEditorUIRule rule: m_EditableEntityUIConfig.GetRules())
372 {
373 if (m_RuleTrackers.Find(rule, ruleTracker))
374 delete ruleTracker;
375 }
376 }
378 if (entityManager)
379 {
381 {
382 EEditableEntityState state = effect.GetState();
383 if (state == 0)
384 continue;
385
386 SCR_BaseEditableEntityFilter stateManager = entityManager.GetFilter(state);
387 if (!stateManager)
388 continue;
389
390 if (stateManager && stateManager.GetOnChanged())
391 stateManager.GetOnChanged().Remove(OnEffect);
392 }
393 }
394 }
395}
396
398class SCR_EditableEntityUISlotSize
399{
400 [Attribute("0", UIWidgets.ComboBox, "Entity type.", enums: ParamEnumArray.FromEnum(EEditableEntityType))]
402
403 [Attribute("48")]
404 private int m_iSize;
405
406 //------------------------------------------------------------------------------------------------
409 {
410 return m_Type;
411 }
412
413 //------------------------------------------------------------------------------------------------
415 int GetSize()
416 {
417 return m_iSize;
418 }
419}
ArmaReforgerScripted GetGame()
Definition game.c:1398
override EGadgetType GetType()
vector position
SCR_EntitiesEditorUIComponent SCR_EditableEntitySlotManagerUIComponent BaseContainerProps()
SCR_EntitiesEditorUIComponent SCR_EditableEntitySlotManagerUIComponent SCR_BaseContainerCustomTitleEnum(EEditableEntityType, "m_Type")
EEditableEntityType m_Type
SCR_RadialMenu GetMenu()
Widget GetWidget()
Definition Color.c:13
Input management system for user interactions.
ScriptInvoker GetOnMenuFocusGained()
ScriptInvoker GetOnMenuUpdate()
ScriptInvoker GetOnMenuFocusLost()
MenuRootSubComponent FindComponent(typename type, bool showError=false)
ScriptInvokerBase< SCR_BaseEditableEntityFilter_OnChange > GetOnChanged()
bool HasEntityState(EEditableEntityState state)
EEditableEntityType GetEntityType(IEntity owner=null)
set< SCR_EditableEntityComponent > GetAttachedEntities()
ref map< SCR_EntitiesEditorUIRule, ref SCR_EditableEntityUIRuleTracker > m_RuleTrackers
void InsertSlot(SCR_EditableEntityComponent entity, SCR_EditableEntityBaseSlotUIComponent slot)
SCR_EditableEntityBaseSlotUIComponent GetEntitySlot(Widget w)
ref map< SCR_EditableEntityComponent, SCR_EditableEntityBaseSlotUIComponent > m_mEntitySlots
SCR_EditableEntityComponent m_EntityUnderCursor
void ApplyAutoEffect(SCR_EditableEntityComponent entity, SCR_EditableEntitySceneSlotUIComponent slot)
SCR_EditableEntityUIConfig m_EditableEntityUIConfig
SCR_CursorEditorUIComponent m_CursorComponent
override bool DeleteSlot(SCR_EditableEntityComponent entity, bool forced=false)
override SCR_EditableEntityBaseSlotUIComponent FindSlot(SCR_EditableEntityComponent entity, bool createIfNull=false)
ref array< ref SCR_BaseEntitiesEditorUIEffect > m_aEffects
ref map< EEditableEntityState, SCR_BaseEntitiesEditorUIEffect > m_aEffectsMap
void PlaceAttachedSlots(SCR_EditableEntityBaseSlotUIComponent entitySlot, vector position, float offset=32)
SCR_HoverEditableEntityFilter m_HoverManager
ref array< ref SCR_EditableEntityUISlotSize > m_aSlotSizes
override bool OnMouseEnter(Widget w, int x, int y)
SCR_MouseAreaEditorUIComponent m_MouseArea
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void OnEffect(EEditableEntityState state, set< SCR_EditableEntityComponent > entitiesInsert, set< SCR_EditableEntityComponent > entitiesRemove)
SCR_BaseEditableEntityFilter GetFilter(EEditableEntityState state, bool showError=false)
static bool IsEditMode()
Definition Functions.c:1566
static SCR_MapEntity GetMapInstance()
Get map entity instance.
Definition Types.c:486
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
EEditableEntityState
SCR_FieldOfViewSettings Attribute
proto native vector Vector(float x, float y, float z)
WidgetFlags
Widget flags. See enf::Widget::SetFlags().
Definition WidgetFlags.c:14