Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LayerAutoEnterUIComponent.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: "1", desc: "How long it takes to toggle hovered entity automatically during entity transformation.")]
4  protected float m_fAutoEnterDuration;
5 
6  [Attribute(defvalue: "0.2", uiwidget: UIWidgets.Slider, "", params: "0 1 0.01")]
7  protected float m_fAutoEnterDelay;
8 
9  protected SCR_LayersEditorComponent m_LayersManager;
10  protected SCR_PreviewEntityEditorComponent m_PreviewEntityManager;
11  protected SCR_TransformingEditorComponent m_TransformingManager;
12  protected SCR_HoverEditableEntityFilter m_HoverFilter;
13  protected SCR_RadialProgressBarUIComponent m_RadialProgressUI;
14  protected SCR_EditableEntityComponent m_AutoEnterTarget;
15  protected float m_fAutoEnterCharge = -1;
16  protected bool m_bCanCharge = true;
17 
18  //------------------------------------------------------------------------------------------------
19  protected void OnTargetChange(SCR_EditableEntityComponent target)
20  {
21  //--- Not editing anymore or the target was deleted, cancel charge
22  if (!target || !m_PreviewEntityManager.IsEditing())
23  {
24  Clear();
25  return;
26  }
27 
28  if (!m_bCanCharge)
29  return;
30 
31  //--- Enter the layer only when hovering over its icon (i.e., delegate)
32  bool isDelegate;
33  SCR_EditableEntityComponent hoverEntity = m_HoverFilter.GetEntityUnderCursor(isDelegate);
34  if (!isDelegate)
35  return;
36 
37  //--- Filter out incompatible entities
38  if (hoverEntity)
39  {
40  hoverEntity = m_LayersManager.GetParentBelowCurrentLayer(hoverEntity);
41  if (!hoverEntity)
42  return;
43 
44  //--- Cannot enter non-interactive entities or compatible slots (hovering snaps to them instead)
45  if (!hoverEntity.HasEntityFlag(EEditableEntityFlag.LAYER) || m_PreviewEntityManager.GetTargetInteraction() != EEditableEntityInteraction.LAYER)
46  return;
47 
48  //--- Cannot enter into itself
49  if (m_TransformingManager && m_TransformingManager.IsEditing(hoverEntity))
50  return;
51  }
52 
53  //--- Start charging
54  if (hoverEntity != m_AutoEnterTarget)
55  {
56  m_AutoEnterTarget = hoverEntity;
57  m_fAutoEnterCharge = 0;
58  }
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  protected void Clear()
63  {
64  m_fAutoEnterCharge = -1;
65  m_AutoEnterTarget = null;
66  GetWidget().SetVisible(false);
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  protected void ResetGracePeriod()
71  {
72  m_bCanCharge = true;
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  protected void OnMenuUpdate(float tDelta)
77  {
78  //--- Enter hovered entity automatically while editing
79  if (m_fAutoEnterCharge >= 0)
80  {
81  //--- Chaaaaarge!
82  m_fAutoEnterCharge += tDelta;
83 
84  if (m_fAutoEnterCharge < m_fAutoEnterDelay)
85  return;
86 
87  GetWidget().SetVisible(true);
88 
89  //--- Update progress bar
90  if (m_RadialProgressUI)
91  m_RadialProgressUI.SetProgress(Math.InverseLerp(m_fAutoEnterDelay, 1, m_fAutoEnterCharge) / m_fAutoEnterDuration);
92 
93  //--- Position the widget on the enetered layer
94  vector worldPos;
95  if (m_AutoEnterTarget.GetPos(worldPos))
96  {
97  vector screenPos = GetGame().GetWorkspace().ProjWorldToScreen(worldPos, m_AutoEnterTarget.GetOwner().GetWorld());
98  FrameSlot.SetPos(GetWidget(), screenPos[0], screenPos[1]);
99  }
100 
101  //--- Charge complete
102  if (m_fAutoEnterCharge > m_fAutoEnterDuration)
103  {
104  m_LayersManager.ToggleCurrentLayer(m_AutoEnterTarget);
105  Clear();
106 
107  //--- Disable charging right after entering a layer, so it won't instantly start charging sub-layer if there is another icon under cursor
108  m_bCanCharge = false;
109  GetGame().GetCallqueue().CallLater(ResetGracePeriod, 100);
110  }
111  }
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  override protected bool IsUnique()
116  {
117  return false;
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  override void HandlerAttachedScripted(Widget w)
122  {
123  super.HandlerAttachedScripted(w);
124 
129  m_RadialProgressUI = SCR_RadialProgressBarUIComponent.Cast(SCR_WidgetTools.FindHandlerInChildren(w, SCR_RadialProgressBarUIComponent));
130 
131  m_PreviewEntityManager.GetOnTargetChange().Insert(OnTargetChange);
132 
133  MenuRootBase menu = GetMenu();
134  if (menu)
135  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
136 
137  Clear();
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  override void HandlerDeattached(Widget w)
142  {
143  super.HandlerDeattached(w);
144 
146  m_PreviewEntityManager.GetOnTargetChange().Remove(OnTargetChange);
147 
148  MenuRootBase menu = GetMenu();
149  if (menu)
150  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
151  }
152 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
EEditableEntityInteraction
EEditableEntityInteraction
Type of suggested interaction when hovering edited entity on top of another entity.
Definition: EEditableEntityInteraction.c:5
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
SCR_WidgetTools
Definition: SCR_WidgetTools.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_RadialProgressBarUIComponent
Definition: SCR_RadialProgressBarUIComponent.c:1
SCR_TransformingEditorComponent
Definition: SCR_TransformingEditorComponent.c:33
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
m_PreviewEntityManager
protected SCR_PreviewEntityEditorComponent m_PreviewEntityManager
Definition: SCR_PreviewEntityEditorUIComponent.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_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_LayerAutoEnterUIComponent
Definition: SCR_LayerAutoEnterUIComponent.c:1
GetWidget
protected Widget GetWidget()
Definition: SCR_VonDisplay.c:155
SCR_PreviewEntityEditorComponent
Definition: SCR_PreviewEntityEditorComponent.c:12