Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ServicesStatusDialogUI.c
Go to the documentation of this file.
7
9{
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
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;
24
25 m_Refresh = FindButton("Refresh");
26 if (m_Refresh)
27 m_Refresh.m_OnActivated.Insert(OnRefresh);
28
30
31#ifdef WORKBENCH
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
47 GetGame().GetCallqueue().Remove(UpdateRefreshWidgets);
48 GetGame().GetCallqueue().Remove(OnRefresh);
49 }
50
51 //------------------------------------------------------------------------------------------------
63
64 //------------------------------------------------------------------------------------------------
65 protected void OnCommStatusUpdated(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
66 {
69
70 UpdateUI(status);
71
72 // Automatic refresh
73 GetGame().GetCallqueue().Remove(OnRefresh);
75 }
76
77 //------------------------------------------------------------------------------------------------
79 protected void UpdateUI(SCR_ECommStatus status)
80 {
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
125 }
126
127 //------------------------------------------------------------------------------------------------
130 {
131 EServiceStatus generalStatus = EServiceStatus.RUNNING; // General Status reporting! o7
132
133 // Main status check
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 {
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 //------------------------------------------------------------------------------------------------
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)
187
189 return;
190
192
193 // Refresh countdown
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
214 return EServiceStatus.RUNNING;
215
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
226 {
227 // returns false even if enabled but without internet connection for now
229 {
230 // SCR_CommonDialogs.CreateServicesStatusDialog();
231 return;
232 }
233
236 }
237
238 //------------------------------------------------------------------------------------------------
239 protected static void OnCommStatusUpdatedOpenDialog(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
240 {
242
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}
ArmaReforgerScripted GetGame()
Definition game.c:1398
bool m_bIsMainMenuOpen
Definition game.c:57
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Widget GetContentLayoutRoot()
Returns the root of the content layout.
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
void UpdateUI(SCR_ECommStatus status)
refresh UI through ServicesStatusDialogComponent
SCR_ServicesStatusDialogComponent m_ServicesStatusDialogComponent
EServiceStatus GetStatusFromString(string status)
void OnCommStatusUpdated(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
static void OnCommStatusUpdatedOpenDialog(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
EServiceStatus UpdateServiceStates()
Updates status of services and returns general status based on the number of active services.
EServiceStatus GetEnumStatus(string wantedItemName)
static ServiceStatusItem GetMainStatus()
static ScriptInvokerCommStatus GetOnCommStatusCheckFinished()
static bool DisplayServiceOnCurrentPlatform(SCR_BackendServiceDisplay service)
static SCR_ECommStatus GetLastReceivedCommStatus()
static ServiceStatusItem GetStatusByName(string statusName)
static int GetPingAge()
Return the last ping's age in milliseconds.
Service status item.
@ RUNNING
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
@ WARNING
Definition LogLevel.c:19
@ ERROR
Same as DELETE, but global error count for OnAfterLoad is affected.
Definition LogLevel.c:20
void UpdateUI()
Virtual method for updating the UI when an item is removed/added.