Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LayersEditorUIComponent.c
Go to the documentation of this file.
5 {
6  //SFX
7  [Attribute(SCR_SoundEvent.SOUND_E_LAYER_EDIT_START, UIWidgets.EditBox, "")]
8  protected string m_sSfxStartLayerEditing;
9 
10  [Attribute(SCR_SoundEvent.SOUND_E_LAYER_EDIT_END, UIWidgets.EditBox, "")]
11  protected string m_sSfxStopLayerEditing;
12 
13  [Attribute(SCR_SoundEvent.SOUND_E_LAYER_DEEPER, UIWidgets.EditBox, "")]
14  protected string m_sSfxGoLayerDeeper;
15 
16  [Attribute(SCR_SoundEvent.SOUND_E_LAYER_BACK, UIWidgets.EditBox, "")]
17  protected string m_sSfxGoLayerBack;
18 
19  //Widget References
20  [Attribute()]
21  protected string m_sLayerElementHolder;
22 
23  protected Widget m_LayerElementHolder;
24 
25  [Attribute()]
26  protected string m_sExitLayerButton;
27 
28  [Attribute()]
29  protected string m_sLayerEditorOverlayName;
30 
31  protected Widget m_LayerEditorOverlay;
32 
33  [Attribute("LayerEditorOverlay")]
34  protected string m_sParentWidgetName;
35 
36  protected Widget m_parentWidget;
37 
38  protected SCR_EditableEntitySlotManagerUIComponent m_SlotManager;
39 
40  //References
41  protected SCR_EditableEntityComponent m_SelectedLayer;
42  protected ref array<SCR_EditableEntityComponent> m_aCurrentSelectedLayers = {};
43  protected SCR_LayersEditorComponent m_LayersManager;
44  protected InputManager m_InputManager;
45  protected SCR_MenuEditorComponent m_EditorMenuManager;
46  protected SCR_StatesEditorComponent m_StatesManager;
47  protected SCR_HoverEditableEntityFilter m_HoverFilter;
48 
49  //Settings
50  [Attribute(defvalue: "0", desc: "Layers shown after WorldRoot but before Dropdown")]
51  protected int m_iLayersShownAfterRoot;
52 
53  [Attribute(defvalue: "1", desc: "Layers shown before current but after Dropdown")]
54  protected int m_iLayersShownBeforeCurrent;
55 
56  //Prefabs
57  [Attribute()]
58  protected ResourceName m_LayerElementPrefab;
59 
60  [Attribute()]
61  protected ResourceName m_LayerElementButtonPrefab;
62 
63  [Attribute()]
64  protected ResourceName m_LayerWorldPrefab;
65 
66  [Attribute()]
67  protected ResourceName m_LayerWorldButtonPrefab;
68 
69  [Attribute()]
70  protected ResourceName m_NextLayerIndicatorPrefab;
71 
72  [Attribute()]
73  protected ResourceName m_MoreLayersIndicatorPrefab;
74 
75  //State
76  protected bool m_bUsesGamepad;
77 
78  protected ref map<SCR_ButtonBaseComponent, SCR_EditableEntityComponent> m_mButtonReferences = new map<SCR_ButtonBaseComponent, SCR_EditableEntityComponent>();
79 
80  //======================== ON MENU UPDATE ========================\\
81 
82  //------------------------------------------------------------------------------------------------
83  protected void OnMenuUpdate(float tDelta)
84  {
85  bool mapShown = SCR_MapEntity.GetMapInstance() && SCR_MapEntity.GetMapInstance().IsOpen();
86  if (m_InputManager && !mapShown)
87  m_InputManager.ActivateContext("EditorEditModeContext");
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  protected void OnLayerButtonPressed(SCR_ButtonBaseComponent button)
92  {
94 
95  if (m_mButtonReferences.Find(button, layer))
96  m_LayersManager.SetCurrentLayer(layer);
97  }
98 
99  //~ToDo: Check is gamepad is used and show controlles for it: GetGame().OnInputDeviceIsGamepadInvoker(). Hide L1 + Right button hint if no children. Check if input can be displayed dynamicly
100  //======================== CREATE LAYER UI ========================\\
101 
102  //------------------------------------------------------------------------------------------------
103  //On Layer changed recreate layer menu
104  protected void OnCompositionLayerChanged(SCR_EditableEntityComponent currentLayer, SCR_EditableEntityComponent prevLayer)
105  {
106  m_SelectedLayer = currentLayer;
107 
108  //If currentLayer is not null then menu should be shown
109  if (m_SelectedLayer)
110  {
111  RefreshLayerUI();
112  }
113  //No current Layer so set UI invisible
114  else
115  {
116  //Clear UI
117  ClearLayerElements();
118  SetVisible(false);
119  }
120 
121  if (!prevLayer && !currentLayer) //~ Safty, No layer thus return
122  return;
123  else if (!prevLayer && currentLayer) //~ Start Layer editing
124  SCR_UISoundEntity.SoundEvent(m_sSfxStartLayerEditing, true);
125  else if (prevLayer && !currentLayer) //~ Stop Layer editing
126  SCR_UISoundEntity.SoundEvent(m_sSfxStopLayerEditing, true);
127  else if (currentLayer.GetParentEntity() == prevLayer) //~ Go layer deeper
128  SCR_UISoundEntity.SoundEvent(m_sSfxGoLayerDeeper, true);
129  else //~ Go layer back
130  SCR_UISoundEntity.SoundEvent(m_sSfxGoLayerBack, true);
131  }
132 
133  //On input change
134 
135  //------------------------------------------------------------------------------------------------
136  protected void OnInputDeviceIsGamepad(bool isGamepad)
137  {
138  m_bUsesGamepad = isGamepad;
139 
140  RefreshLayerUI();
141  }
142 
143  //======================== PARENT ENTITY CHANGED ========================\\
144 
145  //------------------------------------------------------------------------------------------------
146  protected void RefreshLayerUI()
147  {
148  if (m_SelectedLayer == null)
149  return;
150 
151  //~Todo: Figure out what is setting the UI disabled
152  m_parentWidget.SetEnabled(true);
153 
154  //Clear UI
155  ClearLayerElements();
156 
157  //Add the world root
158  CreateWorldRootLayer();
159 
160  //Get Layer List
161  m_aCurrentSelectedLayers = {};
162  m_SelectedLayer.GetParentEntities(m_aCurrentSelectedLayers);
163  m_aCurrentSelectedLayers.InsertAt(m_SelectedLayer, 0);
164  int totalLayerCount = m_aCurrentSelectedLayers.Count();
165  bool hasMoreAfterRootIndicator = false;
166 
167  //Go over each layer and display them properly (In reverse order)
168  for (int i = totalLayerCount -1; i > -1; i--)
169  {
170  //Place layers after World Root or after More indicator
171  if (totalLayerCount - i <= m_iLayersShownAfterRoot || i <= m_iLayersShownBeforeCurrent)
172  {
173  //Create UI elements
174  CreateNextLayerIndicator();
175  CreateLayerElement(m_aCurrentSelectedLayers[i], i == 0);
176  }
177  //Layers are hidden
178  else if (!hasMoreAfterRootIndicator)
179  {
180  hasMoreAfterRootIndicator = true;
181  CreateNextLayerIndicator();
182  CreateMoreLayersIndicator();
183  }
184  }
185 
186  //Set UI visible
187  SetVisible(true);
188  }
189 
190  //======================== CHECK IF CHANGED ========================\\
191 
192  //------------------------------------------------------------------------------------------------
196  protected bool CheckIfSelectedLayerHierarchyChanged(SCR_EditableEntityComponent entity)
197  {
198  //If given entity is not null
199  if (entity)
200  {
201  //Go through array and check if given entity changed
202  for (int i = 0, count = m_aCurrentSelectedLayers.Count(); i < count; i++)
203  {
204  if (m_aCurrentSelectedLayers[i] == entity)
205  return true;
206  }
207  }
208 
209  return false;
210  }
211 
212  //======================== PARENT ENTITY CHANGED ========================\\
213 
214  //------------------------------------------------------------------------------------------------
219  protected void OnParentEntityVisibleChanged(SCR_EditableEntityComponent entity, SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev)
220  {
221  if (CheckIfSelectedLayerHierarchyChanged(entity))
222  {
223  RefreshLayerUI();
224  return;
225  }
226 
227  if (CheckIfSelectedLayerHierarchyChanged(parentEntity))
228  {
229  RefreshLayerUI();
230  return;
231  }
232 
233  if (CheckIfSelectedLayerHierarchyChanged(parentEntityPrev))
234  {
235  RefreshLayerUI();
236  return;
237  }
238  }
239 
240  //======================== ENTITY STATE CHANGED ========================\\
241 
242  //------------------------------------------------------------------------------------------------
243  protected void OnEntityStateChanged(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
244  {
245  //Inserted Entities state changed, check if in Hierarchy, if true: Refresh UI
246  if (entitiesInsert)
247  {
248  for (int i = 0, count = entitiesInsert.Count(); i < count; i++)
249  {
250  if (CheckIfSelectedLayerHierarchyChanged(entitiesInsert[i]))
251  {
252  RefreshLayerUI();
253  return;
254  }
255  }
256  }
257 
258  //Inserted Entities state changed, check if in Hierarchy, if true: Refresh UI
259  if (entitiesRemove)
260  {
261  for (int i = 0, count = entitiesRemove.Count(); i < count; i++)
262  {
263  if (CheckIfSelectedLayerHierarchyChanged(entitiesRemove[i]))
264  {
265  RefreshLayerUI();
266  return;
267  }
268  }
269  }
270  }
271 
272  //======================== CREATE LAYER ELEMENTS ========================\\
273  //------------------------ Layer Element in ------------------------\\
274 
275  //------------------------------------------------------------------------------------------------
276  protected void CreateLayerElement(SCR_EditableEntityComponent layerEntity, bool isLast)
277  {
278  Widget elementWidget;
279 
280  //Spawn Widget
281  if (m_bUsesGamepad || isLast)
282  {
283  elementWidget = GetGame().GetWorkspace().CreateWidgets(m_LayerElementPrefab, m_LayerElementHolder);
284  if (!elementWidget)
285  return;
286  }
287  else
288  {
289  elementWidget = GetGame().GetWorkspace().CreateWidgets(m_LayerElementButtonPrefab, m_LayerElementHolder);
290 
291  if (!elementWidget)
292  return;
293 
294  Widget button = elementWidget.FindAnyWidget("Button");
295 
296  if (!button)
297  return;
298 
299  SCR_ButtonBaseComponent buttonComponent = SCR_ButtonBaseComponent.Cast(button.FindHandler(SCR_ButtonBaseComponent));
300 
301  if (!buttonComponent)
302  return;
303 
304  m_mButtonReferences.Insert(buttonComponent, layerEntity);
305  buttonComponent.m_OnClicked.Insert(OnLayerButtonPressed);
306  }
307 
309  if (!toolbarItem)
310  {
311  elementWidget.RemoveFromHierarchy();
312  return;
313  }
314 
315  toolbarItem.InitToolbarItem(elementWidget);
316 
317  SCR_EditableEntityLinkUIComponent linkedEntityComponent = SCR_EditableEntityLinkUIComponent.Cast(elementWidget.FindHandler(SCR_EditableEntityLinkUIComponent));
318 
319  if (linkedEntityComponent)
320  linkedEntityComponent.SetLinkedEntity(layerEntity);
321 
323  if (entityItem)
324  entityItem.SetEntity(layerEntity, elementWidget, m_SlotManager);
325  }
326 
327  //------------------------ Next Layer Indicator ------------------------\\
328 
329  //------------------------------------------------------------------------------------------------
330  protected void CreateNextLayerIndicator()
331  {
332  Widget nextLayerIndicator = GetGame().GetWorkspace().CreateWidgets(m_NextLayerIndicatorPrefab, m_LayerElementHolder);
333  }
334 
335  //------------------------ Drop menu creator ------------------------\\
336 
337  //------------------------------------------------------------------------------------------------
338  protected void CreateMoreLayersIndicator()
339  {
340  Widget moreLayersIndicator = GetGame().GetWorkspace().CreateWidgets(m_MoreLayersIndicatorPrefab, m_LayerElementHolder);
341  }
342 
343  //------------------------ Children Indicator ------------------------\\
344 
345  //------------------------------------------------------------------------------------------------
346  protected void CreateWorldRootLayer()
347  {
348  Widget elementWidget;
349 
350  //Spawn Widget
351  if (m_bUsesGamepad)
352  {
353  elementWidget = GetGame().GetWorkspace().CreateWidgets(m_LayerWorldPrefab, m_LayerElementHolder);
354  }
355  else
356  {
357  elementWidget = GetGame().GetWorkspace().CreateWidgets(m_LayerWorldButtonPrefab, m_LayerElementHolder);
358  if (!elementWidget)
359  return;
360 
361  Widget button = elementWidget.FindAnyWidget("Button");
362 
363  if (!button)
364  return;
365 
366  SCR_ButtonBaseComponent buttonComponent = SCR_ButtonBaseComponent.Cast(button.FindHandler(SCR_ButtonBaseComponent));
367 
368  if (!buttonComponent)
369  return;
370 
371  m_mButtonReferences.Insert(buttonComponent, null);
372  buttonComponent.m_OnClicked.Insert(OnLayerButtonPressed);
373  }
374  }
375 
376  //======================== MENU VISIBILITY ========================\\
377 
378  //------------------------------------------------------------------------------------------------
381  protected void SetVisible(bool show)
382  {
383  if (!m_parentWidget)
384  return;
385 
386  if (m_parentWidget.IsVisible() != show)
387  {
388  m_parentWidget.SetVisible(show);
389 
390  if (m_LayerEditorOverlay)
391  m_LayerEditorOverlay.SetVisible(show);
392 
393  if (!show)
394  ClearLayerElements();
395  }
396  }
397 
398  //======================== CLEAR UI ========================\\
399 
400  //------------------------------------------------------------------------------------------------
402  protected void ClearLayerElements()
403  {
404  Widget child = m_LayerElementHolder.GetChildren();
405  Widget childtemp;
406  while (child)
407  {
408  childtemp = child;
409  child = child.GetSibling();
410  childtemp.RemoveFromHierarchy();
411  }
412 
413  m_SlotManager.ClearSlots();
414 
415  m_mButtonReferences.Clear();
416  }
417 
418  //======================== BUTTON FUNCTIONS ========================\\
419 
420  //------------------------------------------------------------------------------------------------
421  protected void OnEditorExitLayerButton()
422  {
423  if (m_LayersManager)
424  m_LayersManager.SetCurrentLayerToParent();
425  }
426 
427  //======================== INHERITED ========================\\
428 
429  //------------------------------------------------------------------------------------------------
430  override void HandlerAttachedScripted(Widget w)
431  {
432  if (SCR_Global.IsEditMode()) return; //--- Run-time only
433 
434  m_LayerElementHolder = w.FindAnyWidget(m_sLayerElementHolder);
435 
436  m_parentWidget = GetMenu().GetRootWidget().FindAnyWidget(m_sParentWidgetName);
438 
439  if (m_LayerElementHolder)
440  {
441  //Input device changed
442  OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
443  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
444 
445  //Get layersEditorComponent
447  if (!m_LayersManager)
448  return;
449 
450  //Subscribe to OnCompositionLayerChanged
451  m_LayersManager.GetOnCurrentLayerChange().Insert(OnCompositionLayerChanged);
452 
453  //Get Core
454  SCR_EditableEntityCore core = SCR_EditableEntityCore.Cast(SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore)); //Remove and just get new in Handler
455  if (!core)
456  return;
457 
458  //Subscribe to OnParentEntityChanged
459  core.Event_OnParentEntityChanged.Insert(OnParentEntityVisibleChanged);
460 
462  if (!filter)
463  return;
464 
465  filter.GetOnChanged().Insert(OnEntityStateChanged);
466 
467  //Register buttons
468  Widget widget = w.FindAnyWidget(m_sExitLayerButton);
469  if (widget)
470  {
471  ButtonActionComponent exitLayerButton = ButtonActionComponent.Cast(widget.FindHandler(ButtonActionComponent));
472  if (exitLayerButton)
473  exitLayerButton.GetOnAction().Insert(OnEditorExitLayerButton);
474  }
475 
476  m_EditorMenuManager = SCR_MenuEditorComponent.Cast(SCR_MenuEditorComponent.GetInstance(SCR_MenuEditorComponent));
477 
479  if (!entitiesManager)
480  return;
481 
483 
484  m_HoverFilter = SCR_HoverEditableEntityFilter.Cast(entitiesManager.GetFilter(EEditableEntityState.HOVER));
485  if (!m_HoverFilter)
486  return;
487 
488  MenuRootBase menu = GetMenu();
489  if (menu)
490  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
491 
492  m_InputManager = GetGame().GetInputManager();
493  }
494 
495  //Widget overlay
496  Widget parent = w.GetParent();
497  if (parent)
498  {
499  m_LayerEditorOverlay = parent.FindAnyWidget(m_sLayerEditorOverlayName);
500 
501  if (m_LayerEditorOverlay)
502  m_LayerEditorOverlay.SetVisible(false);
503  }
504 
505  }
506 
507  //------------------------------------------------------------------------------------------------
508  override void HandlerDeattached(Widget w)
509  {
510  if (m_LayersManager)
511  {
512  m_LayersManager.GetOnCurrentLayerChange().Remove(OnCompositionLayerChanged);
513 
514  //Unregister Buttons
515  Widget widget = w.FindAnyWidget(m_sExitLayerButton);
516  if (widget)
517  {
518  ButtonActionComponent exitLayerButton = ButtonActionComponent.Cast(widget.FindHandler(ButtonActionComponent));
519  if (exitLayerButton)
520  exitLayerButton.GetOnAction().Remove(OnEditorExitLayerButton);
521  }
522 
524  if (core)
525  core.Event_OnParentEntityChanged.Remove(OnParentEntityVisibleChanged);
526 
528  if (filter)
529  filter.GetOnChanged().Remove(OnEntityStateChanged);
530 
531  super.HandlerDeattached(w);
532 
533  MenuRootBase menu = GetMenu();
534  if (menu)
535  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
536  }
537  }
538 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
m_StatesManager
private SCR_StatesEditorComponent m_StatesManager
Definition: SCR_AttributesManagerEditorComponent.c:65
SCR_EntityToolbarItemEditorUIComponent
Definition: SCR_EntityToolbarItemEditorUIComponent.c:1
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EditableEntitySlotManagerUIComponent
Definition: SCR_EditableEntitySlotManagerUIComponent.c:1
m_SlotManager
SCR_SlotServiceComponentClass m_SlotManager
Service with basic slot handling functionalities.
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
Attribute
typedef Attribute
Post-process effect of scripted camera.
MenuRootBase
Definition: MenuRootBase.c:6
m_LayersManager
protected SCR_LayersEditorComponent m_LayersManager
Definition: SCR_EntitiesToolbarEditorUIComponent.c:38
m_HoverFilter
protected SCR_HoverEditableEntityFilter m_HoverFilter
Definition: SCR_PreviewEntityEditorUIComponent.c:45
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
ButtonActionComponent
Component to execute action when the button or its shortcut is pressed.
Definition: ButtonActionComponent.c:2
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_LayersEditorUIComponent
Definition: SCR_LayersEditorUIComponent.c:4
SCR_BaseToolbarItemEditorUIComponent
Definition: SCR_BaseToolbarItemEditorUIComponent.c:1
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
SCR_Global
Definition: Functions.c:6
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_MenuEditorComponent
Definition: SCR_MenuEditorComponent.c:8
SCR_StatesEditorComponent
Definition: SCR_StatesEditorComponent.c:9