Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScriptedWidgetTooltip.c
Go to the documentation of this file.
1 /*
2 Parent class of Scripted Widgets Tooltips.
3 These tooltips are set on widgets themselves, in the Behaviour section.
4 In order to keep things orderly with the huge amount of tooltips required, and for ease of access, they can be defined in .conf files.
5 Create a .conf file from SCR_ScriptedWidgetTooltipPresets to define a group of tooltips, add members, and give each preset a unique tag.
6 In the Behaviour section of the widget you want to have a tooltip, pick this class, reference the .conf file and use the appropriate tag.
7 Don't forget to set Ignore Cursor to false or the tooltip won't trigger!
8 */
9 
10 void ScriptInvokerTooltipMethod(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag);
12 typedef ScriptInvokerBase<ScriptInvokerTooltipMethod> ScriptInvokerTooltip;
13 
14 //------------------------------------------------------------------------------------------------
15 class SCR_ScriptedWidgetTooltip : ScriptedWidgetTooltip
16 {
17  [Attribute(desc:"Class must be SCR_ScriptedWidgetTooltipPresets", params:"conf class=SCR_ScriptedWidgetTooltipPresets")]
18  protected ResourceName m_sPresetsConfig;
19 
20  [Attribute(desc:"tag to find the preset in the .conf")]
21  protected string m_sPresetTag;
22 
23  protected ref SCR_ScriptedWidgetTooltipPreset m_Preset;
24  protected WorkspaceWidget m_wWorkspace;
25  protected Widget m_wTooltipProxy;
26  protected Widget m_wHoverWidget;
27 
28  protected float m_fTargetPosition[2];
29 
30  // Content Widgets
31  protected RichTextWidget m_wMessage;
32 
33  // Const
34  protected const string WIDGET_MESSAGE = "Message";
35 
36  private const float DISTANCE_THRESHOLD = 0.001;
37 
38  // Static
39  protected static Widget m_wTooltipContent;
40  protected static WidgetAnimationPosition m_PositionAnimation;
41  protected static SCR_ScriptedWidgetTooltip m_CurrentTooltip;
42 
43  // Invokers
44  // Note that this is a bandaid solution because there is no other way to pass data to the tooltip class.
45  // If possible, only bind on hover/focus gained and make sure to unbind on lost.
46  protected static ref ScriptInvokerTooltip m_OnTooltipShowInit; // Called before creating the content widget, returns the proxy
47  protected static ref ScriptInvokerTooltip m_OnTooltipShow; // Called after creating the content widget, returns the content
48  protected static ref ScriptInvokerTooltip m_OnTooltipHide; // Called after removing the content widget, returns the proxy
49 
51  //------------------------------------------------------------------------------------------------
53  override static Widget CreateTooltipWidget()
54  {
55  return GetGame().GetWorkspace().CreateWidgets("{39445BE1E35BEA33}UI/layouts/Menus/Tooltips/TooltipBaseProxy.layout");
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
60  {
61  ForceHideCurrentTooltip();
62 
63  m_CurrentTooltip = this;
64 
65  // Create presets
66  Resource rsc = BaseContainerTools.LoadContainer(m_sPresetsConfig);
67  BaseContainer container = rsc.GetResource().ToBaseContainer();
68  SCR_ScriptedWidgetTooltipPresets presets = SCR_ScriptedWidgetTooltipPresets.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
69 
70  // Find preset
71  m_Preset = presets.FindPreset(m_sPresetTag);
72 
73  if (!m_Preset)
74  return;
75 
76  m_Preset.Init();
77 
78  // Setup
79  m_wWorkspace = pWorkspace;
80  m_wTooltipProxy = pToolTipWidget;
81 
82  if (GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
83  m_wHoverWidget = WidgetManager.GetWidgetUnderCursor();
84  else
85  m_wHoverWidget = pWorkspace.GetFocusedWidget();
86 
87  if(m_OnTooltipShowInit)
88  m_OnTooltipShowInit.Invoke(this, pToolTipWidget, m_wHoverWidget, m_Preset, m_Preset.m_sTag);
89 
90  // Proxy initialization
91  FrameSlot.SetAnchorMin(pToolTipWidget, 0, 0);
92  FrameSlot.SetAnchorMax(pToolTipWidget, 0, 0);
93 
94  FrameSlot.SetSize(pToolTipWidget, m_Preset.m_vSize[0], m_Preset.m_vSize[1]);
95  FrameSlot.SetSizeToContent(pToolTipWidget, m_Preset.m_bSizeToContent);
96 
97  Widget debugBorder = pToolTipWidget.FindAnyWidget("DebugBorder");
98  bool showDebug;
99 
100  #ifdef WORKBENCH
101  showDebug = m_Preset.m_bShowDebugBorder;
102  #endif
103 
104  if (debugBorder)
105  debugBorder.SetVisible(showDebug);
106 
107  m_wTooltipContent = m_wWorkspace.CreateWidgets(m_Preset.m_sContentLayout, GetContentWrapper());
108  if (!m_wTooltipContent)
109  return;
110 
111  // Determine and cache the correct content position inside the proxy
112  InitContentPosition();
113 
114  // Cache desired position and instantly place the tooltip there
115  UpdatePosition(true, false, true);
116 
117  // Content widgets setup
118  InitContents();
119 
120  // Fade in
121  if (m_Preset.m_fFadeInSpeed > 0)
122  {
123  m_wTooltipProxy.SetOpacity(0);
124  AnimateWidget.Opacity(m_wTooltipProxy, 1, m_Preset.m_fFadeInSpeed);
125  }
126 
128  SCR_MenuHelper.GetOnMenuOpen().Insert(OnMenuChange);
129  SCR_MenuHelper.GetOnMenuClose().Insert(OnMenuChange);
130  SCR_MenuHelper.GetOnTabChange().Insert(OnTabChange);
131 
132  // Invoker
133  if(m_OnTooltipShow)
134  m_OnTooltipShow.Invoke(this, m_wTooltipContent, m_wHoverWidget, m_Preset, m_Preset.m_sTag);
135 
136  // Tick - Used to update the tooltip's position
137  GetGame().GetCallqueue().CallLater(Update, m_Preset.m_fUpdateFrequency, true);
138 
139  // Super
140  super.Show(pWorkspace, pToolTipWidget, desiredPosX, desiredPosY);
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  override void Hide(WorkspaceWidget pWorkspace, Widget pToolTipWidget)
145  {
146  OnHide();
147 
148  super.Hide(pWorkspace, pToolTipWidget);
149  }
150 
152  //------------------------------------------------------------------------------------------------
153  protected void Update()
154  {
156  {
157  Clear();
158  return;
159  }
160 
161  UpdatePosition(m_Preset.m_bFollowCursor && GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE);
162 
163  if (!m_wTooltipProxy.IsVisible())
164  OnHide();
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  protected void OnHide()
169  {
170  Clear();
171 
172  if (m_OnTooltipHide)
173  m_OnTooltipHide.Invoke(this, m_wTooltipProxy, m_wHoverWidget, m_Preset, m_Preset.m_sTag);
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  protected void OnMenuChange(ChimeraMenuBase menu)
178  {
179  ForceHidden();
180  }
181 
182  //------------------------------------------------------------------------------------------------
183  protected void OnTabChange(ChimeraMenuBase menu)
184  {
185  ForceHidden();
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void Clear()
190  {
191  GetGame().GetCallqueue().Remove(Update);
192 
193  SCR_MenuHelper.GetOnMenuOpen().Remove(OnMenuChange);
194  SCR_MenuHelper.GetOnMenuClose().Remove(OnMenuChange);
195  SCR_MenuHelper.GetOnTabChange().Remove(OnTabChange);
196 
197  if (m_PositionAnimation)
198  m_PositionAnimation.Stop();
199 
200  if (m_wTooltipContent)
201  m_wTooltipContent.RemoveFromHierarchy();
202  }
203 
204  // Align the content to the correct side of the proxy
205  //------------------------------------------------------------------------------------------------
206  protected void InitContentPosition()
207  {
208  SCR_TooltipPositionPreset positionPreset = m_Preset.GetInputPositionSettings();
209  if (!positionPreset)
210  return;
211 
212  float targetX = positionPreset.GetContentAlignmentHorizontal();
213  float targetY = positionPreset.GetContentAlignmentVertical();
214 
215  FrameSlot.SetAlignment(m_wTooltipContent, targetX, targetY);
216  FrameSlot.SetAnchorMin(m_wTooltipContent, targetX, targetY);
217  FrameSlot.SetAnchorMax(m_wTooltipContent, targetX, targetY);
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  protected void InitContents()
222  {
223  m_wMessage = RichTextWidget.Cast(m_wTooltipProxy.FindAnyWidget(WIDGET_MESSAGE));
224  SetMessage(m_Preset.m_sMessageText);
225  }
226 
228  //------------------------------------------------------------------------------------------------
229  void UpdatePosition(bool followTarget = true, bool animate = true, bool force = false)
230  {
231  vector tooltipSize = m_Preset.GetTooltipSize(m_wTooltipProxy);
232  bool rendered = tooltipSize[0] != 0 && tooltipSize[1] != 0;
233 
234  vector goalPosition, goalAlignment, goalAlpha;
235 
236  bool shouldUpdate = m_Preset.GetGoalPosition(m_wTooltipContent, m_wHoverWidget, goalPosition, goalAlignment, goalAlpha, (!rendered || force));
237  if (!shouldUpdate)
238  return;
239 
240  // When the content layout is created, its size is 0.
241  // If the proxy is SizeToContent and the tooltip is stationary, we need to slide it in position as soon as we have access to its actual size.
242  if (followTarget || !rendered)
243  m_fTargetPosition = {goalPosition[0], goalPosition[1]};
244 
245  // -- Proxy --
246  // Move the Tooltip
247  vector tooltipPos = FrameSlot.GetPos(m_wTooltipProxy);
248 
249  // Alignment
250  FrameSlot.SetAlignment(m_wTooltipProxy, goalAlignment[0], goalAlignment[1]);
251 
252  // Position
253  if (!animate)
254  FrameSlot.SetPos(m_wTooltipProxy, goalPosition[0], goalPosition[1]);
255 
256  else if (vector.DistanceSq(Vector(tooltipPos[0], tooltipPos[1], 0), Vector(m_fTargetPosition[0], m_fTargetPosition[1], 0)) >= DISTANCE_THRESHOLD)
257  m_PositionAnimation = AnimateWidget.Position(m_wTooltipProxy, m_fTargetPosition, m_Preset.m_fInterpolationSpeed);
258 
259  // -- Content --
260  // Move the content to the correct edge of the proxy
261  if (!m_wTooltipContent)
262  return;
263 
264  FrameSlot.SetAlignment(m_wTooltipContent, goalAlignment[0], goalAlignment[1]);
265  FrameSlot.SetAnchorMin(m_wTooltipContent, goalAlignment[0], goalAlignment[1]);
266  FrameSlot.SetAnchorMax(m_wTooltipContent, goalAlignment[0], goalAlignment[1]);
267  }
268 
269  //------------------------------------------------------------------------------------------------
270  bool SetMessage(string message)
271  {
272  if (!m_wMessage)
273  return false;
274 
275  m_wMessage.SetText(message);
276  return true;
277  }
278 
279  //------------------------------------------------------------------------------------------------
280  bool ResetMessage()
281  {
282  return SetMessage(GetDefaultMessage());
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  bool SetMessageColor(Color color)
287  {
288  if (!m_wMessage || !color)
289  return false;
290 
291  m_wMessage.SetColor(color);
292  return true;
293  }
294 
295  //------------------------------------------------------------------------------------------------
296  string GetMessage()
297  {
298  if (!m_wMessage)
299  return string.Empty;
300 
301  return m_wMessage.GetText();
302  }
303 
304  //------------------------------------------------------------------------------------------------
305  string GetDefaultMessage()
306  {
307  return m_Preset.m_sDefaultMessage;
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  string GetTag()
312  {
313  return m_Preset.m_sTag;
314  }
315 
316  //------------------------------------------------------------------------------------------------
317  bool IsVisible()
318  {
319  return m_wTooltipProxy && m_Preset && m_wTooltipProxy.IsVisible();
320  }
321 
322  //------------------------------------------------------------------------------------------------
323  void ForceHidden()
324  {
325  if (!m_wTooltipProxy)
326  return;
327 
328  m_wTooltipProxy.SetVisible(false);
329  OnHide();
330  }
331 
332  //------------------------------------------------------------------------------------------------
333  Widget GetContentWidget()
334  {
336  }
337 
338  //------------------------------------------------------------------------------------------------
339  Widget GetTooltipWidget()
340  {
342  }
343 
344  //------------------------------------------------------------------------------------------------
345  Widget GetHoverWidget()
346  {
347  return m_wHoverWidget;
348  }
349 
350  //------------------------------------------------------------------------------------------------
352  Widget GetContentWrapper()
353  {
354  return m_wTooltipProxy;
355  }
356 
357  //------------------------------------------------------------------------------------------------
358  static bool ForceHideCurrentTooltip()
359  {
360  if (!m_CurrentTooltip)
361  return false;
362 
363  m_CurrentTooltip.ForceHidden();
364  return true;
365  }
366 
367  //------------------------------------------------------------------------------------------------
368  static SCR_ScriptedWidgetTooltip GetCurrentTooltip()
369  {
370  return m_CurrentTooltip;
371  }
372 
373  //------------------------------------------------------------------------------------------------
374  static ScriptInvokerTooltip GetOnTooltipShowInit()
375  {
376  if (!m_OnTooltipShowInit)
377  m_OnTooltipShowInit = new ScriptInvokerTooltip();
378 
379  return m_OnTooltipShowInit;
380  }
381 
382  //------------------------------------------------------------------------------------------------
383  static ScriptInvokerTooltip GetOnTooltipShow()
384  {
385  if (!m_OnTooltipShow)
386  m_OnTooltipShow = new ScriptInvokerTooltip();
387 
388  return m_OnTooltipShow;
389  }
390 
391  //------------------------------------------------------------------------------------------------
392  static ScriptInvokerTooltip GetOnTooltipHide()
393  {
394  if (!m_OnTooltipHide)
395  m_OnTooltipHide = new ScriptInvokerTooltip();
396 
397  return m_OnTooltipHide;
398  }
399 }
400 
401 
402 //------------------------------------------------------------------------------------------------
403 //------------------------------------------------------------------------------------------------
406 class SCR_ScriptedWidgetTooltipPreset
407 {
408  [Attribute("", UIWidgets.Auto, "Custom tag, used for finding this preset at run time.")]
409  string m_sTag;
410 
411  [Attribute("{197FC671D07413E9}UI/layouts/Menus/Tooltips/Tooltip_SimpleMessage.layout", UIWidgets.ResourceNamePicker, ".layout for the content of the Tooltip", params: "layout")]
412  ResourceName m_sContentLayout;
413 
414  [Attribute()]
415  ref SCR_TooltipPositionPreset m_MousePositionSettings;
416 
417  [Attribute()]
418  ref SCR_TooltipPositionPreset m_GamepadPositionSettings;
419 
420  [Attribute("1", UIWidgets.CheckBox, "Defines if the tooltip should animate to follow mouse cursor or remain at initial position")]
421  bool m_bFollowCursor;
422 
423  [Attribute(desc: "Fixed Absolute screen position")]
424  vector m_vFixedPosition;
425 
426  [Attribute("0", UIWidgets.CheckBox, desc: "Should the proxy adapt to the content: the proxy is used to check for overflowing and contains the actual Content layout. Giving it a fixed size will prevent slide in effect for overflowing tooltips. This will NOT influence the look of the comntent layout, as long as it fits inside the proxy and it's not set to stretch")]
427  bool m_bSizeToContent;
428 
429  [Attribute(desc: "Fixed proxy layout size. The proxy is used to check for overflowing and contains the actual Content layout. This will NOT influence the look of the comntent layout, as long as it fits inside the proxy and it's not set to stretch")]
430  vector m_vSize;
431 
432  [Attribute("", desc: "Message to display")]
433  string m_sMessageText;
434 
435  [Attribute(UIConstants.FADE_RATE_FAST.ToString(), desc: "FadeIn speed. Set to 0 to skip the animation")]
436  float m_fFadeInSpeed;
437 
438  [Attribute(UIConstants.FADE_RATE_SUPER_FAST.ToString(), desc: "Movement speed")]
439  float m_fInterpolationSpeed;
440 
441  [Attribute("40", desc: "Queued update delay in ms")]
442  float m_fUpdateFrequency;
443 
444  [Attribute("0", UIWidgets.CheckBox)]
445  bool m_bShowDebugBorder;
446 
447  string m_sDefaultMessage;
448 
449  //------------------------------------------------------------------------------------------------
450  void Init()
451  {
452  m_sDefaultMessage = m_sMessageText;
453  }
454 
455  //------------------------------------------------------------------------------------------------
458  bool GetGoalPosition(Widget tooltipContent, Widget hoverWidget, out vector goalPosition, out vector goalAlignment, out vector goalAlpha, bool force = false)
459  {
460  vector tooltipSize = GetTooltipSize(tooltipContent);
461  SCR_TooltipPositionPreset positionSettings = GetInputPositionSettings();
462 
463  if (positionSettings.m_eAnchor != SCR_ETooltipAnchor.CURSOR && !force)
464  return false;
465 
466  positionSettings.GetGoalPosition(tooltipSize, hoverWidget, m_vFixedPosition, goalPosition, goalAlignment, goalAlpha);
467  return true;
468  }
469 
470  //------------------------------------------------------------------------------------------------
471  vector GetTooltipSize(Widget tooltip)
472  {
473  vector size;
474  WorkspaceWidget workspace = GetGame().GetWorkspace();
475 
476  // Tooltip size - SCALED
477  float xTooltipSize = workspace.DPIScale(m_vSize[0]);
478  float yTooltipSize = workspace.DPIScale(m_vSize[1]);
479  if (m_bSizeToContent && tooltip)
480  tooltip.GetScreenSize(xTooltipSize, yTooltipSize);
481 
482  size[0] = xTooltipSize;
483  size[1] = yTooltipSize;
484  return size;
485  }
486 
487  //------------------------------------------------------------------------------------------------
488  SCR_TooltipPositionPreset GetInputPositionSettings()
489  {
490  bool isUsingMouse = GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE;
491  if (isUsingMouse)
492  return m_MousePositionSettings;
493  else
494  return m_GamepadPositionSettings;
495  }
496 }
497 
498 
499 //------------------------------------------------------------------------------------------------
501 [BaseContainerProps(configRoot : true)]
503 {
504  [Attribute()]
505  ref array<ref SCR_ScriptedWidgetTooltipPreset> m_aPresets;
506 
507  //------------------------------------------------------------------------------------------------
509  SCR_ScriptedWidgetTooltipPreset FindPreset(string tag)
510  {
511  foreach (SCR_ScriptedWidgetTooltipPreset preset : m_aPresets)
512  {
513  if (preset.m_sTag == tag)
514  return preset;
515  }
516 
517  return null;
518  }
519 }
520 
521 
522 //------------------------------------------------------------------------------------------------
523 //------------------------------------------------------------------------------------------------
524 [BaseContainerProps(configRoot : true)]
525 class SCR_TooltipPositionPreset
526 {
527  [Attribute("0", UIWidgets.ComboBox, "Where to position the Tooltip", "", ParamEnumArray.FromEnum(SCR_ETooltipAnchor))]
528  SCR_ETooltipAnchor m_eAnchor;
529 
530  [Attribute("0", UIWidgets.ComboBox, "Horizontal Alignment", "", ParamEnumArray.FromEnum(SCR_ETooltipAlignmentHorizontal))]
532 
533  [Attribute("0", UIWidgets.ComboBox, "Vertical Alignment", "", ParamEnumArray.FromEnum(SCR_ETooltipAlignmentVertical))]
534  SCR_ETooltipAlignmentVertical m_eVerticalAlignment;
535 
536  [Attribute("8 20 0", desc: "Tooltip offset from cursor or desired position")]
537  vector m_vOffset;
538 
539  [Attribute("0", UIWidgets.ComboBox, "How to deal with overflow", "", ParamEnumArray.FromEnum(SCR_ETooltipOverflowHandling))]
540  SCR_ETooltipOverflowHandling m_eOverflowHandling;
541 
542  const float ALIGNMENT_CENTER = 0.5;
543  const float ALIGNMENT_LEFT_TOP = 0;
544  const float ALIGNMENT_RIGHT_DOWN = 1;
545 
546  //------------------------------------------------------------------------------------------------
548  void GetGoalPosition(vector tooltipSize, Widget hoverWidget, vector absolutePosition, out vector goalPosition, out vector goalAlignment, out vector goalAlpha)
549  {
550  float xHover, yHover;
551  float xHoverSize, yHoverSize;
552 
553  if (hoverWidget)
554  {
555  // Hover widget position - SCALED
556  hoverWidget.GetScreenPos(xHover, yHover);
557 
558  // Hover widget size - SCALED
559  hoverWidget.GetScreenSize(xHoverSize, yHoverSize);
560  }
561 
562  // Cursor position - SCALED
563  int xCursor, yCursor;
564  WidgetManager.GetMousePos(xCursor, yCursor);
565 
566  // Workspace size - SCALED
567  WorkspaceWidget workspace = GetGame().GetWorkspace();
568  float xWorkspaceSize, yWorkspaceSize;
569  workspace.GetScreenSize(xWorkspaceSize, yWorkspaceSize);
570 
571  // Calculations setup
572  float xOffset = m_vOffset[0];
573  float yOffset = m_vOffset[1];
574 
575  float xGoal, yGoal;
576  float xAlignment, yAlignment;
577  float xTargetSize, yTargetSize;
578 
579  switch (m_eAnchor)
580  {
581  case SCR_ETooltipAnchor.CURSOR:
582  xGoal = xCursor;
583  yGoal = yCursor;
584  break;
585 
586  case SCR_ETooltipAnchor.HOVERED_WIDGET:
587  xGoal = xHover;
588  yGoal = yHover;
589  xTargetSize = xHoverSize;
590  yTargetSize = yHoverSize;
591  break;
592 
593  case SCR_ETooltipAnchor.ABSOLUTE:
594  xGoal = absolutePosition[0];
595  yGoal = absolutePosition[1];
596  break;
597  }
598 
599  CalculateGoalPosition(m_eHorizontalAlignment, xTargetSize, tooltipSize[0], xWorkspaceSize, xGoal, xOffset, xAlignment);
600  CalculateGoalPosition(m_eVerticalAlignment, yTargetSize, tooltipSize[1], yWorkspaceSize, yGoal, yOffset, yAlignment);
601 
602  // Set the alpha - SCALED - for anchors related to workspace size, as an alternative to screen position
603  if (xWorkspaceSize == 0)
604  xWorkspaceSize = 1;
605 
606  if (yWorkspaceSize == 0)
607  yWorkspaceSize = 1;
608 
609  goalAlpha[0] = (xGoal + workspace.DPIScale(xOffset)) / xWorkspaceSize;
610  goalAlpha[1] = (yGoal + workspace.DPIScale(yOffset)) / yWorkspaceSize;
611 
612  // Set the goals - UNSCALED
613  goalPosition[0] = workspace.DPIUnscale(xGoal + workspace.DPIScale(xOffset));
614  goalPosition[1] = workspace.DPIUnscale(yGoal + workspace.DPIScale(yOffset));
615 
616  // Set the desired Alignment
617  goalAlignment[0] = xAlignment;
618  goalAlignment[1] = yAlignment;
619  }
620 
621  //------------------------------------------------------------------------------------------------
622  protected void CalculateGoalPosition(int alignmentCase, float targetSize, float tooltipSize, float maxAreaSize, inout float desiredPos, inout float offset, inout float alignment)
623  {
624  switch (alignmentCase)
625  {
626  case 0:
627  break;
628 
629  case 1:
630  desiredPos = desiredPos + (targetSize * ALIGNMENT_CENTER);
631  alignment = ALIGNMENT_CENTER;
632  break;
633 
634  case 2:
635  desiredPos = desiredPos + targetSize;
636  alignment = ALIGNMENT_RIGHT_DOWN;
637  break;
638 
639  case 3:
640  alignment = ALIGNMENT_RIGHT_DOWN;
641  break;
642 
643  case 4:
644  desiredPos = desiredPos + targetSize;
645  break;
646  }
647 
648  CheckOverflow(tooltipSize, maxAreaSize, desiredPos, offset, alignment);
649  }
650 
651  //------------------------------------------------------------------------------------------------
654  bool CheckOverflow(float tooltipSize, float maxAreaSize, inout float desiredPos, inout float offset, inout float alignment)
655  {
656  SCR_ETooltipOverflowType overflowType;
657 
658  // Extending to the right of the position
659  if (alignment < ALIGNMENT_CENTER && desiredPos + offset + tooltipSize > maxAreaSize)
660  {
661  overflowType = SCR_ETooltipOverflowType.RIGHT;
662  }
663 
664  // Extending to the left of the position
665  else if (alignment > ALIGNMENT_CENTER && desiredPos + offset - tooltipSize < 0)
666  {
667  overflowType = SCR_ETooltipOverflowType.LEFT;
668  }
669 
670  // Center
671  else
672  {
673  if (desiredPos + offset + (tooltipSize * ALIGNMENT_CENTER) > maxAreaSize)
674  overflowType = SCR_ETooltipOverflowType.CENTER_RIGHT;
675 
676 
677  else if (desiredPos + offset - (tooltipSize * ALIGNMENT_CENTER) < 0)
678  overflowType = SCR_ETooltipOverflowType.CENTER_LEFT;
679  }
680 
681  if (overflowType == SCR_ETooltipOverflowType.NONE)
682  return false;
683 
684  // -- Handle overflow --
685  // Invert
686  if (m_eOverflowHandling == SCR_ETooltipOverflowHandling.INVERT)
687  {
688  if (alignment == ALIGNMENT_CENTER)
689  desiredPos = Math.Clamp(desiredPos, offset + (tooltipSize * ALIGNMENT_CENTER), maxAreaSize - (offset + (tooltipSize * ALIGNMENT_CENTER)));
690 
691  alignment = 1 - alignment;
692  }
693 
694  // Stop
695  else
696  {
697  switch (overflowType)
698  {
699  case SCR_ETooltipOverflowType.LEFT: desiredPos = tooltipSize + offset; break;
700  case SCR_ETooltipOverflowType.RIGHT: desiredPos = maxAreaSize - tooltipSize - offset; break;
701  case SCR_ETooltipOverflowType.CENTER_LEFT: desiredPos = (tooltipSize * ALIGNMENT_CENTER) + offset; break;
702  case SCR_ETooltipOverflowType.CENTER_RIGHT: desiredPos = maxAreaSize - (tooltipSize * ALIGNMENT_CENTER) - offset; break;
703  }
704  }
705 
706  return true;
707  }
708 
709  //------------------------------------------------------------------------------------------------
710  float GetContentAlignmentHorizontal()
711  {
712  switch (m_eHorizontalAlignment)
713  {
714  case SCR_ETooltipAlignmentHorizontal.LEFT: return ALIGNMENT_LEFT_TOP;
715  case SCR_ETooltipAlignmentHorizontal.RIGHT: return ALIGNMENT_RIGHT_DOWN;
716  case SCR_ETooltipAlignmentHorizontal.CENTER: return ALIGNMENT_CENTER;
717  case SCR_ETooltipAlignmentHorizontal.SIDE_LEFT: return ALIGNMENT_LEFT_TOP;
718  case SCR_ETooltipAlignmentHorizontal.SIDE_RIGHT: return ALIGNMENT_RIGHT_DOWN;
719  }
720 
721  return ALIGNMENT_LEFT_TOP;
722  }
723 
724  //------------------------------------------------------------------------------------------------
725  float GetContentAlignmentVertical()
726  {
727  switch (m_eVerticalAlignment)
728  {
729  case SCR_ETooltipAlignmentVertical.TOP: return ALIGNMENT_LEFT_TOP;
730  case SCR_ETooltipAlignmentVertical.ABOVE: return ALIGNMENT_RIGHT_DOWN;
731  case SCR_ETooltipAlignmentVertical.BELOW: return ALIGNMENT_LEFT_TOP;
732  case SCR_ETooltipAlignmentVertical.BOTTOM: return ALIGNMENT_RIGHT_DOWN;
733  case SCR_ETooltipAlignmentVertical.CENTER: return ALIGNMENT_CENTER;
734  }
735 
736  return ALIGNMENT_LEFT_TOP;
737  }
738 }
739 
740 //------------------------------------------------------------------------------------------------
741 //------------------------------------------------------------------------------------------------
742 /*
743 LEFT:
744  __
745  |__|_____
746  | |
747  |________|
748 
749 
750 CENTER:
751  __
752  __|__|__
753  | |
754  |________|
755 
756 
757 RIGHT:
758  __
759  _____|__|
760  | |
761  |________|
762 
763 
764 SIDE_LEFT:
765  __ ________
766  |__| |
767  |________|
768 
769 
770 SIDE_RIGHT:
771  ________ __
772  | |__|
773  |________|
774 */
776 {
782 }
783 
784 //------------------------------------------------------------------------------------------------
785 /*
786 TOP:
787  ________
788  | |__| |
789  |________|
790 
791 
792 CENTER:
793  ________
794  | __ |
795  |________|
796 
797 
798 BOTTOM:
799  ________
800  | __ |
801  |__|__|__|
802 
803 
804 ABOVE:
805  __
806  __|__|__
807  | |
808  |________|
809 
810 
811 BELOW:
812  ________
813  | |
814  |________|
815  |__|
816 */
817 enum SCR_ETooltipAlignmentVertical
818 {
819  TOP,
820  CENTER,
821  BOTTOM,
822  ABOVE,
823  BELOW
824 }
825 
826 //------------------------------------------------------------------------------------------------
827 enum SCR_ETooltipAnchor
828 {
829  CURSOR,
831  ABSOLUTE
832 }
833 
834 //------------------------------------------------------------------------------------------------
835 enum SCR_ETooltipOverflowHandling
836 {
837  INVERT,
838  STOP
839 }
840 
841 //------------------------------------------------------------------------------------------------
842 enum SCR_ETooltipOverflowType
843 {
844  NONE,
845  LEFT,
846  RIGHT,
847  CENTER_LEFT,
849 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
SCR_ETooltipAlignmentHorizontal
SCR_ETooltipAlignmentHorizontal
Definition: SCR_ScriptedWidgetTooltip.c:775
NONE
enum SCR_ETooltipAlignmentHorizontal NONE
CENTER_RIGHT
SCR_ScrollBarComponent CENTER_RIGHT
m_sPresetTag
protected string m_sPresetTag
Definition: SCR_ScriptedWidgetTooltip.c:17
ScriptInvokerTooltip
ScriptInvokerBase< ScriptInvokerTooltipMethod > ScriptInvokerTooltip
Definition: SCR_ScriptedWidgetTooltip.c:12
m_eHorizontalAlignment
protected SCR_ETooltipAlignmentHorizontal m_eHorizontalAlignment
Definition: SCR_TooltipManagerEntity.c:19
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
STOP
@ STOP
Definition: SCR_AICombatMoveRequest.c:4
CENTER_LEFT
enum SCR_ETooltipAlignmentHorizontal CENTER_LEFT
LEFT
enum SCR_ETooltipAlignmentHorizontal LEFT
Definition: SCR_ScriptedWidgetTooltip.c:777
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
ScriptInvokerTooltipMethod
func ScriptInvokerTooltipMethod
Definition: SCR_ScriptedWidgetTooltip.c:11
m_wMessage
protected RichTextWidget m_wMessage
Definition: SCR_BrowserHoverTooltipComponent.c:24
func
func
Definition: SCR_AIThreatSystem.c:5
Init
void Init(IEntity entity=null, vector worldPos=vector.Zero, float timestamp=0.0, EAITargetInfoCategory category=0)
Definition: SCR_AITargetInfo.c:27
m_bFollowCursor
protected bool m_bFollowCursor
Definition: SCR_TooltipManagerEntity.c:15
m_wHoverWidget
protected Widget m_wHoverWidget
Definition: SCR_ScriptedWidgetTooltip.c:22
WIDGET_MESSAGE
const protected string WIDGET_MESSAGE
Definition: SCR_ScriptedWidgetTooltip.c:30
TOP
enum SCR_ETooltipAlignmentHorizontal TOP
ABOVE
enum SCR_ETooltipAlignmentHorizontal ABOVE
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_eVerticalAlignment
protected SCR_ETooltipAlignmentVertical m_eVerticalAlignment
Definition: SCR_TooltipManagerEntity.c:20
SIDE_RIGHT
@ SIDE_RIGHT
Definition: SCR_ScriptedWidgetTooltip.c:781
m_wTooltipContent
protected Widget m_wTooltipContent
Definition: SCR_BrowserHoverTooltipComponent.c:21
RIGHT
enum SCR_ETooltipAlignmentHorizontal RIGHT
Definition: SCR_ScriptedWidgetTooltip.c:779
m_Preset
ref SCR_ScriptedWidgetTooltipPreset m_Preset
Definition: SCR_BrowserHoverTooltipComponent.c:3
HOVERED_WIDGET
enum SCR_ETooltipAlignmentHorizontal HOVERED_WIDGET
m_sPresetsConfig
protected ResourceName m_sPresetsConfig
Definition: SCR_ScriptedWidgetTooltip.c:14
m_aPresets
ref array< ref SCR_ScriptedWidgetTooltipPreset > m_aPresets
Definition: SCR_ScriptedWidgetTooltip.c:407
m_fTargetPosition
protected float m_fTargetPosition[2]
Definition: SCR_ScriptedWidgetTooltip.c:24
SIDE_LEFT
@ SIDE_LEFT
Definition: SCR_ScriptedWidgetTooltip.c:780
SCR_ScriptedWidgetTooltipPresets
Class for a .conf file with multiple Tooltip presets.
Definition: SCR_ScriptedWidgetTooltip.c:502
SCR_MenuHelper
Definition: SCR_MenuHelper.c:15
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
CURSOR
enum SCR_ETooltipAlignmentHorizontal CURSOR
m_wTooltipProxy
protected Widget m_wTooltipProxy
Definition: SCR_ScriptedWidgetTooltip.c:21
BOTTOM
enum SCR_ETooltipAlignmentHorizontal BOTTOM
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
INVERT
enum SCR_ETooltipAlignmentHorizontal INVERT
m_fFadeInSpeed
protected float m_fFadeInSpeed
Definition: SCR_TooltipManagerEditorUIComponent.c:11
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
BaseContainerProps
SCR_ScriptedWidgetTooltip ScriptedWidgetTooltip BaseContainerProps(configRoot :true)
Configuration for a Tooltip.
Definition: SCR_ScriptedWidgetTooltip.c:524
SCR_BaseContainerCustomTitleField
SCR_ScriptedWidgetTooltip ScriptedWidgetTooltip SCR_BaseContainerCustomTitleField("m_sTag")
Definition: SCR_ScriptedWidgetTooltip.c:405
m_wWorkspace
private WorkspaceWidget m_wWorkspace
Definition: SCR_CursorEditorUIComponent.c:17
m_vOffset
protected vector m_vOffset
Definition: SCR_PositionalInsectType.c:11
CENTER
enum SCR_ETooltipAlignmentHorizontal CENTER
Definition: SCR_ScriptedWidgetTooltip.c:778