Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EntitiesEditorUIComponent.c
Go to the documentation of this file.
2 {
4  protected ref array<ref SCR_BaseEntitiesEditorUIEffect> m_aEffects;
5 
7  protected ref array<ref SCR_EditableEntityUISlotSize> m_aSlotSizes;
8 
9  [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
10  protected ResourceName m_SlotPrefab;
11 
12  protected SCR_EditableEntityUIConfig m_EditableEntityUIConfig;
13  protected ref map<EEditableEntityState, SCR_BaseEntitiesEditorUIEffect> m_aEffectsMap = new map<EEditableEntityState, SCR_BaseEntitiesEditorUIEffect>();
14  protected WorkspaceWidget m_Workspace;
15  protected InputManager m_InputManager;
16  protected SCR_HoverEditableEntityFilter m_HoverManager;
17  protected SCR_CursorEditorUIComponent m_CursorComponent;
18  protected SCR_EditableEntityComponent m_EntityUnderCursor;
19  protected SCR_MouseAreaEditorUIComponent m_MouseArea;
20  protected SCR_MapEntity m_MapEntity;
21 
23  //--- Registration
25 
26  //------------------------------------------------------------------------------------------------
27  override SCR_EditableEntityBaseSlotUIComponent FindSlot(SCR_EditableEntityComponent entity, bool createIfNull = false)
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
76  foreach (SCR_EditableEntityUIRuleTracker ruleTracker : m_RuleTrackers)
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)
90  m_EntityUnderCursor = null;
91 
92  return deleted;
93  }
94 
96  //--- Mouse interaction
98 
99  //------------------------------------------------------------------------------------------------
100  override bool OnMouseEnter(Widget w, int x, int y)
101  {
102  SCR_EditableEntityBaseSlotUIComponent entitySlot = GetEntitySlot(w);
103  if (entitySlot)
104  m_EntityUnderCursor = entitySlot.GetEntity();
105 
106  return false;
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
111  {
112  SCR_EditableEntityBaseSlotUIComponent entitySlot = GetEntitySlot(w);
113  if (entitySlot)
114  m_EntityUnderCursor = null;
115 
116  return false;
117  }
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;
124  }
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  //------------------------------------------------------------------------------------------------
163  {
164  foreach (EEditableEntityState effectState, SCR_BaseEntitiesEditorUIEffect effect : m_aEffectsMap)
165  {
166  if (entity.HasEntityState(effectState))
167  {
168  effect.ApplyOn(slot.GetWidget());
169  break;
170  }
171  }
172  }
173 
175  //--- Update
177 
178  //------------------------------------------------------------------------------------------------
180  void OnMenuUpdate(float tDelta)
181  {
182  //--- No scene interaction when the map is opened
183  bool isMapOpen = m_MapEntity && m_MapEntity.IsOpen();
184  GetWidget().SetVisible(!isMapOpen);
185  if (isMapOpen)
186  return;
187 
188  int screenW = m_Workspace.GetWidth();
189  int screenH = m_Workspace.GetHeight();
190  screenW = m_Workspace.DPIUnscale(screenW);
191  screenH = m_Workspace.DPIUnscale(screenH);
192  vector posCenter = Vector(screenW / 2, screenH / 2, 0);
193 
194  vector transformCam[4];
195  GetGame().GetWorld().GetCurrentCamera(transformCam);
196  vector posCam = transformCam[3];
197 
198  if (!m_bInteractive || !m_CursorComponent || (m_InputManager && m_InputManager.IsUsingMouseAndKeyboard()))
199  {
200  //--- Mouse & keyboard (or non-interactive)
201  foreach (SCR_EditableEntityBaseSlotUIComponent entitySlot : m_mEntitySlots)
202  {
203  entitySlot.UpdateSlot(screenW, screenH, posCenter, posCam);
204  }
205  }
206  else
207  {
208  //--- Gamepad (check for icon distances)
209  float dis;
210  float nearestDis = m_CursorComponent.GetCursorRadiusSq();
211  vector cursorPos = m_CursorComponent.GetCursorPos();
213  foreach (SCR_EditableEntityBaseSlotUIComponent entitySlot : m_mEntitySlots)
214  {
215  dis = vector.DistanceSq(cursorPos, entitySlot.UpdateSlot(screenW, screenH, posCenter, posCam));
216  if (dis < nearestDis && !entitySlot.IsPreview()) //--- Ignore preview entity, it's snapped cursor and would block actual entities under cursor
217  {
218  nearestDis = dis;
219  nearestSlot = entitySlot;
220  }
221  }
222  if (nearestSlot)
223  m_EntityUnderCursor = nearestSlot.GetEntity();
224  else
225  m_EntityUnderCursor = null;
226  }
227 
228  if (m_HoverManager && m_MouseArea.IsMouseOn())
229  m_HoverManager.SetEntityUnderCursor(m_EntityUnderCursor, true);
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  protected void OnMenuFocusLost()
234  {
235  //--- When menu focus is lost, OnMenuUpdate is not called anymore. Keep it updating with low frequency.
236  GetGame().GetCallqueue().CallLater(OnMenuUpdate, 10, true, 0);
237  }
238 
239  //------------------------------------------------------------------------------------------------
240  protected void OnMenuFocusGained()
241  {
242  GetGame().GetCallqueue().Remove(OnMenuUpdate);
243  }
244 
246  //--- Default functions
248 
249  //------------------------------------------------------------------------------------------------
250  override void HandlerAttachedScripted(Widget w)
251  {
252  if (SCR_Global.IsEditMode())
253  return; //--- Run-time only
254 
256  if (!entityManager)
257  return;
258 
259  MenuRootBase menu = GetMenu();
260  if (!menu)
261  return;
262 
263  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
264  menu.GetOnMenuFocusLost().Insert(OnMenuFocusLost);
265  menu.GetOnMenuFocusGained().Insert(OnMenuFocusGained);
266 
267  if (!menu.IsFocused())
268  OnMenuFocusLost();
269 
270  m_Workspace = w.GetWorkspace();
271  if (!m_Workspace)
272  return;
273 
274  m_InputManager = GetGame().GetInputManager();
275  m_HoverManager = SCR_HoverEditableEntityFilter.Cast(entityManager.GetFilter(EEditableEntityState.HOVER));
276 
277  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
278 
279  MenuRootComponent root = GetRootComponent();
280  if (root)
281  {
284  }
285 
286  //--- Init effects
288  {
289  EEditableEntityState state = effect.GetState();
290  if (state == 0)
291  continue;
292 
293  SCR_BaseEditableEntityFilter stateManager = entityManager.GetFilter(state);
294  if (!stateManager)
295  continue;
296 
297  stateManager.GetOnChanged().Insert(OnEffect);
298  m_aEffectsMap.Insert(state, effect);
299  }
300 
301  m_MapEntity = SCR_MapEntity.GetMapInstance();
302 
303  super.HandlerAttachedScripted(w);
304  }
305 
306  //------------------------------------------------------------------------------------------------
307  override void HandlerDeattached(Widget w)
308  {
309  super.HandlerDeattached(w);
310  if (SCR_Global.IsEditMode())
311  return; //--- Run-time only
312 
313  MenuRootBase menu = GetMenu();
314  if (menu)
315  {
316  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
317  menu.GetOnMenuFocusLost().Remove(OnMenuFocusLost);
318  menu.GetOnMenuFocusGained().Remove(OnMenuFocusGained);
319  }
320 
321  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
322 
324  {
326  foreach (SCR_EntitiesEditorUIRule rule: m_EditableEntityUIConfig.GetRules())
327  {
328  if (m_RuleTrackers.Find(rule, ruleTracker))
329  delete ruleTracker;
330  }
331  }
333  if (entityManager)
334  {
336  {
337  EEditableEntityState state = effect.GetState();
338  if (state == 0)
339  continue;
340 
341  SCR_BaseEditableEntityFilter stateManager = entityManager.GetFilter(state);
342  if (!stateManager)
343  continue;
344 
345  if (stateManager && stateManager.GetOnChanged())
346  stateManager.GetOnChanged().Remove(OnEffect);
347  }
348  }
349  }
350 }
351 
353 class SCR_EditableEntityUISlotSize
354 {
355  [Attribute("0", UIWidgets.ComboBox, "Entity type.", enums: ParamEnumArray.FromEnum(EEditableEntityType))]
356  private EEditableEntityType m_Type;
357 
358  [Attribute("48")]
359  private int m_iSize;
360 
361  //------------------------------------------------------------------------------------------------
364  {
365  return m_Type;
366  }
367 
368  //------------------------------------------------------------------------------------------------
370  int GetSize()
371  {
372  return m_iSize;
373  }
374 }
SCR_BaseContainerCustomTitleEnum
SCR_EntitiesEditorUIComponent SCR_EditableEntitySlotManagerUIComponent SCR_BaseContainerCustomTitleEnum(EEditableEntityType, "m_Type")
Definition: SCR_EntitiesEditorUIComponent.c:352
m_MouseArea
private SCR_MouseAreaEditorUIComponent m_MouseArea
Definition: SCR_CursorEditorUIComponent.c:38
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_CursorEditorUIComponent
Definition: SCR_CursorEditorUIComponent.c:3
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
BaseContainerProps
SCR_EntitiesEditorUIComponent SCR_EditableEntitySlotManagerUIComponent BaseContainerProps()
SCR_BaseEntitiesEditorUIEffect
Definition: SCR_BaseEntitiesEditorUIEffect.c:2
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
GetType
override EGadgetType GetType()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:52
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
SCR_EntitiesEditorUIRule
Definition: SCR_EditableEntityUIRule.c:8
m_aSlotSizes
protected ref array< ref SCR_EditableEntityUISlotSize > m_aSlotSizes
Definition: SCR_EntitiesEditorUIComponent.c:6
SCR_EditableEntityBaseSlotUIComponent
Definition: SCR_EditableEntityBaseSlotUIComponent.c:6
SCR_EditableEntityUIRuleTracker
Definition: SCR_EditableEntityUIRuleTracker.c:8
SCR_EntitiesEditorUIComponent
Definition: SCR_EntitiesEditorUIComponent.c:1
m_SlotPrefab
protected ResourceName m_SlotPrefab
Definition: SCR_EntitiesEditorUIComponent.c:9
SCR_EditableEntitySlotManagerUIComponent
Definition: SCR_EditableEntitySlotManagerUIComponent.c:1
m_aEffectsMap
protected ref map< EEditableEntityState, SCR_BaseEntitiesEditorUIEffect > m_aEffectsMap
Definition: SCR_EntitiesEditorUIComponent.c:12
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
m_HoverManager
SCR_BaseActionsEditorComponentClass m_HoverManager
Attribute
typedef Attribute
Post-process effect of scripted camera.
MenuRootBase
Definition: MenuRootBase.c:6
SCR_MouseAreaEditorUIComponent
Definition: SCR_MouseAreaEditorUIComponent.c:3
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
m_EntityUnderCursor
private SCR_EditableEntityComponent m_EntityUnderCursor
Definition: SCR_CursorEditorUIComponent.c:20
m_Type
protected EEditableEntityType m_Type
Definition: SCR_EntitiesToolbarEditorUIComponent.c:3
SCR_EditableEntitySceneSlotUIComponent
Definition: SCR_EditableEntitySceneSlotUIComponent.c:1
m_Workspace
protected WorkspaceWidget m_Workspace
Definition: SCR_EntitiesEditorUIComponent.c:13
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
m_EditableEntityUIConfig
protected SCR_EditableEntityUIConfig m_EditableEntityUIConfig
Definition: SCR_EntitiesEditorUIComponent.c:11
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
MenuRootComponent
Definition: MenuRootComponent.c:6
SCR_Global
Definition: Functions.c:6
m_CursorComponent
protected SCR_CursorEditorUIComponent m_CursorComponent
Definition: SCR_EntitiesEditorUIComponent.c:16
GetSize
int GetSize()
Definition: SCR_EditableGroupComponent.c:264
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_aEffects
protected ref array< ref SCR_BaseEntitiesEditorUIEffect > m_aEffects
Definition: SCR_EntitiesEditorUIComponent.c:3
SCR_EditableEntityUIConfig
Definition: SCR_EntitiesEditorUIConfig.c:7
GetWidget
protected Widget GetWidget()
Definition: SCR_VonDisplay.c:155