Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServicesStatusDialogComponent.c
Go to the documentation of this file.
1 class SCR_ServicesStatusDialogComponent : ScriptedWidgetComponent
2 {
4  protected ref SCR_BackendServiceDisplayPresets m_ServicesPresets;
5 
7  protected ref array<ref SCR_ServicesStatusDialogComponent_Status> m_aStatuses;
8 
10  protected ref array<ref SCR_ServicesStatusDialogComponent_Status> m_aMainStatuses;
11 
12  [Attribute(defvalue: "{D6EA742398E63066}UI/layouts/Menus/Dialogs/ServiceStatusLine.layout", params: "layout")]
13  protected ResourceName m_LineLayout;
14 
15  // Ping
16  [Attribute(defvalue: " - ")]
17  protected string m_sNoPing;
18 
19  [Attribute(defvalue: " ... ")]
20  protected string m_sUpdatingPing;
21 
22  [Attribute(defvalue: "%1+", desc: "Can use %1 for Max Ping display (default \"%1+\" e.g \"999+\")")]
23  protected string m_sBigPing;
24 
25  // Status message
26  [Attribute(defvalue: "#AR-Account_LoginTimeout")]
27  protected string m_sStatusesMessageInitializationError;
28 
29  [Attribute(defvalue: "#AR-ServicesStatus_Message_AttemptingToConnect")]
30  protected string m_sStatusesMessageAttemptingToConnect;
31 
32  [Attribute(defvalue: "#AR-Workshop_Dialog_NoConnection_CheckConnection")]
33  protected string m_sStatusesMessageNoConnection;
34 
35  [Attribute(defvalue: "#AR-ServicesStatus_Message_AllServicesUp")]
36  protected string m_sStatusesMessageRunning;
37 
38  [Attribute(defvalue: "#AR-ServicesStatus_Message_SomeServicesUp")]
39  protected string m_sStatusesMessageWarning;
40 
41  [Attribute(defvalue: "#AR-ServicesStatus_Message_AllServicesDown")]
42  protected string m_sStatusesMessageError;
43 
44  // Last Update message
45  [Attribute(defvalue: "#AR-ServicesStatus_LastUpdate_Seconds_Condensed")]
46  protected string m_sLastUpdateMessageSeconds;
47 
48  [Attribute(defvalue: "#AR-ServicesStatus_LastUpdate_Condensed")]
49  protected string m_sLastUpdateMessageMinutes;
50 
51  [Attribute(defvalue: "#AR-Account_LoginTimeout")]
52  protected string m_sLastUpdateMessageNoConnection;
53 
54  // Legend Tooltip
55  [Attribute(defvalue: "ServiceStatusLegend")]
56  protected string m_sTooltipTag;
57 
58  [Attribute(defvalue: "#AR-ServicesStatus_Legend_Warning")]
59  protected string m_sLegendWarning;
60 
61  [Attribute(defvalue: "#AR-ServicesStatus_Legend_Running")]
62  protected string m_sLegendRunning;
63 
64  [Attribute(defvalue: "#AR-ServicesStatus_Legend_Error")]
65  protected string m_sLegendError;
66 
67  // Elements
68  protected TextWidget m_wPingWidget;
69  protected Widget m_wLinesParentWidget;
70  protected TextWidget m_wServicesMessage;
71  protected TextWidget m_wLastUpdate;
72  protected TextWidget m_wRefreshMessage;
73 
74  protected string m_sPingText;
75  protected string m_sRefreshText;
76 
77  protected SCR_ScriptedWidgetTooltip m_Tooltip;
78 
79  //------------------------------------------------------------------------------------------------
80  override void HandlerAttached(Widget w)
81  {
82  super.HandlerAttached(w);
83 
84  if (!m_LineLayout || !m_ServicesPresets || m_ServicesPresets.GetServices().IsEmpty())
85  return;
86 
87  // services message
88  m_wServicesMessage = TextWidget.Cast(w.FindAnyWidget("ServicesMessage"));
89  UpdateServicesMessage(SCR_ServicesStatusHelper.GetLastReceivedCommStatus(), EServiceStatus.ERROR);
90 
91  // ping
92  m_wPingWidget = TextWidget.Cast(SCR_WidgetHelper.GetWidgetOrChild(w, "Ping"));
93  if (m_wPingWidget)
94  {
95  m_sPingText = m_wPingWidget.GetText();
96  m_wPingWidget.SetColor(Color.FromInt(UIColors.WARNING.PackToInt()));
97  }
98 
99  // lines
100  m_wLinesParentWidget = SCR_WidgetHelper.GetWidgetOrChild(w, "Statuses");
102  return;
103 
104  // last update
105  m_wLastUpdate = TextWidget.Cast(w.FindAnyWidget("LastUpdate"));
106  SetLastUpdateMessage(-1);
107 
108  // refresh message
109  m_wRefreshMessage = TextWidget.Cast(w.FindAnyWidget("RefreshCountdown"));
110  if (m_wRefreshMessage)
111  {
112  m_sRefreshText = m_wRefreshMessage.GetText();
113  SetRefreshMessage(0, false);
114  }
115 
116  // build info
117  ArmaReforgerScripted game = GetGame();
118  TextWidget buildInfo = TextWidget.Cast(w.FindAnyWidget("BuildInfo"));
119  if (buildInfo)
120  buildInfo.SetTextFormat(buildInfo.GetText(), game.GetBuildVersion(), game.GetBuildTime());
121 
122  CreateLines(w);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  override void HandlerDeattached(Widget w)
127  {
128  super.HandlerDeattached(w);
129 
130  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
131  }
132 
133  //------------------------------------------------------------------------------------------------
134  protected void CreateLines(Widget w)
135  {
136  if (!m_ServicesPresets)
137  return;
138 
139  SCR_ServicesStatusDialogComponent_Status status;
140  if (m_aStatuses && !m_aStatuses.IsEmpty())
141  status = m_aStatuses[0];
142 
143  Widget line;
144  TextWidget titleWidget;
145  foreach (SCR_BackendServiceDisplay service : m_ServicesPresets.GetServices())
146  {
147  if (SCR_ServicesStatusHelper.SkipConsoleService(service))
148  continue;
149 
150  line = GetGame().GetWorkspace().CreateWidgets(m_LineLayout, m_wLinesParentWidget);
151  if (!line)
152  continue;
153 
154  line.SetName(service.m_sId);
155 
157  if (!lineComp)
158  continue;
159 
160  if (lineComp.m_wTitle)
161  lineComp.m_wTitle.SetText(service.m_sTitle);
162 
163  lineComp.GetOnMouseEnter().Insert(OnLineMouseEnter);
164  lineComp.GetOnMouseLeave().Insert(OnLineMouseLeave);
165 
166  if (status)
167  SetServiceState(service.m_sId, status.m_Status);
168  }
169  }
170 
171  //------------------------------------------------------------------------------------------------
174  void SetPing(int pingInMs)
175  {
176  if (!m_wPingWidget)
177  return;
178 
179  Color color = Color.FromInt(UIColors.WARNING.PackToInt());
180  if (pingInMs < SCR_ServicesStatusHelper.PING_THRESHOLD_BAD)
181  color = Color.FromInt(UIColors.HIGHLIGHTED.PackToInt());
182  if (pingInMs < SCR_ServicesStatusHelper.PING_THRESHOLD_GOOD)
183  color = Color.FromInt(UIColors.CONFIRM.PackToInt());
184 
185  string sPing;
186  if (pingInMs == -1)
187  {
188  sPing = m_sNoPing;
189  color = Color.FromInt(UIColors.WARNING.PackToInt());
190  }
191 
192  else if (pingInMs == 0)
193  {
194  sPing = m_sUpdatingPing;
195  color = Color.FromInt(UIColors.NEUTRAL_ACTIVE_STANDBY.PackToInt());
196  }
197 
198  else if (pingInMs < 0 || pingInMs > SCR_ServicesStatusHelper.PING_MAX)
199  {
200  sPing = string.Format(m_sBigPing, SCR_ServicesStatusHelper.PING_MAX);
201  color = Color.FromInt(UIColors.WARNING.PackToInt());
202  }
203 
204  else
205  {
206  sPing = pingInMs.ToString();
207  }
208 
209  m_wPingWidget.SetColor(color);
210  m_wPingWidget.SetTextFormat(m_sPingText, sPing);
211  }
212 
213  //------------------------------------------------------------------------------------------------
215  array<ref SCR_BackendServiceDisplay> GetAllServices()
216  {
217  array<ref SCR_BackendServiceDisplay> services = {};
218  if (m_ServicesPresets)
219  services = m_ServicesPresets.GetServices();
220 
221  return services;
222  }
223 
224  //------------------------------------------------------------------------------------------------
226  void SetAllServicesState(EServiceStatus status)
227  {
228  if (!m_ServicesPresets)
229  return;
230 
231  foreach (SCR_BackendServiceDisplay serviceInfo : m_ServicesPresets.GetServices())
232  {
233  if (SCR_ServicesStatusHelper.SkipConsoleService(serviceInfo))
234  continue;
235 
236  SetServiceState(serviceInfo.m_sId, status);
237  }
238  }
239 
240  //------------------------------------------------------------------------------------------------
243  void SetServiceState(string serviceId, EServiceStatus status)
244  {
245  Widget line = m_wLinesParentWidget.FindAnyWidget(serviceId);
246  if (!line)
247  return;
248 
250  if (!lineComp)
251  return;
252 
253  if (lineComp.m_wBackground)
254  SetStatusBackground(lineComp.m_wBackground, status);
255 
256  if (lineComp.m_wIconWidget)
257  SetStatusImageAndColor(lineComp.m_wIconWidget, status);
258 
259  if (lineComp.m_wTitle)
260  SetStatusText(lineComp.m_wTitle, status);
261 
262  lineComp.CacheStatus(status);
263 
264  if (m_Tooltip)
265  m_Tooltip.ForceHidden();
266  }
267 
268  //------------------------------------------------------------------------------------------------
272  // The message reflects first of all the communication status with backend.
273  // Should communication succeed, the message will then change depending on the state of services
274  void UpdateServicesMessage(SCR_ECommStatus commStatus, EServiceStatus servicesStatus)
275  {
276  if (!m_wServicesMessage)
277  return;
278 
279  switch(commStatus)
280  {
281  case SCR_ECommStatus.NOT_EXECUTED:
282  {
284  break;
285  }
286 
287  case SCR_ECommStatus.RUNNING:
288  {
290  break;
291  }
292 
293  // Connection succeded, change the message based on the services available
294  case SCR_ECommStatus.FINISHED:
295  {
296  switch(servicesStatus)
297  {
298  case EServiceStatus.RUNNING:
300  break;
301 
302  case EServiceStatus.WARNING:
304  break;
305 
306  case EServiceStatus.ERROR:
308  break;
309  }
310  break;
311  }
312 
313  case SCR_ECommStatus.FAILED:
314  {
316  break;
317  }
318  }
319  }
320 
321  //------------------------------------------------------------------------------------------------
323  // pingAge is in milliseconds
324  void SetLastUpdateMessage(int pingAge)
325  {
326  if (!m_wLastUpdate)
327  return;
328 
329  //No connection with backend
330  if (pingAge < 0)
331  {
333  return;
334  }
335 
336  int minutes = pingAge / 60000;
337  int seconds = (pingAge / 1000) - (60 * minutes);
338 
339  if (minutes < 1)
340  m_wLastUpdate.SetTextFormat(m_sLastUpdateMessageSeconds, seconds);
341  else
342  m_wLastUpdate.SetTextFormat(m_sLastUpdateMessageMinutes, minutes, seconds);
343  }
344 
345  //------------------------------------------------------------------------------------------------
348  void SetRefreshMessage(int countdown, bool visible = true)
349  {
350  if (!m_wRefreshMessage)
351  return;
352 
353  m_wRefreshMessage.SetVisible(visible);
354  if (!visible)
355  return;
356 
357  m_wRefreshMessage.SetTextFormat(m_sRefreshText, countdown);
358  }
359 
360  //------------------------------------------------------------------------------------------------
361  protected void SetStatusBackground(ImageWidget backgroundWidget, EServiceStatus serviceStatus)
362  {
363  SCR_ServicesStatusDialogComponent_Status status = GetStatus(serviceStatus, m_aStatuses);
364  if (!status)
365  return;
366 
367  backgroundWidget.SetColor(status.m_sBackgroundColor);
368  }
369 
370  //------------------------------------------------------------------------------------------------
371  protected void SetStatusText(Widget textWidget, EServiceStatus serviceStatus)
372  {
373  SCR_ServicesStatusDialogComponent_Status status = GetStatus(serviceStatus, m_aStatuses);
374  if (!status)
375  return;
376 
377  textWidget.SetColor(status.m_sTextColor);
378  }
379 
380  //------------------------------------------------------------------------------------------------
384  void SetStatusImageAndColor(ImageWidget iconWidget, EServiceStatus serviceStatus, bool mainIcon = false)
385  {
386  SCR_ServicesStatusDialogComponent_Status status;
387 
388  if (mainIcon)
389  status = GetStatus(serviceStatus, m_aMainStatuses);
390  else
391  status = GetStatus(serviceStatus, m_aStatuses);
392 
393  if (!status)
394  return;
395 
396  iconWidget.LoadImageFromSet(0, status.m_sImageSet, status.m_sIcon);
397  iconWidget.SetColor(status.m_sIconColor);
398  }
399 
400  //------------------------------------------------------------------------------------------------
401  protected SCR_ServicesStatusDialogComponent_Status GetStatus(EServiceStatus serviceStatus, array<ref SCR_ServicesStatusDialogComponent_Status> statuses)
402  {
403  if (!statuses)
404  return null;
405 
406  foreach (SCR_ServicesStatusDialogComponent_Status status : statuses)
407  {
408  if (status.m_Status == serviceStatus)
409  return status;
410  }
411 
412  return null;
413  }
414 
415  //------------------------------------------------------------------------------------------------
416  protected void OnLineMouseEnter()
417  {
418  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnTooltipShow);
419  }
420 
421  //------------------------------------------------------------------------------------------------
422  protected void OnLineMouseLeave()
423  {
424  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
425  }
426 
427  //------------------------------------------------------------------------------------------------
428  protected void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
429  {
430  if (tag != m_sTooltipTag || !hoverWidget || !tooltipClass)
431  {
432  m_Tooltip = null;
433  return;
434  }
435 
436  m_Tooltip = tooltipClass;
437 
439  if (!lineComp)
440  return;
441 
442  EServiceStatus status = lineComp.GetStatus();
443  string message;
444 
445  switch(status)
446  {
447  case EServiceStatus.ERROR:
448  {
449  message = m_sLegendError;
450  break;
451  }
452 
453  case EServiceStatus.WARNING:
454  {
455  message = m_sLegendWarning;
456  break;
457  }
458 
459  case EServiceStatus.RUNNING:
460  {
461  message = m_sLegendRunning;
462  break;
463  }
464  }
465 
466  m_Tooltip.SetMessage(message);
467 
468  SCR_ServicesStatusDialogComponent_Status statusPreset = GetStatus(status, m_aStatuses);
469  if (statusPreset)
470  m_Tooltip.SetMessageColor(statusPreset.m_sIconColor);
471  }
472 }
473 
475 class SCR_ServicesStatusDialogComponent_Status
476 {
477  [Attribute(defvalue: UIConstants.ICONS_IMAGE_SET, params: "imageset")]
478  ResourceName m_sImageSet;
479 
480  [Attribute(defvalue: SCR_Enum.GetDefault(EServiceStatus.ERROR), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EServiceStatus))]
481  EServiceStatus m_Status;
482 
483  [Attribute(defvalue: "okCircle")]
484  string m_sIcon;
485 
486  [Attribute(defvalue: "1 1 1 1")]
487  ref Color m_sIconColor;
488 
489  [Attribute(defvalue: "0 0 0 0")]
490  ref Color m_sBackgroundColor;
491 
492  [Attribute(defvalue: "1 1 1 1")]
493  ref Color m_sTextColor;
494 }
495 
497 {
498  protected EServiceStatus m_eStatus;
499 
500  TextWidget m_wTitle;
501  ImageWidget m_wBackground;
502  ImageWidget m_wIconWidget;
503 
504  //------------------------------------------------------------------------------------------------
505  override void HandlerAttached(Widget w)
506  {
507  super.HandlerAttached(w);
508 
509  m_wTitle = TextWidget.Cast(w.FindAnyWidget("Text"));
510  m_wBackground = ImageWidget.Cast(w.FindAnyWidget("Background"));
511  m_wIconWidget = ImageWidget.Cast(w.FindAnyWidget("Icon"));
512  }
513 
514  //------------------------------------------------------------------------------------------------
517  void CacheStatus(EServiceStatus status)
518  {
519  m_eStatus = status;
520  }
521 
522  //------------------------------------------------------------------------------------------------
524  EServiceStatus GetStatus()
525  {
526  return m_eStatus;
527  }
528 
529  //------------------------------------------------------------------------------------------------
533  static SCR_ServicesStatusDialogLineComponent FindComponent(notnull Widget w)
534  {
536  }
537 }
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
SCR_ServicesStatusDialogLineComponent
Definition: SCR_ServicesStatusDialogComponent.c:496
m_wPingWidget
protected TextWidget m_wPingWidget
Definition: SCR_ServicesStatusDialogComponent.c:67
m_sLastUpdateMessageNoConnection
protected string m_sLastUpdateMessageNoConnection
Definition: SCR_ServicesStatusDialogComponent.c:51
m_sLegendWarning
protected string m_sLegendWarning
Definition: SCR_ServicesStatusDialogComponent.c:58
m_sPingText
protected string m_sPingText
Definition: SCR_ServicesStatusDialogComponent.c:73
SCR_Enum
Definition: SCR_Enum.c:1
m_sLastUpdateMessageMinutes
protected string m_sLastUpdateMessageMinutes
Definition: SCR_ServicesStatusDialogComponent.c:48
UIConstants
Definition: Constants.c:130
m_sStatusesMessageRunning
protected string m_sStatusesMessageRunning
Definition: SCR_ServicesStatusDialogComponent.c:35
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_ServicesPresets
protected ref SCR_BackendServiceDisplayPresets m_ServicesPresets
Definition: SCR_ServicesStatusDialogComponent.c:3
m_wRefreshMessage
protected TextWidget m_wRefreshMessage
Definition: SCR_ServicesStatusDialogComponent.c:71
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_sStatusesMessageError
protected string m_sStatusesMessageError
Definition: SCR_ServicesStatusDialogComponent.c:41
m_aStatuses
protected ref array< ref SCR_ServicesStatusDialogComponent_Status > m_aStatuses
Definition: SCR_ServicesStatusDialogComponent.c:6
m_sStatusesMessageInitializationError
protected string m_sStatusesMessageInitializationError
Definition: SCR_ServicesStatusDialogComponent.c:26
SCR_WidgetHelper
Definition: SCR_WidgetHelper.c:1
m_sImageSet
ResourceName m_sImageSet
Definition: SCR_MapToolMenuUI.c:8
BaseContainerProps
SCR_ServicesStatusDialogComponent ScriptedWidgetComponent BaseContainerProps()] class SCR_ServicesStatusDialogComponent_Status
Definition: SCR_ServicesStatusDialogComponent.c:474
Attribute
typedef Attribute
Post-process effect of scripted camera.
EServiceStatus
EServiceStatus
Definition: SCR_ServicesStatusDialogUI.c:1
UIColors
Definition: Constants.c:16
SCR_EventHandlerComponent
Definition: SCR_EventHandlerComponent.c:5
m_sLastUpdateMessageSeconds
protected string m_sLastUpdateMessageSeconds
Definition: SCR_ServicesStatusDialogComponent.c:45
m_wServicesMessage
protected TextWidget m_wServicesMessage
Definition: SCR_ServicesStatusDialogComponent.c:69
m_sUpdatingPing
protected string m_sUpdatingPing
Definition: SCR_ServicesStatusDialogComponent.c:19
m_sTooltipTag
protected string m_sTooltipTag
Definition: SCR_ServicesStatusDialogComponent.c:55
m_sStatusesMessageAttemptingToConnect
protected string m_sStatusesMessageAttemptingToConnect
Definition: SCR_ServicesStatusDialogComponent.c:29
SCR_ServicesStatusDialogComponent
Definition: SCR_ServicesStatusDialogComponent.c:1
m_wLinesParentWidget
protected Widget m_wLinesParentWidget
Definition: SCR_ServicesStatusDialogComponent.c:68
m_sRefreshText
protected string m_sRefreshText
Definition: SCR_ServicesStatusDialogComponent.c:74
m_sStatusesMessageWarning
protected string m_sStatusesMessageWarning
Definition: SCR_ServicesStatusDialogComponent.c:38
m_sLegendRunning
protected string m_sLegendRunning
Definition: SCR_ServicesStatusDialogComponent.c:61
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
m_wBackground
protected ImageWidget m_wBackground
Definition: SCR_InventoryHitZonePointUI.c:382
m_LineLayout
protected ResourceName m_LineLayout
Definition: SCR_ServicesStatusDialogComponent.c:12
m_Tooltip
protected SCR_ScriptedWidgetTooltip m_Tooltip
Definition: SCR_ServicesStatusDialogComponent.c:76
SCR_BackendServiceDisplay
Definition: SCR_ServicesStatusHelper.c:438
m_sLegendError
protected string m_sLegendError
Definition: SCR_ServicesStatusDialogComponent.c:64
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_sStatusesMessageNoConnection
protected string m_sStatusesMessageNoConnection
Definition: SCR_ServicesStatusDialogComponent.c:32
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
m_sIcon
protected string m_sIcon
Definition: SCR_InventoryHitZonePointUI.c:373
m_sNoPing
protected string m_sNoPing
Definition: SCR_ServicesStatusDialogComponent.c:16
m_wLastUpdate
protected TextWidget m_wLastUpdate
Definition: SCR_ServicesStatusDialogComponent.c:70