Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TooltipManagerEditorUIComponent.c
Go to the documentation of this file.
1 
4 {
5  protected static const float INERTIA_THRESHOLD = 0.001; //--- Squared value
6 
7  [Attribute()]
8  protected ref array<ref SCR_TooltipEditorEntry> m_Tooltips;
9 
10  [Attribute(defvalue: "0.1", desc: "How long (s) it will take before the tooltips appear.")]
11  protected float m_fDelay;
12 
13  [Attribute(defvalue: "10", desc: "How fast is the fade-in effect")]
14  protected float m_fFadeInSpeed;
15 
16  [Attribute(defvalue: "0.03", desc: "Inertia strength. Larger values mean more inertia.")]
17  private float m_fInertiaStrength;
18 
19  [Attribute("1", desc: "When enabled, changes in entity hover state will refresh tooltips.")]
20  protected bool m_bTrackHoverState;
21 
22  protected InputManager m_InputManager;
23  protected SCR_LayersEditorComponent m_LayersManager;
24  protected SCR_TooltipAreaEditorUIComponent m_TooltipArea;
25  protected SCR_CursorEditorUIComponent m_Cursor;
26  protected SCR_BaseTooltipEditorUIComponent m_Tooltip;
27  protected SCR_BaseContextMenuEditorUIComponent m_ContextMenu;
28  protected SCR_UIInfo m_Info;
29  protected Managed m_InfoInstance;
30  protected bool m_bTooltipShown;
31 
32  //------------------------------------------------------------------------------------------------
37  void SetInfo(SCR_UIInfo info, EEditorTooltip type = 0, Managed instance = null)
38  {
39  if (!m_TooltipArea)
40  return;
41 
42  if (info && info == m_Info)
43  return;
44 
45  if (m_Tooltip)
46  ResetInfo();
47 
48  foreach (SCR_TooltipEditorEntry tooltipEntry: m_Tooltips)
49  {
50  if (tooltipEntry.GetTooltipType() == type)
51  {
52  ResourceName layout = tooltipEntry.GetTooltipLayout();
53  if (!layout.IsEmpty())
54  {
55  Widget tooltipWidget = GetWidget().GetWorkspace().CreateWidgets(layout, m_TooltipArea.GetAreaWidget());
56  FrameSlot.SetOffsets(tooltipWidget, 0, 0, 0, 0);
57  FrameSlot.SetSizeToContent(tooltipWidget, true);
58 
60  if (m_Tooltip)
61  {
62  if (m_Tooltip.SetTooltip(info, instance))
63  {
64  //OnMenuUpdate(0);
65  GetGame().GetCallqueue().CallLater(PlayAnimation, m_fDelay * 1000, false);
66  }
67  else
68  {
69  tooltipWidget.RemoveFromHierarchy();
70  tooltipWidget = null;
71  }
72  }
73  else
74  {
75  Print(string.Format("SCR_BaseTooltipEditorUIComponent not found in tooltip '%1'", layout), LogLevel.WARNING);
76  return;
77  }
78  }
79  else
80  {
81  Print(string.Format("Layout for tooltip of type '%1' not defined!", typename.EnumToString(EEditorTooltip, type)), LogLevel.WARNING);
82  return;
83  }
84  }
85  }
86 
87  //--- Ignore when tooltip type is undefined (it may be intentionally so)
88  if (!m_Tooltip)
89  return;
90 
91  m_Info = info;
92  m_InfoInstance = instance;
93  }
94 
95  //------------------------------------------------------------------------------------------------
98  void ResetInfo(SCR_UIInfo info = null)
99  {
100  //--- Only reset if given info is currently shown
101  if (info && info != m_Info)
102  return;
103 
104  if (m_Tooltip)
105  {
106  m_Tooltip.GetWidget().RemoveFromHierarchy();
107  m_Tooltip = null;
108  GetGame().GetCallqueue().Remove(PlayAnimation);
109  ResetAnimation();
110  }
111  m_Info = null;
112  m_InfoInstance = null;
113  }
114 
115  //------------------------------------------------------------------------------------------------
120  void RefreshInfo(SCR_UIInfo info, EEditorTooltip type = 0, Managed instance = null)
121  {
122  if (m_InfoInstance && instance == m_InfoInstance)
123  SetInfo(info, type, instance)
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  protected void PlayAnimation()
128  {
129  //m_TooltipArea.GetWidget().SetOpacity(1);
130  AnimateWidget.Opacity(m_TooltipArea.GetWidget(), 1, m_fFadeInSpeed);
131 
132  m_bTooltipShown = true;
133  }
134 
135  //------------------------------------------------------------------------------------------------
136  protected void ResetAnimation()
137  {
138  AnimateWidget.StopAnimation(m_TooltipArea.GetWidget(), WidgetAnimationOpacity);
139  m_TooltipArea.GetWidget().SetOpacity(0);
140  m_bTooltipShown = false;
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  protected void ShowEntityTooltip(SCR_EditableEntityComponent entity)
145  {
146  if (!entity)
147  return;
148 
149  if (m_LayersManager)
150  entity = m_LayersManager.GetParentBelowCurrentLayer(entity);
151 
152  if (entity)
153  SetInfo(entity.GetInfo(), EEditorTooltip.ENTITY, entity);
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  protected void OnHover(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
158  {
159  if (!GetMenu().IsFocused())
160  return;
161 
162  //--- Entity tooltip not available when context menu is opened
163  if (m_ContextMenu && m_ContextMenu.IsContextMenuOpen())
164  return;
165 
166  if (entitiesRemove && !entitiesRemove.IsEmpty())
167  {
168  ResetInfo();
169  }
170  if (entitiesInsert && !entitiesInsert.IsEmpty())
171  {
172  ShowEntityTooltip(entitiesInsert[0]);
173  }
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  protected void OnInputDeviceIsGamepad(bool isGamepad)
178  {
179  /*
180  if (!GetMenu())
181  return;
182 
183  if (newDevice == EInputDeviceType.KEYBOARD || newDevice == EInputDeviceType.MOUSE)
184  GetMenu().GetOnMenuUpdate().Insert(OnMenuUpdate);
185  else
186  GetMenu().GetOnMenuUpdate().Remove(OnMenuUpdate);
187  */
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  protected void OnRadialMenuToggle(IEntity owner, bool isOpened)
192  {
193  if (isOpened)
194  {
195  //--- Hide entity tooltip when radial menu is opened
196  ResetInfo();
197  }
198  else
199  {
200  //--- Show entity tooltip when radial menu is closed again
202  if (hoverFilter)
203  ShowEntityTooltip(hoverFilter.GetFirstEntity());
204  }
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  protected void OnContextMenuToggle(bool isOpened)
209  {
210  //--- Hide entity tooltip when context menu is opened
211  if (isOpened)
212  ResetInfo();
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  protected void OnMenuUpdate(float tDelta)
217  {
218  if (!m_Tooltip)
219  return;
220 
221  m_Tooltip.UpdateTooltip(m_InfoInstance);
222 
223  if (!m_InputManager.IsUsingMouseAndKeyboard())
224  return;
225 
226  Widget widget = m_TooltipArea.GetAreaWidget();
227  WorkspaceWidget workspace = widget.GetWorkspace();
228 
229  float posX, posY;
230  int offsetTop, offsetRight, offsetBottom, offsetLeft;
231  int screenW = workspace.GetWidth();
232  int screenH = workspace.GetHeight();
233  screenW = workspace.DPIUnscale(screenW);
234  screenH = workspace.DPIUnscale(screenH);
235 
236  m_TooltipArea.GetOffsets(offsetTop, offsetRight, offsetBottom, offsetLeft);
237 
238  if (m_Cursor)
239  {
240  vector cursorPos = m_Cursor.GetCursorPos();
241  posX = cursorPos[0];
242  posY = cursorPos[1];
243  }
244  else
245  {
246  int mouseX, mouseY;
247  WidgetManager.GetMousePos(mouseX, mouseY);
248  posX = workspace.DPIUnscale(mouseX);
249  posY = workspace.DPIUnscale(mouseY);
250  }
251 
252  float tooltipX, tooltipY, tooltipW, tooltipH;
253 
254  //--- Get unscaled position. Using scaled one and converting would cause a jitter due to conversion imprecision.
255  vector tooltipPos = FrameSlot.GetPos(widget);
256  tooltipX = tooltipPos[0];
257  tooltipY = tooltipPos[1];
258 
259  //--- Get actual sceen size. Cannot use FrameSLot.GetSize, that returns configured, not actual size.
260  widget.GetScreenSize(tooltipW, tooltipH);
261  tooltipW = workspace.DPIUnscale(tooltipW);
262  tooltipH = workspace.DPIUnscale(tooltipH);
263 
264  //--- Prevent screen overflow
265  if (posX > screenW - tooltipW - offsetRight)
266  posX -= tooltipW + offsetLeft;
267  else
268  posX += offsetRight;
269 
270  if (posY > screenH - tooltipH - offsetBottom)
271  posY -= tooltipH + offsetTop;
272  else
273  posY += offsetBottom;
274 
275  if (vector.DistanceSq(Vector(tooltipX, tooltipY, 0), Vector(posX, posY, 0)) < INERTIA_THRESHOLD)
276  return;
277 
278  //--- Smooth movement, important especially when changing direction close to screen edges
279  if (m_bTooltipShown && tDelta != 0)
280  {
281  float progress = Math.Min(tDelta * m_fInertiaStrength, 1);
282  posX = Math.Lerp(tooltipX, posX, progress);
283  posY = Math.Lerp(tooltipY, posY, progress);
284  }
285 
286  FrameSlot.SetPos(widget, posX, posY);
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  protected void OnMenuFocusLost()
291  {
292  ResetInfo();
293  }
294 
295  //------------------------------------------------------------------------------------------------
296  override void HandlerAttachedScripted(Widget w)
297  {
298  m_InputManager = GetGame().GetInputManager();
299  if (!m_InputManager)
300  return;
301 
302  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
303 
304  MenuRootBase menu = GetMenu();
305  if (menu)
306  {
307  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
308  menu.GetOnMenuFocusLost().Insert(OnMenuFocusLost);
309  }
310 
311  MenuRootComponent menuRoot = GetRootComponent();
312  if (!menuRoot)
313  return;
314 
315  m_Cursor = SCR_CursorEditorUIComponent.Cast(menuRoot.FindComponent(SCR_CursorEditorUIComponent));
316  //if (!m_Cursor)
317  // return;
318 
320  if (m_ContextMenu)
321  m_ContextMenu.GetOnContextMenuToggle().Insert(OnContextMenuToggle);
322 
324  if (!m_TooltipArea)
325  return;
326 
327  m_TooltipArea.GetWidget().SetOpacity(0);
328 
329  if (m_bTrackHoverState)
330  {
332  if (hoverFilter)
333  hoverFilter.GetOnChanged().Insert(OnHover);
334  }
335 
337 
338  m_fInertiaStrength = 1 / Math.Max(m_fInertiaStrength, 0.001);
339 
340  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLTIP_DEBUG, "", "Show debug in tooltips", "Editor GUI");
341  }
342 
343  //------------------------------------------------------------------------------------------------
344  override void HandlerDeattached(Widget w)
345  {
347  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
348 
349  MenuRootBase menu = GetMenu();
350  if (menu)
351  {
352  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
353  menu.GetOnMenuFocusLost().Remove(OnMenuFocusLost);
354  }
355 
356  if (m_TooltipArea)
357  m_TooltipArea.ClearTooltips();
358 
359  if (m_bTrackHoverState)
360  {
362  if (hoverFilter)
363  hoverFilter.GetOnChanged().Remove(OnHover);
364  }
365 
366  if (m_ContextMenu)
367  m_ContextMenu.GetOnContextMenuToggle().Remove(OnContextMenuToggle);
368 
369  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLTIP_DEBUG);
370  }
371 }
372 
374 class SCR_TooltipEditorEntry
375 {
376  [Attribute("0", UIWidgets.ComboBox, "", enums: ParamEnumArray.FromEnum(EEditorTooltip))]
377  protected EEditorTooltip m_TooltipType;
378 
379  [Attribute(params: "layout")]
380  protected ResourceName m_TooltipLayout;
381 
382  //------------------------------------------------------------------------------------------------
384  EEditorTooltip GetTooltipType()
385  {
386  return m_TooltipType;
387  }
388 
389  //------------------------------------------------------------------------------------------------
391  ResourceName GetTooltipLayout()
392  {
393  return m_TooltipLayout;
394  }
395 }
396 
398 {
404 }
m_fInertiaStrength
private float m_fInertiaStrength
Definition: SCR_TooltipManagerEditorUIComponent.c:14
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_BaseContainerCustomTitleEnum
SCR_TooltipManagerEditorUIComponent SCR_BaseEditorUIComponent SCR_BaseContainerCustomTitleEnum(EEditorTooltip, "m_TooltipType")
Definition: SCR_TooltipManagerEditorUIComponent.c:373
SCR_CursorEditorUIComponent
Definition: SCR_CursorEditorUIComponent.c:3
SCR_BaseTooltipEditorUIComponent
Definition: SCR_BaseTooltipEditorUIComponent.c:3
ENTITY
@ ENTITY
Definition: SCR_TooltipManagerEditorUIComponent.c:401
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
m_bTooltipShown
protected bool m_bTooltipShown
Definition: SCR_TooltipManagerEditorUIComponent.c:27
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fDelay
protected float m_fDelay
Definition: SCR_TooltipManagerEditorUIComponent.c:8
EEditorTooltip
EEditorTooltip
Definition: SCR_TooltipManagerEditorUIComponent.c:397
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
SCR_TooltipAreaEditorUIComponent
Definition: SCR_TooltipAreaEditorUIComponent.c:3
TOOLBAR_ACTION
@ TOOLBAR_ACTION
Definition: SCR_TooltipManagerEditorUIComponent.c:403
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_Info
protected ref SCR_HintUIInfo m_Info
Definition: SCR_BaseHintCondition.c:3
MenuRootBase
Definition: MenuRootBase.c:6
SCR_BaseContextMenuEditorUIComponent
Definition: SCR_BaseContextMenuEditorUIComponent.c:2
m_LayersManager
protected SCR_LayersEditorComponent m_LayersManager
Definition: SCR_EntitiesToolbarEditorUIComponent.c:38
DEFAULT
@ DEFAULT
Definition: SCR_TooltipManagerEditorUIComponent.c:399
SCR_ContextMenuActionsEditorUIComponent
Definition: SCR_ContextMenuActionsEditorUIComponent.c:1
m_Tooltips
protected ref array< ref SCR_TooltipEditorEntry > m_Tooltips
Definition: SCR_TooltipManagerEditorUIComponent.c:5
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_UIInfo
Definition: SCR_UIInfo.c:7
m_Cursor
protected SCR_CursorEditorUIComponent m_Cursor
Definition: SCR_TooltipManagerEditorUIComponent.c:22
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
m_InfoInstance
protected Managed m_InfoInstance
Definition: SCR_TooltipManagerEditorUIComponent.c:26
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
MenuRootComponent
Definition: MenuRootComponent.c:6
m_Tooltip
protected SCR_ScriptedWidgetTooltip m_Tooltip
Definition: SCR_ServicesStatusDialogComponent.c:76
CONTEXT_ACTION
@ CONTEXT_ACTION
Definition: SCR_TooltipManagerEditorUIComponent.c:402
m_TooltipArea
protected SCR_TooltipAreaEditorUIComponent m_TooltipArea
Definition: SCR_TooltipManagerEditorUIComponent.c:21
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_fFadeInSpeed
protected float m_fFadeInSpeed
Definition: SCR_TooltipManagerEditorUIComponent.c:11
SCR_TooltipManagerEditorUIComponent
Definition: SCR_TooltipManagerEditorUIComponent.c:3
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
m_ContextMenu
protected SCR_BaseContextMenuEditorUIComponent m_ContextMenu
Definition: SCR_TooltipManagerEditorUIComponent.c:24
MODE
@ MODE
Definition: SCR_TooltipManagerEditorUIComponent.c:400
OnInputDeviceIsGamepadInvoker
ScriptInvoker OnInputDeviceIsGamepadInvoker()
Definition: game.c:246
GetWidget
protected Widget GetWidget()
Definition: SCR_VonDisplay.c:155
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468