Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BrowserHoverTooltipComponent.c
Go to the documentation of this file.
2 {
4  ref SCR_ScriptedWidgetTooltipPreset m_Preset;
5 
6  [Attribute("{87037226B1A2064B}UI/layouts/WidgetLibrary/Buttons/WLib_NavigationButtonSuperSmall.layout", params:"layout")]
7  protected ResourceName m_sButtonsLayout;
8 
9  [Attribute(desc: "Actions to be shown in the Tooltip")]
10  protected ref array<ref SCR_BrowserTooltipButtonPresetData> m_aButtons;
11 
12  [Attribute("1.000000 1.000000 1.000000 1.000000", UIWidgets.ColorPicker)] //0.508995 0.508995 0.502998 1.000000
13  protected ref Color m_ButtonsColor;
14 
15  [Attribute("1")]
16  protected float m_fButtonsOpacity;
17 
18  [Attribute("12", desc: "Spacing between each button")]
19  protected int m_iButtonsPadding;
20 
21  protected Widget m_wTooltip;
22  protected Widget m_wTooltipContent;
23  protected Widget m_wInputsLayout;
24  protected Widget m_wMessageLayout;
25  protected RichTextWidget m_wMessage;
26 
27  protected ref array<ref SCR_BrowserTooltipButtonPresetData> m_aScriptButtons = {};
28  protected ref map<string, SCR_InputButtonComponent> m_aButtonComponents = new map<string, SCR_InputButtonComponent>();
29 
30 
31  //------------------------------------------------------------------------------------------------
32  Widget CreateTooltip()
33  {
34  if(!m_Preset)
35  return null;
36 
37  SCR_ETooltipAlignmentHorizontal horizontalAlignment;
38  SCR_ETooltipAlignmentVertical verticalAlignment;
39  vector offset = vector.Zero;
40 
43 
44  if (!m_wTooltip)
45  return null;
46 
48  m_wMessageLayout = m_wTooltip.FindAnyWidget("MessageLayout");
49  if (m_wMessageLayout)
50  m_wMessage = RichTextWidget.Cast(m_wMessageLayout.FindAnyWidget("Message"));
51 
52  SetMessage(m_Preset.m_sMessageText);
53 
55  m_wInputsLayout = m_wTooltip.FindAnyWidget("InputsLayout");
56 
58  m_aButtonComponents.Clear();
59 
60  int count;
61  int padding;
62  foreach (SCR_BrowserTooltipButtonPresetData buttonPreset : m_aButtons)
63  {
64  if (count != 0)
65  padding = m_iButtonsPadding;
66 
67  CreateButton(buttonPreset, m_wInputsLayout, padding);
68  count++;
69  }
70 
71  return m_wTooltip;
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  void ForceDeleteTooltip()
76  {
77  SCR_TooltipManagerEntity.DeleteTooltip();
78  }
79 
80  //------------------------------------------------------------------------------------------------
81  protected SCR_InputButtonComponent CreateButton(SCR_BrowserTooltipButtonPresetData buttonPreset, Widget buttonContainer, int padding)
82  {
83  if (!m_wTooltip || !buttonContainer)
84  return null;
85 
87  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sButtonsLayout, buttonContainer);
88  if (!w)
89  return null;
90 
92  AlignableSlot.SetPadding(w, padding, 0, 0, 0);
93 
96  if (!comp)
97  {
98  GetGame().GetWorkspace().RemoveChild(w);
99  return null;
100  }
101 
102  comp.SetVisible(buttonPreset.m_bShowButton, false);
103  comp.SetLabel(buttonPreset.m_sLabel);
104  comp.SetAction(buttonPreset.UpdateDisplayedAction());
105  comp.SetColorActionDisabled(m_ButtonsColor);
106  comp.SetDisabledOpacity(m_fButtonsOpacity);
107  comp.SetEnabled(false);
108 
110  m_aButtonComponents.Insert(buttonPreset.m_sTag, comp);
111 
112  return comp;
113  }
114 
115  //------------------------------------------------------------------------------------------------
117  SCR_InputButtonComponent FindButton(string tag)
118  {
119  return m_aButtonComponents.Get(tag);
120  }
121 
122 
123  //------------------------------------------------------------------------------------------------
125  SCR_BrowserTooltipButtonPresetData FindButtonPresetData(string tag)
126  {
127  foreach (SCR_BrowserTooltipButtonPresetData button : m_aButtons)
128  {
129  if (button.m_sTag == tag)
130  return button;
131  }
132 
133  return null;
134  }
135 
136  //------------------------------------------------------------------------------------------------
138  SCR_InputButtonComponent AddButton(string tag, string label, string actionName, string actionNameMouse = string.Empty, bool showButton = true)
139  {
141  if (!m_wTooltip)
142  return null;
143 
144  SCR_BrowserTooltipButtonPresetData buttonPreset = new SCR_BrowserTooltipButtonPresetData();
145  buttonPreset.SetData(tag, label, actionName, actionNameMouse, showButton);
146 
148  int padding;
149  if (!m_aButtonComponents.IsEmpty())
150  padding = m_iButtonsPadding;
151 
152  SCR_InputButtonComponent newButton = CreateButton(buttonPreset, m_wInputsLayout, padding);
153  return newButton;
154  }
155 
156  //------------------------------------------------------------------------------------------------
158  bool RemoveButton(string tag)
159  {
160  if (!m_wTooltip)
161  return false;
162 
163  SCR_InputButtonComponent button = FindButton(tag);
164 
165  if (!button)
166  return false;
167 
168  m_aButtonComponents.Remove(tag);
169  m_wTooltip.RemoveChild(button.GetRootWidget());
170  return true;
171  }
172 
173 
174  //------------------------------------------------------------------------------------------------
176  SCR_BrowserTooltipButtonPresetData AddSetupButton(string tag, string label, string actionName, string actionNameMouse = string.Empty, bool showButton = true)
177  {
178  SCR_BrowserTooltipButtonPresetData buttonPreset = new SCR_BrowserTooltipButtonPresetData;
179  buttonPreset.SetData(tag, label, actionName, actionNameMouse, showButton);
180 
182  foreach (SCR_BrowserTooltipButtonPresetData button : m_aButtons)
183  {
184  if (button.m_sTag == tag)
185  return null;
186  }
187 
188  m_aScriptButtons.Insert(buttonPreset);
189  m_aButtons.Insert(buttonPreset);
190  return buttonPreset;
191  }
192 
193  //------------------------------------------------------------------------------------------------
195  bool RemoveSetupButton(string tag)
196  {
197  foreach (SCR_BrowserTooltipButtonPresetData buttonPreset : m_aScriptButtons)
198  {
199  if (tag == buttonPreset.m_sTag)
200  {
201  m_aScriptButtons.RemoveItem(buttonPreset);
202  m_aButtons.RemoveItem(buttonPreset);
203  return true;
204  }
205  }
206 
207  return false;
208  }
209 
210  //------------------------------------------------------------------------------------------------
212  void ClearSetupButtons()
213  {
214  foreach (SCR_BrowserTooltipButtonPresetData buttonPreset : m_aScriptButtons)
215  {
216  m_aButtons.RemoveItem(buttonPreset);
217  }
218 
219  m_aScriptButtons.Clear();
220  }
221 
222  //------------------------------------------------------------------------------------------------
224  void UpdateAllButtonActions()
225  {
226  foreach (SCR_BrowserTooltipButtonPresetData buttonData : m_aButtons)
227  {
228  UpdateButtonAction(buttonData.m_sTag);
229  }
230  }
231 
232  //------------------------------------------------------------------------------------------------
234  void UpdateButtonAction(string tag)
235  {
236  //Button settings
237  SCR_BrowserTooltipButtonPresetData buttonData = FindButtonPresetData(tag);
238 
239  if (!buttonData)
240  return;
241 
242  string actionName = buttonData.UpdateDisplayedAction();
243  SCR_InputButtonComponent button = FindButton(tag);
244  if (button)
245  button.SetAction(actionName);
246  }
247 
248 
249  //------------------------------------------------------------------------------------------------
250  static SCR_BrowserHoverTooltipComponent FindComponent(notnull Widget w)
251  {
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  bool SetMessage(string message)
257  {
258  m_Preset.m_sMessageText = message;
259 
260  if (!m_wMessage)
261  return false;
262 
263  m_wMessage.SetText(message);
264  SetMessageVisible(!message.IsEmpty());
265  return true;
266  }
267 
268  //------------------------------------------------------------------------------------------------
269  bool SetMessageVisible(bool newVisible)
270  {
271  if (!m_wMessageLayout)
272  return false;
273 
274  bool visible = newVisible && !GetMessage().IsEmpty();
275 
276  m_wMessageLayout.SetVisible(visible);
277 
279  if (!m_aButtons.IsEmpty())
280  AlignableSlot.SetPadding(m_wMessageLayout, m_iButtonsPadding, 0, 0, 0);
281 
282  return true;
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  string GetMessage()
287  {
288  return m_Preset.m_sMessageText;
289  }
290 
291  //------------------------------------------------------------------------------------------------
292  bool IsMessageVisible()
293  {
294  return m_wMessageLayout && m_wMessageLayout.IsVisible();
295  }
296 
297  //------------------------------------------------------------------------------------------------
298  Widget GetTooltip()
299  {
300  return SCR_TooltipManagerEntity.GetTooltip();
301  }
302 }
303 
304 //------------------------------------------------------------------------------------------------
307 class SCR_BrowserTooltipButtonPresetData
308 {
309  [Attribute(desc: "Custom tag, used for finding this button at run time")]
310  string m_sTag;
311 
312  [Attribute(desc: "Label of the button")]
313  string m_sLabel;
314 
315  [Attribute(desc: "Action name the button will display")]
316  string m_sActionName;
317 
318  [Attribute(desc: "Action name the button will display when using mouse")]
319  string m_sActionNameMouse;
320 
321  [Attribute("1")]
322  bool m_bShowButton;
323 
324  protected string m_sActionToDisplay;
325 
326  //------------------------------------------------------------------------------------------------
327  void SetData(string tag, string label, string actionName, string actionNameMouse, bool showButton)
328  {
329  m_sTag = tag;
330  m_sLabel = label;
331  m_sActionName = actionName;
332  m_sActionNameMouse = actionNameMouse;
333  m_bShowButton = showButton;
334  }
335 
336  //------------------------------------------------------------------------------------------------
337  string GetDisplayedAction()
338  {
339  return m_sActionToDisplay;
340  }
341 
342  //------------------------------------------------------------------------------------------------
343  string UpdateDisplayedAction()
344  {
347 
348  EInputDeviceType inputDeviceType = GetGame().GetInputManager().GetLastUsedInputDevice();
349 
350  if (inputDeviceType == EInputDeviceType.MOUSE && !m_sActionNameMouse.IsEmpty())
351  m_sActionToDisplay = m_sActionNameMouse;
352  else
353  m_sActionToDisplay = m_sActionName;
354 
355  return m_sActionToDisplay;
356  }
357 }
SCR_ETooltipAlignmentHorizontal
SCR_ETooltipAlignmentHorizontal
Definition: SCR_ScriptedWidgetTooltip.c:775
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_TooltipManagerEntity
void SCR_TooltipManagerEntity(IEntitySource src, IEntity parent)
Definition: SCR_TooltipManagerEntity.c:170
m_iButtonsPadding
protected int m_iButtonsPadding
Definition: SCR_BrowserHoverTooltipComponent.c:18
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_sActionName
protected string m_sActionName
Definition: SCR_ActionsRadialMenuEditorComponent.c:24
m_aButtonComponents
protected ref map< string, SCR_InputButtonComponent > m_aButtonComponents
Definition: SCR_BrowserHoverTooltipComponent.c:27
SCR_BrowserHoverTooltipComponent
Definition: SCR_BrowserHoverTooltipComponent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_wMessage
protected RichTextWidget m_wMessage
Definition: SCR_BrowserHoverTooltipComponent.c:24
m_wMessageLayout
protected Widget m_wMessageLayout
Definition: SCR_BrowserHoverTooltipComponent.c:23
BaseContainerProps
SCR_BrowserHoverTooltipComponent SCR_ScriptedWidgetComponent BaseContainerProps()] class SCR_BrowserTooltipButtonPresetData
Configuration for a button. These buttons are purely visual hints, their actions are disabled.
Definition: SCR_BrowserHoverTooltipComponent.c:306
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_fButtonsOpacity
protected float m_fButtonsOpacity
Definition: SCR_BrowserHoverTooltipComponent.c:15
m_Preset
ref SCR_ScriptedWidgetTooltipPreset m_Preset
Definition: SCR_BrowserHoverTooltipComponent.c:3
m_aScriptButtons
protected ref array< ref SCR_BrowserTooltipButtonPresetData > m_aScriptButtons
Definition: SCR_BrowserHoverTooltipComponent.c:26
m_wInputsLayout
protected Widget m_wInputsLayout
Definition: SCR_BrowserHoverTooltipComponent.c:22
m_ButtonsColor
protected ref Color m_ButtonsColor
Definition: SCR_BrowserHoverTooltipComponent.c:12
m_sButtonsLayout
protected ResourceName m_sButtonsLayout
Definition: SCR_BrowserHoverTooltipComponent.c:6
SetData
void SetData(Managed data)
Definition: SCR_ModularButtonComponent.c:164
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
m_aButtons
protected ref array< ref SCR_BrowserTooltipButtonPresetData > m_aButtons
Definition: SCR_BrowserHoverTooltipComponent.c:9
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
m_wTooltip
protected Widget m_wTooltip
Definition: SCR_BrowserHoverTooltipComponent.c:20