Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoginProcessDialogUI.c
Go to the documentation of this file.
1/*
2 Parent class of login/profile dialogs
3*/
4//------------------------------------------------------------------------------------------------
6{
7 // Widgets
8 protected const string TOS_BUTTON = "ProfileTOS";
9 protected const string TOS_LINK = "Link_PrivacyPolicy";
10
11 protected const string REGISTER_BUTTON = "createAccount";
12 protected const string REGISTER_LINK = "Link_RegisterAccount";
13
14 protected const string PID_TEXT_WIDGET = "PIDText";
15 protected const string PID_BUTTON_WIDGET = "CopyPIDButton";
16
17 // Buttons
21
24
25 // Other
28
30 protected bool m_bIsLoading;
31
33
34 protected const int ON_FAIL_DELAY = 2000;
35
36 protected static const ResourceName DIALOG_CONFIG = "{9381BF296A0E273B}Configs/Dialogs/LoginDialogs.conf";
37
38 // Dialog creation
39 //------------------------------------------------------------------------------------------------
41 {
43 {
44 SCR_LoginDialogConsoleUI dialog = new SCR_LoginDialogConsoleUI();
46
47 return dialog;
48 }
49
52
53 return dialog;
54 }
55
56 //------------------------------------------------------------------------------------------------
64
65 //------------------------------------------------------------------------------------------------
66 static void Create2FADialog(string name, string code)
67 {
69 {
70 SCR_Login2FADialogConsoleUI dialog = new SCR_Login2FADialogConsoleUI(name, code);
72
73 return;
74 }
75
76 SCR_Login2FADialogUI dialog = new SCR_Login2FADialogUI(name, code);
78 }
79
80 // Generic account related feedback dialogs
81 // We use the SCR_ConfigurableDialogUi because confirming must close the dialog and there's no need for SCR_LoginProcessDialogUI functionalities
82 //------------------------------------------------------------------------------------------------
87
88 //------------------------------------------------------------------------------------------------
93
94 //------------------------------------------------------------------------------------------------
95 static SCR_AccountLockedDialogUi CreateAccountLockedDialog()
96 {
97 SCR_AccountLockedDialogUi dialog = new SCR_AccountLockedDialogUi();
99
100 return dialog;
101 }
102
103 // Overrides
104 //------------------------------------------------------------------------------------------------
106 {
107 super.OnMenuOpen(preset);
108
110 if (m_TOSButton)
111 m_TOSButton.m_OnActivated.Insert(OnTOSButton);
112
114 if (m_CreateAccount)
115 m_CreateAccount.m_OnActivated.Insert(OnCreateAccount);
116
118
119 m_wPIDText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(PID_TEXT_WIDGET));
120
123 m_CopyButtonComponent.m_OnClicked.Insert(CopyPID);
124
126 ShowWarningMessage(false);
127
128 // Status check
131
133
134 // Callback events
136
137 m_Callback.SetOnSuccess(OnSuccess);
138 m_Callback.SetOnError(OnFail);
139 }
140
141 //------------------------------------------------------------------------------------------------
142 override void OnMenuClose()
143 {
144 super.OnMenuClose();
145
147
148 GetGame().GetCallqueue().Remove(OnTimeoutScripted);
149 }
150
151 //------------------------------------------------------------------------------------------------
152 override void OnConfirm()
153 {
154 ShowLoadingAnim(true);
155 ShowWarningMessage(false);
156
157 // fallback timeout should the backend callback not work
158 GetGame().GetCallqueue().Remove(OnTimeoutScripted);
160 }
161
162 // Methods
163 //------------------------------------------------------------------------------------------------
164 protected bool UpdateButtons()
165 {
167
170
172
173 string identity = BackendAuthenticatorApi.GetIdentityId();
174
175 if (m_wPIDText)
176 m_wPIDText.SetText(identity);
177
179 m_CopyButtonComponent.SetVisible(!GetGame().IsPlatformGameConsole() && !identity.IsEmpty(), false);
180
181 if (m_wPIDText)
182 m_wPIDText.SetVisible(!identity.IsEmpty());
183
185 }
186
187 //------------------------------------------------------------------------------------------------
188 protected void ShowLoadingAnim(bool show)
189 {
190 m_bIsLoading = show;
191
192 if (show)
194 else if (m_LoadingOverlay)
195 m_LoadingOverlay.HideAndDelete();
196 }
197
198 //------------------------------------------------------------------------------------------------
199 protected void ShowWarningMessage(bool show)
200 {
201 if (m_Warning)
202 m_Warning.SetWarningVisible(show);
203 }
204
205 //------------------------------------------------------------------------------------------------
207 protected void CopyPID()
208 {
209 System.ExportToClipboard(m_wPIDText.GetText());
210 }
211
212 //------------------------------------------------------------------------------------------------
214 protected bool VerifyFormatting(string text)
215 {
216 return true;
217 }
218
219 // Events
220 //------------------------------------------------------------------------------------------------
221 protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
222 {
224 }
225
226 //------------------------------------------------------------------------------------------------
227 protected void OnTOSButton()
228 {
229 GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.PrivacyPolicyMenu);
230 Close();
231 }
232
233 //------------------------------------------------------------------------------------------------
234 private void OnCreateAccount()
235 {
236 GetGame().GetPlatformService().OpenBrowser(GetGame().GetBackendApi().GetLinkItem(REGISTER_LINK));
237 }
238
239 //------------------------------------------------------------------------------------------------
240 protected void OnSuccess(BackendCallback callback)
241 {
243 Close();
244 }
245
246 //------------------------------------------------------------------------------------------------
247 protected void OnFail(BackendCallback callback)
248 {
249 GetGame().GetCallqueue().Remove(OnTimeoutScripted);
250
251 if (callback.GetRestResult() != ERestResult.EREST_ERROR_TIMEOUT)
252 {
253 // Add a delay to prevent the backend from being overwhelmed
254 // TODO: change this into a cooldown after the response has been received to make the UI as responsive as possible
255 GetGame().GetCallqueue().Remove(OnFailDelayed);
256 GetGame().GetCallqueue().CallLater(OnFailDelayed, ON_FAIL_DELAY, false, callback);
257 return;
258 }
259
260 // Timeout handling
261 ShowLoadingAnim(false);
262 ShowWarningMessage(false);
263
265 }
266
267 //------------------------------------------------------------------------------------------------
268 protected void OnTimeout()
269 {
270 GetGame().GetCallqueue().Remove(OnTimeoutScripted);
271
272 ShowLoadingAnim(false);
273 ShowWarningMessage(false);
274
276 }
277
278 //------------------------------------------------------------------------------------------------
279 protected void OnFailDelayed(BackendCallback callback)
280 {
281 GetGame().GetCallqueue().Remove(OnFailDelayed);
282
283 ShowLoadingAnim(false);
284 ShowWarningMessage(false);
285
286 // Based on restCode
287 // wrong credentials: 401
288 if (callback.GetHttpCode() == SCR_ELoginFailReason.INVALID_CREDENTIALS)
289 {
290 ShowWarningMessage(true);
291 return;
292 }
293
294 // bad request: 400
295 // user not found: EApiCode.EACODE_ERROR_USER_NOT_FOUND -> player wrote wrong credentials
296 if (callback.GetApiCode() == EApiCode.EACODE_ERROR_USER_NOT_FOUND)
297 ShowWarningMessage(true);
298
299 // account locked: EApiCode.EACODE_ERROR_USER_LOCKED
300 else if (callback.GetApiCode() == EApiCode.EACODE_ERROR_USER_LOCKED)
302
303 else
305 }
306
307 //------------------------------------------------------------------------------------------------
308 protected void OnTimeoutScripted()
309 {
310 OnTimeout();
311 }
312
313 //------------------------------------------------------------------------------------------------
315 {
316 return m_Callback;
317 }
318}
319
320class SCR_AccountLockedDialogUi : SCR_ConfigurableDialogUi
321{
322 protected const string MAIN_MESSAGE = "#AR-Account_Locked_Message";
323 protected const string CONTENT_MESSAGE = "#AR-CoreMenus_Support";
324 protected const string MINUTES = "#AR-ValueUnit_Short_Minutes";
325 protected const string SECONDS = "#AR-ValueUnit_Short_Seconds";
326
327 protected const string SUPPORT = "Link_SupportEmail";
328
329 //------------------------------------------------------------------------------------------------
331 {
332 super.OnMenuOpen(preset);
333
335 return;
336
337 RichTextWidget widget = RichTextWidget.Cast(GetContentWidget(m_wRoot).FindAnyWidget("ContentText"));
338 if (!widget)
339 return;
340
341 string message = string.Format("<color rgba=%1>%2</color>", UIColors.FormatColor(UIColors.CONTRAST_COLOR), GetGame().GetBackendApi().GetLinkItem(SUPPORT));
342 widget.SetTextFormat(CONTENT_MESSAGE, message);
343
345 GetGame().GetCallqueue().CallLater(UpdateMessage, 1000, true);
346 }
347
348 //------------------------------------------------------------------------------------------------
349 override void OnMenuClose()
350 {
351 super.OnMenuClose();
352
353 GetGame().GetCallqueue().Remove(UpdateMessage);
354 }
355
356 //------------------------------------------------------------------------------------------------
357 protected void UpdateMessage()
358 {
359 int seconds = BohemiaAccountApi.GetSecondsUntilAccountUnlockTime();
360 int minutes = seconds / 60;
361
362 string time = WidgetManager.Translate(MINUTES, minutes) + " " + WidgetManager.Translate(SECONDS, seconds - (60 * minutes));
363 if (seconds < 60)
364 time = WidgetManager.Translate(SECONDS, seconds);
365
366 SetMessage(WidgetManager.Translate(MAIN_MESSAGE, time));
367 }
368}
369
370//------------------------------------------------------------------------------------------------
ChimeraMenuPreset
Menu presets.
@ MINUTES
@ SECONDS
bool IsPlatformGameConsole()
Definition game.c:1357
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_Login2FADialogUI(string name, string code)
Widget m_wRoot
Widget GetContentWidget()
@ TWO_FACTOR_AUTHENTICATION
const string SUPPORT
SCR_LoginProcessDialogUI MAIN_MESSAGE
const string CONTENT_MESSAGE
void UpdateMessage()
override void OnMenuOpen()
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
static SCR_ConfigurableDialogUi CreateFromPreset(ResourceName presetsResourceName, string tag, SCR_ConfigurableDialogUi customDialogObj=null)
Creates a dialog from preset.
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
OverlayWidget GetDialogBaseOverlay()
Returns the base dialog overlay (the rectangle covered by the background). Useful for dialog wide dar...
static SCR_LoadingOverlay ShowForWidget(Widget targetWidget, string text=string.Empty, bool showBlur=true, bool showBackground=true)
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
static SCR_AccountLockedDialogUi CreateAccountLockedDialog()
SCR_InputButtonComponent m_TOSButton
static SCR_LoginDialogUI CreateLoginDialog()
static SCR_ConfigurableDialogUi CreateLoginSuccessDialog()
void OnFailDelayed(BackendCallback callback)
bool VerifyFormatting(string text)
Override in children.
SCR_SimpleWarningComponent m_Warning
static SCR_PlayerProfileDialogUI CreateProfileDialog()
static const ResourceName DIALOG_CONFIG
SCR_InputButtonComponent m_ConfirmButton
SCR_InputButtonComponent m_CreateAccount
void OnFail(BackendCallback callback)
void CopyPID()
Copy playerID to clipboard.
SCR_ButtonImageComponent m_CopyButtonComponent
void OnSuccess(BackendCallback callback)
static SCR_ConfigurableDialogUi CreateLoginTimeoutDialog()
static void Create2FADialog(string name, string code)
void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
static bool IsServiceActive(string serviceName)
static const string SERVICE_ACCOUNT_PROFILE
static ScriptInvokerCommStatus GetOnCommStatusCheckFinished()
static SCR_SimpleWarningComponent FindComponentInHierarchy(notnull Widget root)
EApiCode
Definition EApiCode.c:13
ERestResult
States and result + error code produced by RestApi.
Definition ERestResult.c:14