Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ConnectionStateButtonComponent.c
Go to the documentation of this file.
4 {
5  // services
6  [Attribute()]
7  protected ref SCR_BackendServiceDisplayPresets m_ServicesPresets;
8 
9  // button states
10  [Attribute()]
11  protected ref array<ref SCR_ConnectionStateButtonComponent_StatusPreset> m_aStatuses;
12 
13  // Low Bandwidth
14  [Attribute(UIColors.GetColorAttribute(UIColors.NEUTRAL_ACTIVE_STANDBY), UIWidgets.ColorPicker)]
15  protected ref Color m_LowBandwidthColor;
16 
17  [Attribute("1")]
18  protected bool m_bShowLowBandwidthLabel;
19 
20  [Attribute("ConnectionState")]
21  protected string m_sTooltipTag;
22 
23  [Attribute(UIConstants.PROCESSING_SPINNER_ANIMATION_SPEED.ToString())]
24  protected float m_fSpinnerSpeed;
25 
26  [Attribute(defvalue: SCR_Enum.GetDefault(EAnimationCurve.EASE_IN_OUT_SINE), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EAnimationCurve))]
27  EAnimationCurve m_eSpinnerAnimationCurve;
28 
29  protected bool m_bIsListeningForCommCheckEvent;
30 
31  protected ref array<string> m_aUnavailableServices = {};
32  protected SCR_ConnectionStateButtonComponent_StatusPreset m_CurrentStatusPreset;
33  protected SCR_ScriptedWidgetTooltip m_Tooltip;
34 
35  protected ImageWidget m_wConnectingSpinner;
36  protected WidgetAnimationImageRotation m_SpinnerAnimation;
37 
38  //------------------------------------------------------------------------------------------------
39  override void HandlerAttached(Widget w)
40  {
41  super.HandlerAttached(w);
42 
43  if (GetGame().InPlayMode())
44  {
45  SetVisible(false);
46  UpdateStatus(SCR_ServicesStatusHelper.GetLastReceivedCommStatus());
47  }
48 
49  m_wConnectingSpinner = ImageWidget.Cast(w.FindAnyWidget("ConnectingSpinner"));
50  SCR_ConnectionStateButtonComponent_StatusPreset connectingPreset = GetStatusPreset(SCR_ECommStatus.RUNNING);
51  if (m_wConnectingSpinner && connectingPreset)
52  m_wConnectingSpinner.SetColor(connectingPreset.m_Color);
53 
54  // Owner menu events
55  SCR_MenuHelper.GetOnMenuShow().Insert(OnMenuEnabled);
56  SCR_MenuHelper.GetOnMenuFocusGained().Insert(OnMenuEnabled);
57  SCR_MenuHelper.GetOnMenuHide().Insert(OnMenuDisabled);
58 
59  GetButton().m_OnClicked.Insert(OnButtonClicked);
60  GetButton().m_OnFocus.Insert(OnButtonFocused);
61  GetButton().m_OnFocusLost.Insert(OnButtonFocusLost);
62 
63  // Automatic Refresh
64  GetGame().GetCallqueue().CallLater(OnAutomaticRefresh, SCR_ServicesStatusHelper.AUTOMATIC_REFRESH_RATE, true);
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  override void HandlerDeattached(Widget w)
69  {
70  super.HandlerDeattached(w);
71 
72  ClearInvokers();
73 
74  // Owner menu events
75  SCR_MenuHelper.GetOnMenuShow().Remove(OnMenuEnabled);
76  SCR_MenuHelper.GetOnMenuFocusGained().Remove(OnMenuEnabled);
77  SCR_MenuHelper.GetOnMenuHide().Remove(OnMenuDisabled);
78 
79  // Automatic Refresh
80  GetGame().GetCallqueue().Remove(OnAutomaticRefresh);
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  override void SetVisible(bool visible, bool animate = false, float rate = UIConstants.FADE_RATE_FAST)
85  {
86  super.SetVisible(visible, animate, rate);
87 
88  if (!visible && m_Tooltip)
89  m_Tooltip.ForceHidden();
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  protected void OnMenuEnabled(ChimeraMenuBase menu)
94  {
95  if (menu != ChimeraMenuBase.GetOwnerMenu(GetRootWidget()))
96  return;
97 
99  {
100  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusUpdated);
101  SCR_ServicesStatusHelper.GetOnCommStatusCheckStart().Insert(OnCommStatusCheckStart);
102  }
103 
105 
106  SCR_ServicesStatusHelper.RefreshPing();
107 
108  UpdateStatus(SCR_ServicesStatusHelper.GetLastReceivedCommStatus());
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  protected void OnMenuDisabled(ChimeraMenuBase menu)
113  {
114  if (menu != ChimeraMenuBase.GetOwnerMenu(GetRootWidget()))
115  return;
116 
117  ClearInvokers();
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  protected void ClearInvokers()
122  {
123  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusUpdated);
124  SCR_ServicesStatusHelper.GetOnCommStatusCheckStart().Remove(OnCommStatusCheckStart);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  protected void OnCommStatusUpdated(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
130  {
131  UpdateStatus(status);
132  }
133 
134  //------------------------------------------------------------------------------------------------
135  protected void OnCommStatusCheckStart()
136  {
137  if (m_CurrentStatusPreset && m_CurrentStatusPreset.m_Status != SCR_ServicesStatusHelper.GetLastReceivedCommStatus())
138  UpdateStatus(SCR_ServicesStatusHelper.GetLastReceivedCommStatus());
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void OnAutomaticRefresh()
143  {
144  SCR_ServicesStatusHelper.RefreshPing();
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected void UpdateStatus(SCR_ECommStatus status)
149  {
150  switch(status)
151  {
152  case SCR_ECommStatus.FINISHED:
153  {
154  if (AreServicesUnavailable())
155  {
156  UpdateWidgets(status);
157  break;
158  }
159 
160  // everything ok, check for low bandwidth
161  if (CheckLowBandwidth())
162  {
163  UpdateWidgets(status, true);
164  break;
165  }
166 
167  // no issues, no need to show the button
168  SetVisible(false, IsVisible());
169  break;
170  }
171 
172  default:
173  {
174  UpdateWidgets(status);
175  break;
176  }
177  }
178 
179  AnimateSpinner();
180  UpdateTooltip();
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  // \return true in case services are unavailable and caches the problematic ones to be displayed in tooltips
185  protected bool AreServicesUnavailable()
186  {
187  if (!m_ServicesPresets)
188  return true;
189 
190  m_aUnavailableServices.Clear();
191 
192  // Check states of services
193  foreach (SCR_BackendServiceDisplay serviceInfo : m_ServicesPresets.GetServices())
194  {
195  if (SCR_ServicesStatusHelper.SkipConsoleService(serviceInfo))
196  continue;
197 
198  ServiceStatusItem statusItem = SCR_ServicesStatusHelper.GetStatusByName(serviceInfo.m_sServiceId);
199 
200  if (!statusItem || statusItem.Status() != SCR_ServicesStatusHelper.STATUS_OK)
201  m_aUnavailableServices.Insert(serviceInfo.m_sTitle);
202  }
203 
204  // Main status check
205  ServiceStatusItem mainStatus = SCR_ServicesStatusHelper.GetMainStatus();
206  return !mainStatus || mainStatus.Status().IsEmpty() || !m_aUnavailableServices.IsEmpty();
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  protected bool CheckLowBandwidth()
211  {
212  //TODO: update this if we ever get an API for bandwidth
213  int ping = SCR_ServicesStatusHelper.GetPingValue();
214  return ping > SCR_ServicesStatusHelper.PING_THRESHOLD_AWFUL || ping < 0;
215  }
216 
217  //------------------------------------------------------------------------------------------------
218  protected void UpdateWidgets(SCR_ECommStatus status, bool lowBandwidth = false)
219  {
220  m_CurrentStatusPreset = GetStatusPreset(status);
221  SetVisible(m_CurrentStatusPreset != null, true);
222 
224  return;
225 
226  string icon = m_CurrentStatusPreset.m_sIcon;
227  Color color = m_CurrentStatusPreset.m_Color;
228  string label = m_CurrentStatusPreset.m_sLabel;
229  bool showLabel = m_CurrentStatusPreset.m_bShowLabel;
230 
231  if (lowBandwidth)
232  {
233  icon = m_sIconName;
234  color = m_LowBandwidthColor;
235  label = m_sLabel;
236  showLabel = m_bShowLowBandwidthLabel;
237  }
238 
239  SetIcon(icon);
240  SetIconColor(color);
241 
242  if (showLabel)
243  SetLabelText(label);
244  else
245  SetLabelText("");
246  }
247 
248  //------------------------------------------------------------------------------------------------
249  protected void AnimateSpinner()
250  {
251  if (m_SpinnerAnimation)
252  {
253  m_SpinnerAnimation.GetOnCycleCompleted().Remove(AnimateSpinner);
254  if (!ShowSpinner())
255  m_SpinnerAnimation.Stop();
256  }
257 
258  if (!m_wConnectingSpinner)
259  return;
260 
261  m_wConnectingSpinner.SetVisible(ShowSpinner());
262 
263  m_wConnectingSpinner.SetRotation(0);
264  m_SpinnerAnimation = AnimateWidget.Rotation(m_wConnectingSpinner, 360, m_fSpinnerSpeed);
265  if (m_SpinnerAnimation)
266  {
267  m_SpinnerAnimation.SetRepeat(true);
268  m_SpinnerAnimation.SetCurve(m_eSpinnerAnimationCurve);
269  m_SpinnerAnimation.GetOnCycleCompleted().Insert(AnimateSpinner);
270  }
271  }
272 
273  //------------------------------------------------------------------------------------------------
274  protected bool ShowSpinner()
275  {
276  return m_CurrentStatusPreset && m_CurrentStatusPreset.m_Status == SCR_ECommStatus.RUNNING;
277  }
278 
279  //------------------------------------------------------------------------------------------------
280  protected SCR_ConnectionStateButtonComponent_StatusPreset GetStatusPreset(SCR_ECommStatus status)
281  {
282  foreach (SCR_ConnectionStateButtonComponent_StatusPreset preset : m_aStatuses)
283  {
284  if (preset.m_Status == status)
285  return preset;
286  }
287 
288  return null;
289  }
290 
291  //------------------------------------------------------------------------------------------------
292  protected void SetIconColor(Color color)
293  {
294  if (!m_wIcon)
295  return;
296 
297  m_wIcon.SetColor(color);
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  protected void OnButtonClicked()
302  {
303  SCR_CommonDialogs.CreateServicesStatusDialog();
304  }
305 
306  //------------------------------------------------------------------------------------------------
307  protected void OnButtonFocused()
308  {
309  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnTooltipShow);
310  }
311 
312  //------------------------------------------------------------------------------------------------
313  protected void OnButtonFocusLost()
314  {
315  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
316  }
317 
318  //------------------------------------------------------------------------------------------------
319  protected void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
320  {
321  if (tag != m_sTooltipTag)
322  {
323  m_Tooltip = null;
324  return;
325  }
326 
327  m_Tooltip = tooltipClass;
328  UpdateTooltip();
329  }
330 
331  //------------------------------------------------------------------------------------------------
332  protected void UpdateTooltip()
333  {
335  return;
336 
337  string message = m_CurrentStatusPreset.m_sTooltipMessage;
338  Color messageColor = m_CurrentStatusPreset.m_Color;
339 
340  if (m_CurrentStatusPreset.m_Status == SCR_ECommStatus.FINISHED)
341  {
342  // Unavailable services: the tooltips will display the list of issues
343  if (!m_aUnavailableServices.IsEmpty())
344  {
345  // fill the tooltip with the list of issues
346  Widget tooltipContent = m_Tooltip.GetContentWidget();
347  if (tooltipContent)
348  {
349  SCR_ListTooltipComponent comp = SCR_ListTooltipComponent.FindComponent(tooltipContent);
350  if (comp)
351  comp.Init(m_aUnavailableServices);
352  }
353  }
354 
355  // Low bandwidth: this is the default message set in the tooltip's .conf file
356  else if (CheckLowBandwidth())
357  {
358  message = m_Tooltip.GetDefaultMessage();
359  messageColor = m_LowBandwidthColor;
360  }
361 
362  // if everything is of the button will disappear and so should the tooltip
363  else
364  {
365  m_Tooltip.ForceHidden();
366  }
367  }
368 
369  m_Tooltip.SetMessage(message);
370  m_Tooltip.SetMessageColor(messageColor);
371  }
372 }
373 
375 class SCR_ConnectionStateButtonComponent_StatusPreset
376 {
377  [Attribute(defvalue: UIConstants.ICONS_IMAGE_SET, params: "imageset")]
378  ResourceName m_sImageSet;
379 
380  [Attribute(defvalue: SCR_Enum.GetDefault(SCR_ECommStatus.RUNNING), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ECommStatus))]
381  SCR_ECommStatus m_Status;
382 
383  [Attribute("connection")]
384  string m_sIcon;
385 
386  [Attribute("#AR-Workshop_Connecting")]
387  string m_sLabel;
388 
389  [Attribute(UIColors.GetColorAttribute(UIColors.CONTRAST_COLOR), UIWidgets.ColorPicker)]
390  ref Color m_Color;
391 
392  [Attribute("#AR-Workshop_Connecting")]
393  string m_sTooltipMessage;
394 
395  [Attribute("1")]
396  bool m_bShowLabel;
397 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
m_wIcon
protected ImageWidget m_wIcon
Definition: SCR_InventoryHitZonePointUI.c:374
SCR_ListTooltipComponent
Definition: SCR_ListTooltipComponent.c:4
SCR_Enum
Definition: SCR_Enum.c:1
m_wConnectingSpinner
protected ImageWidget m_wConnectingSpinner
Definition: SCR_ConnectionStateButtonComponent.c:32
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CommonDialogs
Definition: CommonDialogs.c:5
SCR_ConnectionStateButtonComponent
Definition: SCR_ConnectionStateButtonComponent.c:3
m_ServicesPresets
protected ref SCR_BackendServiceDisplayPresets m_ServicesPresets
Definition: SCR_ServicesStatusDialogComponent.c:3
m_aStatuses
protected ref array< ref SCR_ServicesStatusDialogComponent_Status > m_aStatuses
Definition: SCR_ServicesStatusDialogComponent.c:6
m_SpinnerAnimation
protected WidgetAnimationImageRotation m_SpinnerAnimation
Definition: SCR_ConnectionStateButtonComponent.c:33
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
m_aUnavailableServices
protected ref array< string > m_aUnavailableServices
Definition: SCR_ConnectionStateButtonComponent.c:28
m_bIsListeningForCommCheckEvent
protected bool m_bIsListeningForCommCheckEvent
Definition: SCR_ConnectionStateButtonComponent.c:26
m_sImageSet
ResourceName m_sImageSet
Definition: SCR_MapToolMenuUI.c:8
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
m_sTooltipTag
protected string m_sTooltipTag
Definition: SCR_ServicesStatusDialogComponent.c:55
m_LowBandwidthColor
protected ref Color m_LowBandwidthColor
Definition: SCR_ConnectionStateButtonComponent.c:12
SCR_MenuHelper
Definition: SCR_MenuHelper.c:15
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
m_Tooltip
protected SCR_ScriptedWidgetTooltip m_Tooltip
Definition: SCR_ServicesStatusDialogComponent.c:76
SCR_BackendServiceDisplay
Definition: SCR_ServicesStatusHelper.c:438
m_Color
ref Color m_Color
Definition: SCR_GeneratorBaseEntity.c:3
m_CurrentStatusPreset
protected SCR_ConnectionStateButtonComponent_StatusPreset m_CurrentStatusPreset
Definition: SCR_ConnectionStateButtonComponent.c:29
IsVisible
bool IsVisible()
Definition: SCR_ResourceComponent.c:870
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_CoreMenuHeaderButtonComponent
Helper component for core menu header button prefabs.
Definition: SCR_CoreMenuHeaderButtonComponent.c:2
m_bShowLowBandwidthLabel
protected bool m_bShowLowBandwidthLabel
Definition: SCR_ConnectionStateButtonComponent.c:15
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
m_sIcon
protected string m_sIcon
Definition: SCR_InventoryHitZonePointUI.c:373
BaseContainerProps
SCR_ConnectionStateButtonComponent SCR_CoreMenuHeaderButtonComponent BaseContainerProps()] class SCR_ConnectionStateButtonComponent_StatusPreset
Definition: SCR_ConnectionStateButtonComponent.c:374