Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServicesStatusDialogUI.c
Go to the documentation of this file.
2 {
3  RUNNING = 0,
6 };
7 
9 {
10  protected SCR_ServicesStatusDialogComponent m_ServicesStatusDialogComponent;
11 
12  protected static const int LAST_UPDATED_REFRESH_RATE = 500; // ping age check frequency (is the ping old enough to enable the "Refresh" button?)
13 
14  protected SCR_InputButtonComponent m_Refresh;
15  protected static bool m_bIsOpen;
16 
17  //------------------------------------------------------------------------------------------------
18  protected override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
19  {
20  super.OnMenuOpen(preset);
21 
22  m_bIsOpen = true;
23  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusUpdatedOpenDialog);
24 
25  m_Refresh = FindButton("Refresh");
26  if (m_Refresh)
27  m_Refresh.m_OnActivated.Insert(OnRefresh);
28 
29  m_ServicesStatusDialogComponent = SCR_ServicesStatusDialogComponent.Cast(SCR_ConfigurableDialogUi.GetContentLayoutRoot(GetRootWidget()).FindHandler(SCR_ServicesStatusDialogComponent));
30 
31 #ifdef WORKBENCH
32  if (!m_ServicesStatusDialogComponent)
33  Print("No SCR_ServicesStatusDialogComponent component found | " + __FILE__ + ": " + __LINE__, LogLevel.WARNING);
34 #endif
35 
36  OnRefresh();
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  protected override void OnMenuClose()
41  {
42  super.OnMenuClose();
43 
44  m_bIsOpen = false;
45 
46  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusUpdated);
47  GetGame().GetCallqueue().Remove(UpdateRefreshWidgets);
48  GetGame().GetCallqueue().Remove(OnRefresh);
49  }
50 
51  //------------------------------------------------------------------------------------------------
54  protected void OnRefresh()
55  {
56  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusUpdated);
57  SCR_ServicesStatusHelper.RefreshPing();
58  if (!SCR_ServicesStatusHelper.IsInRefreshCooldown())
59  SCR_ServicesStatusHelper.ClearRefreshQueue();
60 
61  UpdateUI(SCR_ServicesStatusHelper.GetLastReceivedCommStatus());
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  protected void OnCommStatusUpdated(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
66  {
67  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusUpdated);
68  SCR_ServicesStatusHelper.ClearRefreshQueue();
69 
70  UpdateUI(status);
71 
72  // Automatic refresh
73  GetGame().GetCallqueue().Remove(OnRefresh);
74  GetGame().GetCallqueue().CallLater(OnRefresh, SCR_ServicesStatusHelper.AUTOMATIC_REFRESH_RATE);
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  protected void UpdateUI(SCR_ECommStatus status)
80  {
81  if (!m_ServicesStatusDialogComponent)
82  return;
83 
84  EServiceStatus servicesStatus;
85 
86  switch(status)
87  {
88  case SCR_ECommStatus.NOT_EXECUTED:
89  {
90  servicesStatus = EServiceStatus.ERROR;
91  m_ServicesStatusDialogComponent.SetAllServicesState(EServiceStatus.ERROR);
92  break;
93  }
94 
95  case SCR_ECommStatus.RUNNING:
96  {
97  servicesStatus = EServiceStatus.WARNING;
98  m_ServicesStatusDialogComponent.SetAllServicesState(EServiceStatus.WARNING);
99  break;
100  }
101 
102  case SCR_ECommStatus.FINISHED:
103  {
104  servicesStatus = UpdateServiceStates();
105  break;
106  }
107 
108  case SCR_ECommStatus.FAILED:
109  {
110  servicesStatus = EServiceStatus.WARNING;
111  m_ServicesStatusDialogComponent.SetAllServicesState(EServiceStatus.WARNING);
112  break;
113  }
114  }
115 
116  // Update main Icon and message
117  m_ServicesStatusDialogComponent.UpdateServicesMessage(status, servicesStatus);
118 
119  if (m_wImgTitleIcon)
120  m_ServicesStatusDialogComponent.SetStatusImageAndColor(m_wImgTitleIcon, servicesStatus, true);
121 
122  // Update refresh widgets
123  UpdatePingValueUI();
124  UpdateRefreshWidgets();
125  }
126 
127  //------------------------------------------------------------------------------------------------
129  protected EServiceStatus UpdateServiceStates()
130  {
131  EServiceStatus generalStatus = EServiceStatus.RUNNING; // General Status reporting! o7
132 
133  // Main status check
134  ServiceStatusItem mainStatus = SCR_ServicesStatusHelper.GetMainStatus();
135  if (!mainStatus || mainStatus.Status().IsEmpty())
136  {
137  generalStatus = EServiceStatus.ERROR;
138  m_ServicesStatusDialogComponent.SetAllServicesState(generalStatus);
139  return generalStatus;
140  }
141 
142  // Update states of services
143  int errors, warnings, totalServices;
144 
145  EServiceStatus status;
146  foreach (SCR_BackendServiceDisplay serviceInfo : m_ServicesStatusDialogComponent.GetAllServices())
147  {
148  if (SCR_ServicesStatusHelper.SkipConsoleService(serviceInfo))
149  continue;
150 
151  status = GetEnumStatus(serviceInfo.m_sServiceId);
152  m_ServicesStatusDialogComponent.SetServiceState(serviceInfo.m_sId, status);
153 
154  if (status == EServiceStatus.ERROR)
155  errors++;
156  if (status == EServiceStatus.WARNING)
157  warnings++;
158 
159  totalServices++;
160  }
161 
162  if (warnings > 0)
163  generalStatus = EServiceStatus.WARNING;
164  if (errors + warnings == totalServices)
165  generalStatus = EServiceStatus.ERROR;
166 
167  return generalStatus;
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  protected void UpdatePingValueUI()
172  {
173  if (!m_ServicesStatusDialogComponent)
174  return;
175 
176  m_ServicesStatusDialogComponent.SetPing(SCR_ServicesStatusHelper.GetPingValue());
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  protected void UpdateRefreshWidgets()
181  {
182  GetGame().GetCallqueue().Remove(UpdateRefreshWidgets);
183  GetGame().GetCallqueue().CallLater(UpdateRefreshWidgets, LAST_UPDATED_REFRESH_RATE);
184 
185  if (m_Refresh)
186  m_Refresh.SetEnabled(SCR_ServicesStatusHelper.CanRefresh());
187 
188  if (!m_ServicesStatusDialogComponent)
189  return;
190 
191  m_ServicesStatusDialogComponent.SetLastUpdateMessage(SCR_ServicesStatusHelper.GetPingAge());
192 
193  // Refresh countdown
194  int seconds = ((SCR_ServicesStatusHelper.REFRESH_COOLDOWN - SCR_ServicesStatusHelper.GetPingAge()) * 0.001) + 1;
195  m_ServicesStatusDialogComponent.SetRefreshMessage(seconds, !SCR_ServicesStatusHelper.CanRefresh() && seconds > 0);
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  protected EServiceStatus GetEnumStatus(string wantedItemName)
200  {
201  ServiceStatusItem serviceItem = SCR_ServicesStatusHelper.GetStatusByName(wantedItemName);
202  if (!serviceItem)
203  return EServiceStatus.WARNING;
204 
205  return GetStatusFromString(serviceItem.Status());
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  protected EServiceStatus GetStatusFromString(string status)
210  {
211  status.ToLower();
212 
213  if (status == SCR_ServicesStatusHelper.STATUS_OK)
214  return EServiceStatus.RUNNING;
215 
216  if (status == SCR_ServicesStatusHelper.STATUS_ERROR)
217  return EServiceStatus.ERROR;
218 
219  return EServiceStatus.WARNING;
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  // TODO: look at the code where this is called, it's working weirdly
224  // the waiting-for-display logic should happen in MainMenuUI, the refresh logic in here
225  static void OpenIfServicesAreNotOK()
226  {
227  // returns false even if enabled but without internet connection for now
228  if (!SCR_ServicesStatusHelper.IsBackendEnabled())
229  {
230  // SCR_CommonDialogs.CreateServicesStatusDialog();
231  return;
232  }
233 
234  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusUpdatedOpenDialog);
235  SCR_ServicesStatusHelper.RefreshPing();
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  protected static void OnCommStatusUpdatedOpenDialog(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
240  {
241  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusUpdatedOpenDialog);
242 
243  ServiceStatusItem mainStatus = SCR_ServicesStatusHelper.GetMainStatus();
244 
245  bool statusIssues = status == SCR_ECommStatus.NOT_EXECUTED || !mainStatus || mainStatus.Status() != SCR_ServicesStatusHelper.STATUS_OK;
246  if (statusIssues && !m_bIsOpen && GetGame().m_bIsMainMenuOpen) //Open in core menus only
247  SCR_CommonDialogs.CreateServicesStatusDialog();
248  }
249 }
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
m_bIsMainMenuOpen
bool m_bIsMainMenuOpen
Definition: game.c:63
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CommonDialogs
Definition: CommonDialogs.c:5
RUNNING
@ RUNNING
Definition: SCR_ServicesStatusDialogUI.c:3
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
EServiceStatus
EServiceStatus
Definition: SCR_ServicesStatusDialogUI.c:1
WARNING
@ WARNING
Definition: SCR_ServicesStatusDialogUI.c:4
ERROR
@ ERROR
Definition: SCR_ServicesStatusDialogUI.c:5
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_ServicesStatusDialogComponent
Definition: SCR_ServicesStatusDialogComponent.c:1
SCR_ServicesStatusDialogUI
Definition: SCR_ServicesStatusDialogUI.c:8
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_BackendServiceDisplay
Definition: SCR_ServicesStatusHelper.c:438
FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition: SCR_BrowserHoverTooltipComponent.c:116
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1