Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TooltipManagerEntity.c
Go to the documentation of this file.
1 
6 class SCR_TooltipManagerEntityClass : GenericEntityClass
7 {
8 }
9 
10 //------------------------------------------------------------------------------------------------
12 {
13  protected static SCR_TooltipManagerEntity s_Instance = null;
14 
15  protected bool m_bFollowCursor; // When true, tooltip will be following cursor
16  protected Widget m_wTooltip; // The tooltip widget
17  protected ref SCR_ScriptedWidgetTooltipPreset m_Preset; // The tooltip settings
18  protected Widget m_wHoverWidget; // When cursor leaves this widget, or this widget gets destroyed, current tooltip will be reset
19  protected SCR_ETooltipAlignmentHorizontal m_eHorizontalAlignment; // Tooltip position in relation to the hover Widget
20  protected SCR_ETooltipAlignmentVertical m_eVerticalAlignment; // Tooltip position in relation to the hover Widget
21 
22  protected bool m_bIsRendered;
23  protected Widget m_wInteractableWidget; // Currently focused or hovered widget
24  protected WorkspaceWidget m_wWorkspace;
25 
26  const int TOOLTIP_Z_ORDER = 10000; // Z order of tooltip. Tooltip widget is created in Workspace and must be above other widgets.
27 
28  //------------------------------------------------------------------------------------------------
29  // PUBLIC
30  //------------------------------------------------------------------------------------------------
32  {
33  return s_Instance;
34  }
35 
36  //------------------------------------------------------------------------------------------------
43  static Widget CreateTooltip(notnull SCR_ScriptedWidgetTooltipPreset preset, notnull Widget hoverWidget)
44  {
46 
47  if (!ent)
48  return null;
49 
50  return ent.Internal_CreateTooltip(preset, hoverWidget);
51  }
52 
53  //------------------------------------------------------------------------------------------------
57  static void DeleteTooltip()
58  {
60 
61  if (!ent)
62  return;
63 
64  ent.Internal_DeleteTooltip();
65  }
66 
67  //------------------------------------------------------------------------------------------------
71  static Widget GetTooltip()
72  {
74 
75  if (!ent)
76  return null;
77 
78  return ent.m_wTooltip;
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  // PROTECTED
83  //------------------------------------------------------------------------------------------------
84  protected Widget Internal_CreateTooltip(notnull SCR_ScriptedWidgetTooltipPreset preset, notnull Widget hoverWidget)
85  {
86  m_Preset = preset;
87  m_wHoverWidget = hoverWidget;
88  m_bFollowCursor = m_Preset.m_bFollowCursor;
89  m_bIsRendered = false;
90 
91  // Delete the old tooltip
92  DeleteTooltip();
93 
94  m_wWorkspace = GetGame().GetWorkspace();
95  m_wTooltip = m_wWorkspace.CreateWidgets(preset.m_sContentLayout, m_wWorkspace);
96 
97  if (m_wTooltip)
98  m_wTooltip.SetZOrder(TOOLTIP_Z_ORDER);
99 
100  UpdatePosition(true);
101 
102  // Activate lazily - only when creating some tooltip
103  SetEventMask(EntityEvent.FRAME);
104 
105  return m_wTooltip;
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  protected void Internal_DeleteTooltip()
110  {
111  if (m_wTooltip)
112  GetGame().GetWorkspace().RemoveChild(m_wTooltip);
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  protected override void EOnFrame(IEntity owner, float timeSlice)
117  {
118  m_wWorkspace = GetGame().GetWorkspace();
119 
120  // Bail, deactivate, delete tooltip if hover widget is different or is gone
121  if (GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
122  m_wInteractableWidget = WidgetManager.GetWidgetUnderCursor();
123  else
124  m_wInteractableWidget = m_wWorkspace.GetFocusedWidget();
125 
127  {
129  ClearEventMask(EntityEvent.FRAME);
130  return;
131  }
132 
133  // Bail, deactivate if there is no tooltip any more (smth else deleted it or we deleted it)
134  if (!m_wTooltip)
135  {
136  ClearEventMask(EntityEvent.FRAME);
137  return;
138  }
139 
140  // Check for first render
141  if (!m_bIsRendered)
142  {
143  // Check if the widget has been rendered
144  float tooltipSizeX, tooltipSizeY;
145  m_wTooltip.GetScreenSize(tooltipSizeX, tooltipSizeY);
146  m_bIsRendered = tooltipSizeX != 0 && tooltipSizeY != 0;
147 
148  UpdatePosition(true);
149  return;
150  }
151 
152  // Update current tooltip position if required
153  if (m_bFollowCursor)
154  UpdatePosition();
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  protected void UpdatePosition(bool force = false)
159  {
160  vector goalPosition, goalAlignment, goalAlpha;
161  bool shouldUpdate = m_Preset.GetGoalPosition(m_wTooltip, m_wHoverWidget, goalPosition, goalAlignment, goalAlpha, force);
162  if (!shouldUpdate)
163  return;
164 
165  FrameSlot.SetAlignment(m_wTooltip, goalAlignment[0], goalAlignment[1]);
166  FrameSlot.SetPos(m_wTooltip, goalPosition[0], goalPosition[1]);
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  void SCR_TooltipManagerEntity(IEntitySource src, IEntity parent)
171  {
172  s_Instance = this;
173  SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
174  }
175 
176  //------------------------------------------------------------------------------------------------
178  {
180  }
181 }
SCR_ETooltipAlignmentHorizontal
SCR_ETooltipAlignmentHorizontal
Definition: SCR_ScriptedWidgetTooltip.c:775
m_Preset
protected ref SCR_ScriptedWidgetTooltipPreset m_Preset
Definition: SCR_TooltipManagerEntity.c:17
UpdatePosition
protected void UpdatePosition(bool force=false)
Definition: SCR_TooltipManagerEntity.c:158
TOOLTIP_Z_ORDER
const int TOOLTIP_Z_ORDER
Definition: SCR_TooltipManagerEntity.c:26
SCR_TooltipManagerEntity
void SCR_TooltipManagerEntity(IEntitySource src, IEntity parent)
Definition: SCR_TooltipManagerEntity.c:170
m_eHorizontalAlignment
protected SCR_ETooltipAlignmentHorizontal m_eHorizontalAlignment
Definition: SCR_TooltipManagerEntity.c:19
~SCR_TooltipManagerEntity
void ~SCR_TooltipManagerEntity()
Definition: SCR_TooltipManagerEntity.c:177
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_wTooltip
protected Widget m_wTooltip
Definition: SCR_TooltipManagerEntity.c:16
EOnFrame
protected override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_TooltipManagerEntity.c:116
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
m_bFollowCursor
protected bool m_bFollowCursor
Definition: SCR_TooltipManagerEntity.c:15
m_wHoverWidget
protected Widget m_wHoverWidget
Definition: SCR_TooltipManagerEntity.c:18
GetTooltip
Widget GetTooltip()
Definition: SCR_BrowserHoverTooltipComponent.c:297
SCR_TooltipManagerEntityClass
Definition: SCR_TooltipManagerEntity.c:6
m_eVerticalAlignment
protected SCR_ETooltipAlignmentVertical m_eVerticalAlignment
Definition: SCR_TooltipManagerEntity.c:20
m_wWorkspace
protected WorkspaceWidget m_wWorkspace
Definition: SCR_TooltipManagerEntity.c:24
m_wInteractableWidget
protected Widget m_wInteractableWidget
Definition: SCR_TooltipManagerEntity.c:23
Internal_CreateTooltip
protected Widget Internal_CreateTooltip(notnull SCR_ScriptedWidgetTooltipPreset preset, notnull Widget hoverWidget)
Definition: SCR_TooltipManagerEntity.c:84
m_bIsRendered
protected bool m_bIsRendered
Definition: SCR_TooltipManagerEntity.c:22
Internal_DeleteTooltip
protected void Internal_DeleteTooltip()
Definition: SCR_TooltipManagerEntity.c:109
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
s_Instance
SCR_TooltipManagerEntityClass s_Instance
CreateTooltip
Widget CreateTooltip()
Definition: SCR_BrowserHoverTooltipComponent.c:31