Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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)]
16
17 [Attribute("1")]
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))]
28
30
31 protected ref array<string> m_aUnavailableServices = {};
32 protected SCR_ConnectionStateButtonComponent_StatusPreset m_CurrentStatusPreset;
34
37
38 //------------------------------------------------------------------------------------------------
39 override void HandlerAttached(Widget w)
40 {
41 super.HandlerAttached(w);
42
43 if (GetGame().InPlayMode())
44 {
45 SetVisible(false);
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
58
59 GetButton().m_OnClicked.Insert(OnButtonClicked);
60 GetButton().m_OnFocus.Insert(OnButtonFocused);
61 GetButton().m_OnFocusLost.Insert(OnButtonFocusLost);
62
63 // Automatic Refresh
65 }
66
67 //------------------------------------------------------------------------------------------------
68 override void HandlerDeattached(Widget w)
69 {
70 super.HandlerDeattached(w);
71
73
74 // Owner menu events
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 //------------------------------------------------------------------------------------------------
110
111 //------------------------------------------------------------------------------------------------
112 protected void OnMenuDisabled(ChimeraMenuBase menu)
113 {
115 return;
116
118 }
119
120 //------------------------------------------------------------------------------------------------
127
128 //------------------------------------------------------------------------------------------------
129 protected void OnCommStatusUpdated(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
130 {
131 UpdateStatus(status);
132 }
133
134 //------------------------------------------------------------------------------------------------
140
141 //------------------------------------------------------------------------------------------------
142 protected void OnAutomaticRefresh()
143 {
145 }
146
147 //------------------------------------------------------------------------------------------------
148 protected void UpdateStatus(SCR_ECommStatus status)
149 {
150 switch(status)
151 {
152 case SCR_ECommStatus.FINISHED:
153 {
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
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 {
188 return true;
189
191
192 // Check states of services
193 foreach (SCR_BackendServiceDisplay serviceInfo : m_ServicesPresets.GetServices())
194 {
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
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
214 return ping > SCR_ServicesStatusHelper.PING_THRESHOLD_AWFUL || ping < 0;
215 }
216
217 //------------------------------------------------------------------------------------------------
218 protected void UpdateWidgets(SCR_ECommStatus status, bool lowBandwidth = false)
219 {
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(string.Empty);
246 }
247
248 //------------------------------------------------------------------------------------------------
249 protected void AnimateSpinner()
250 {
252 {
253 m_SpinnerAnimation.GetOnCycleCompleted().Remove(AnimateSpinner);
254 if (!ShowSpinner())
255 m_SpinnerAnimation.Stop();
256 }
257
259 return;
260
261 m_wConnectingSpinner.SetVisible(ShowSpinner());
262
263 m_wConnectingSpinner.SetRotation(0);
266 {
267 m_SpinnerAnimation.SetRepeat(true);
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 {
310 }
311
312 //------------------------------------------------------------------------------------------------
317
318 //------------------------------------------------------------------------------------------------
320 {
321 if (tooltip.GetTag() != m_sTooltipTag)
322 {
323 m_Tooltip = null;
324 return;
325 }
326
327 m_Tooltip = tooltip;
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
341 if (!content)
342 return;
343
344 if (m_CurrentStatusPreset.m_Status == SCR_ECommStatus.FINISHED)
345 {
346 // Unavailable services: the tooltips will display the list of issues
347 if (!m_aUnavailableServices.IsEmpty())
348 {
349 // fill the tooltip with the list of issues
350 Widget tooltipContent = content.GetContentRoot();
351 if (tooltipContent)
352 {
354 if (comp)
356 }
357 }
358
359 // Low bandwidth: this is the default message set in the tooltip's .conf file
360 else if (CheckLowBandwidth())
361 {
362 message = content.GetDefaultMessage();
363 messageColor = m_LowBandwidthColor;
364 }
365
366 // if everything is of the button will disappear and so should the tooltip
367 else
368 {
369 m_Tooltip.ForceHidden();
370 }
371 }
372
373 content.SetMessage(message);
374 content.SetMessageColor(messageColor);
375 }
376}
377
379class SCR_ConnectionStateButtonComponent_StatusPreset
380{
381 [Attribute(defvalue: UIConstants.ICONS_IMAGE_SET, params: "imageset")]
383
384 [Attribute(defvalue: SCR_Enum.GetDefault(SCR_ECommStatus.RUNNING), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ECommStatus))]
386
387 [Attribute(SCR_ConnectionUICommon.ICON_CONNECTION)]
388 string m_sIcon;
390 [Attribute(SCR_ConnectionUICommon.MESSAGE_CONNECTING)]
391 string m_sLabel;
393 [Attribute(UIColors.GetColorAttribute(UIColors.CONTRAST_COLOR), UIWidgets.ColorPicker)]
394 ref Color m_Color;
396 [Attribute(SCR_ConnectionUICommon.MESSAGE_CONNECTING)]
397 string m_sTooltipMessage;
399 [Attribute("1")]
400 bool m_bShowLabel;
class RestAPIHelper< JsonApiStruct T > content
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_ConnectionStateButtonComponent SCR_CoreMenuHeaderButtonComponent BaseContainerProps()] class SCR_ConnectionStateButtonComponent_StatusPreset
ref Color m_Color
ResourceName m_sImageSet
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
void UpdateWidgets()
EAnimationCurve
static WidgetAnimationImageRotation Rotation(Widget widget, float targetValue, float speed)
Constant variables used in various menus.
static ChimeraMenuBase GetOwnerMenu(Widget w)
Returns parent menu of a widget.
Definition Color.c:13
void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltip)
void UpdateWidgets(SCR_ECommStatus status, bool lowBandwidth=false)
void OnCommStatusUpdated(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
SCR_ConnectionStateButtonComponent_StatusPreset m_CurrentStatusPreset
ref SCR_BackendServiceDisplayPresets m_ServicesPresets
override void SetVisible(bool visible, bool animate=false, float rate=UIConstants.FADE_RATE_FAST)
ref array< ref SCR_ConnectionStateButtonComponent_StatusPreset > m_aStatuses
SCR_ConnectionStateButtonComponent_StatusPreset GetStatusPreset(SCR_ECommStatus status)
Helper component for core menu header button prefabs.
void Init(array< string > messages, bool showSeparator=false)
static SCR_ListTooltipComponent FindComponent(notnull Widget w)
static ScriptInvokerMenu GetOnMenuShow()
static ScriptInvokerMenu GetOnMenuHide()
static ScriptInvokerMenu GetOnMenuFocusGained()
static ScriptInvokerTooltip GetOnTooltipShow()
static ServiceStatusItem GetMainStatus()
static ScriptInvokerCommStatus GetOnCommStatusCheckFinished()
static ScriptInvokerVoid GetOnCommStatusCheckStart()
static bool DisplayServiceOnCurrentPlatform(SCR_BackendServiceDisplay service)
static SCR_ECommStatus GetLastReceivedCommStatus()
static ServiceStatusItem GetStatusByName(string statusName)
Service status item.
SCR_FieldOfViewSettings Attribute