Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ServicesStatusDialogComponent.c
Go to the documentation of this file.
2{
3 [Attribute()]
4 protected ref SCR_BackendServiceDisplayPresets m_ServicesPresets;
5
6 [Attribute()]
7 protected ref array<ref SCR_ServicesStatusDialogComponent_Status> m_aStatuses;
8
9 [Attribute()]
10 protected ref array<ref SCR_ServicesStatusDialogComponent_Status> m_aMainStatuses;
11
12 [Attribute(defvalue: "{D6EA742398E63066}UI/layouts/Menus/Dialogs/ServiceStatusLine.layout", params: "layout")]
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")]
28
29 [Attribute(defvalue: "#AR-ServicesStatus_Message_AttemptingToConnect")]
31
32 [Attribute(defvalue: "#AR-Workshop_Dialog_NoConnection_CheckConnection")]
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")]
47
48 [Attribute(defvalue: "#AR-ServicesStatus_LastUpdate_Condensed")]
50
51 [Attribute(defvalue: "#AR-Account_LoginTimeout")]
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
73
74 protected string m_sPingText;
75 protected string m_sRefreshText;
76
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"));
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"));
107
108 // refresh message
109 m_wRefreshMessage = TextWidget.Cast(w.FindAnyWidget("RefreshCountdown"));
111 {
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
131 }
132
133 //------------------------------------------------------------------------------------------------
134 protected void CreateLines(Widget w)
135 {
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 {
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());
181 color = Color.FromInt(UIColors.HIGHLIGHTED.PackToInt());
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 = {};
219 services = m_ServicesPresets.GetServices();
220
221 return services;
222 }
223
224 //------------------------------------------------------------------------------------------------
227 {
229 return;
230
231 foreach (SCR_BackendServiceDisplay serviceInfo : m_ServicesPresets.GetServices())
232 {
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 {
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 {
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 //------------------------------------------------------------------------------------------------
420
421 //------------------------------------------------------------------------------------------------
426
427 //------------------------------------------------------------------------------------------------
429 {
430 if (!tooltip || tooltip.GetTag() != m_sTooltipTag || !tooltip.GetHoverWidget())
431 {
432 m_Tooltip = null;
433 return;
434 }
435
436 m_Tooltip = tooltip;
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
467 if (!content)
468 return;
469
470 content.SetMessage(message);
471
472 SCR_ServicesStatusDialogComponent_Status statusPreset = GetStatus(status, m_aStatuses);
473 if (statusPreset)
474 content.SetMessageColor(statusPreset.m_sIconColor);
475 }
476}
477
479class SCR_ServicesStatusDialogComponent_Status
481 [Attribute(defvalue: UIConstants.ICONS_IMAGE_SET, params: "imageset")]
484 [Attribute(defvalue: SCR_Enum.GetDefault(EServiceStatus.ERROR), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EServiceStatus))]
485 EServiceStatus m_Status;
487 [Attribute(defvalue: UIConstants.ICON_OK)]
488 string m_sIcon;
490 [Attribute(defvalue: "1 1 1 1")]
491 ref Color m_sIconColor;
492
493 [Attribute(defvalue: "0 0 0 0")]
494 ref Color m_sBackgroundColor;
495
496 [Attribute(defvalue: "1 1 1 1")]
497 ref Color m_sTextColor;
498}
501{
507
508 //------------------------------------------------------------------------------------------------
509 override void HandlerAttached(Widget w)
510 {
511 super.HandlerAttached(w);
513 m_wTitle = TextWidget.Cast(w.FindAnyWidget("Text"));
514 m_wBackground = ImageWidget.Cast(w.FindAnyWidget("Background"));
515 m_wIconWidget = ImageWidget.Cast(w.FindAnyWidget("Icon"));
516 }
517
518 //------------------------------------------------------------------------------------------------
523 m_eStatus = status;
524 }
526 //------------------------------------------------------------------------------------------------
529 {
530 return m_eStatus;
531 }
533 //------------------------------------------------------------------------------------------------
class RestAPIHelper< JsonApiStruct T > content
ref DSGameConfig game
Definition DSConfig.c:81
ArmaReforgerScripted GetGame()
Definition game.c:1398
ResourceName m_sImageSet
Widget m_wBackground
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ServicesStatusDialogComponent ScriptedWidgetComponent BaseContainerProps()] class SCR_ServicesStatusDialogComponent_Status
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
TextWidget m_wTitle
Definition Color.c:13
static ScriptInvokerTooltip GetOnTooltipShow()
ref array< ref SCR_ServicesStatusDialogComponent_Status > m_aMainStatuses
SCR_ServicesStatusDialogComponent_Status GetStatus(EServiceStatus serviceStatus, array< ref SCR_ServicesStatusDialogComponent_Status > statuses)
void SetRefreshMessage(int countdown, bool visible=true)
void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltip)
ref array< ref SCR_ServicesStatusDialogComponent_Status > m_aStatuses
void UpdateServicesMessage(SCR_ECommStatus commStatus, EServiceStatus servicesStatus)
array< ref SCR_BackendServiceDisplay > GetAllServices()
void SetStatusText(Widget textWidget, EServiceStatus serviceStatus)
void SetStatusImageAndColor(ImageWidget iconWidget, EServiceStatus serviceStatus, bool mainIcon=false)
void SetStatusBackground(ImageWidget backgroundWidget, EServiceStatus serviceStatus)
void SetServiceState(string serviceId, EServiceStatus status)
ref SCR_BackendServiceDisplayPresets m_ServicesPresets
static SCR_ServicesStatusDialogLineComponent FindComponent(notnull Widget w)
static bool DisplayServiceOnCurrentPlatform(SCR_BackendServiceDisplay service)
static SCR_ECommStatus GetLastReceivedCommStatus()
SCR_FieldOfViewSettings Attribute