Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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  // Warning messages
18  protected const string WARNING_SUCCESS_IMG = "check";
19  protected const string WARNING_FAILED_IMG = "warning";
20  protected const string WARNING_TIMEOUT_IMG = "disconnection";
21 
22  protected const string WARNING_TIMEOUT = "#AR-Account_LoginTimeout";
23 
24  // Buttons
25  protected SCR_InputButtonComponent m_TOSButton;
26  protected SCR_InputButtonComponent m_ConfirmButton;
27  protected SCR_InputButtonComponent m_CreateAccount;
28 
29  protected SCR_ButtonImageComponent m_CopyButtonComponent;
30  protected RichTextWidget m_wPIDText;
31 
32  // Other
33  protected SCR_LoadingOverlay m_LoadingOverlay;
34  protected SCR_SimpleWarningComponent m_Warning;
35 
36  protected bool m_bForceConfirmButtonDisabled;
37  protected bool m_bIsLoading;
38 
39  protected ref SCR_BackendCallback m_Callback;
40 
41  protected const int ON_FAIL_DELAY = 2000;
42 
43  protected static const ResourceName DIALOG_CONFIG = "{9381BF296A0E273B}Configs/Dialogs/LoginDialogs.conf";
44 
45  // Dialog creation
46  //------------------------------------------------------------------------------------------------
47  static void CreateLoginDialog()
48  {
50  {
51  SCR_LoginDialogConsoleUI dialog = new SCR_LoginDialogConsoleUI();
52  SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "LOGIN_CONSOLE", dialog);
53 
54  return;
55  }
56 
57  SCR_LoginDialogUI dialog = new SCR_LoginDialogUI();
58  SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "LOGIN", dialog);
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  static SCR_PlayerProfileDialogUI CreateProfileDialog()
63  {
65  SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "PLAYER_PROFILE", dialog);
66 
67  return dialog;
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  static void Create2FADialog(string name, string code)
72  {
74  {
75  SCR_Login2FADialogConsoleUI dialog = new SCR_Login2FADialogConsoleUI(name, code);
76  SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "2FA_CONSOLE", dialog);
77 
78  return;
79  }
80 
81  SCR_Login2FADialogUI dialog = new SCR_Login2FADialogUI(name, code);
82  SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "2FA", dialog);
83  }
84 
85  // Generic account related feedback dialogs
86  // We use the SCR_ConfigurableDialogUi because confirming must close the dialog and there's no need for SCR_LoginProcessDialogUI functionalities
87  //------------------------------------------------------------------------------------------------
88  static SCR_ConfigurableDialogUi CreateLoginSuccessDialog()
89  {
90  return SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "LOGIN_SUCCESS");
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  static SCR_ConfigurableDialogUi CreateLoginTimeoutDialog()
95  {
96  return SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "LOGIN_TIMEOUT");
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  static SCR_AccountLockedDialogUi CreateAccountLockedDialog()
101  {
102  SCR_AccountLockedDialogUi dialog = new SCR_AccountLockedDialogUi();
103  SCR_ConfigurableDialogUi.CreateFromPreset(DIALOG_CONFIG, "ACCOUNT_LOCKED", dialog);
104 
105  return dialog;
106  }
107 
108  // Overrides
109  //------------------------------------------------------------------------------------------------
110  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
111  {
112  super.OnMenuOpen(preset);
113 
114  m_TOSButton = FindButton(TOS_BUTTON);
115  if (m_TOSButton)
116  m_TOSButton.m_OnActivated.Insert(OnTOSButton);
117 
118  m_CreateAccount = FindButton(REGISTER_BUTTON);
119  if (m_CreateAccount)
120  m_CreateAccount.m_OnActivated.Insert(OnCreateAccount);
121 
122  m_ConfirmButton = FindButton(BUTTON_CONFIRM);
123 
124  m_wPIDText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(PID_TEXT_WIDGET));
125 
126  m_CopyButtonComponent = SCR_ButtonImageComponent.GetButtonImage(PID_BUTTON_WIDGET, m_wRoot);
127  if (m_CopyButtonComponent)
128  m_CopyButtonComponent.m_OnClicked.Insert(CopyPID);
129 
130  m_Warning = SCR_SimpleWarningComponent.FindComponentInHierarchy(m_wRoot);
131  ShowWarningMessage(false);
132 
133  // Status check
134  SCR_ServicesStatusHelper.RefreshPing();
135  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusCheckFinished);
136 
137  UpdateButtons();
138 
139  // Callback events
141 
142  m_Callback.GetEventOnSuccess().Insert(OnSuccess);
143  m_Callback.GetEventOnFail().Insert(OnFail);
144  m_Callback.GetEventOnTimeOut().Insert(OnTimeout);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  override void OnMenuClose()
149  {
150  super.OnMenuClose();
151 
152  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusCheckFinished);
153 
154  GetGame().GetCallqueue().Remove(OnTimeoutScripted);
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  override void OnConfirm()
159  {
160  ShowLoadingAnim(true);
161  ShowWarningMessage(false);
162 
163  // fallback timeout should the backend callback not work
164  GetGame().GetCallqueue().Remove(OnTimeoutScripted);
165  GetGame().GetCallqueue().CallLater(OnTimeoutScripted, SCR_ServicesStatusHelper.AUTOMATIC_REFRESH_RATE);
166  }
167 
168  // Methods
169  //------------------------------------------------------------------------------------------------
170  protected bool UpdateButtons()
171  {
172  string service = SCR_ServicesStatusHelper.SERVICE_ACCOUNT_PROFILE;
173 
174  SCR_InputButtonComponent.ForceConnectionButtonEnabled(m_TOSButton, SCR_ServicesStatusHelper.IsBackendConnectionAvailable(), false);
175  SCR_InputButtonComponent.ForceConnectionButtonEnabled(m_CreateAccount, SCR_ServicesStatusHelper.IsBackendConnectionAvailable(), false);
176 
177  SCR_InputButtonComponent.SetConnectionButtonEnabled(m_ConfirmButton, service, m_bForceConfirmButtonDisabled || ! SCR_ServicesStatusHelper.IsBackendConnectionAvailable(), false);
178 
179  string identity;
180  BackendApi backendAPI = GetGame().GetBackendApi();
181  if (backendAPI)
182  identity = backendAPI.GetLocalIdentityId();
183 
184  if (m_wPIDText)
185  m_wPIDText.SetText(identity);
186 
187  if (m_CopyButtonComponent)
188  m_CopyButtonComponent.SetVisible(!GetGame().IsPlatformGameConsole() && !identity.IsEmpty(), false);
189 
190  if (m_wPIDText)
191  m_wPIDText.SetVisible(!identity.IsEmpty());
192 
193  return SCR_ServicesStatusHelper.IsServiceActive(service);
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  protected void ShowLoadingAnim(bool show)
198  {
199  m_bIsLoading = show;
200 
201  if (show)
202  m_LoadingOverlay = SCR_LoadingOverlay.ShowForWidget(GetDialogBaseOverlay(), string.Empty, false, true);
203  else if (m_LoadingOverlay)
204  m_LoadingOverlay.HideAndDelete();
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  protected void ShowWarningMessage(bool show)
209  {
210  if (m_Warning)
211  m_Warning.SetWarningVisible(show);
212  }
213 
214  //------------------------------------------------------------------------------------------------
216  protected void CopyPID()
217  {
218  System.ExportToClipboard(m_wPIDText.GetText());
219  }
220 
221  //------------------------------------------------------------------------------------------------
223  protected bool VerifyFormatting(string text)
224  {
225  return true;
226  }
227 
228  // Events
229  //------------------------------------------------------------------------------------------------
230  protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
231  {
232  UpdateButtons();
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  protected void OnTOSButton()
237  {
238  GetGame().GetPlatformService().OpenBrowser(GetGame().GetBackendApi().GetLinkItem(TOS_LINK));
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  private void OnCreateAccount()
243  {
244  GetGame().GetPlatformService().OpenBrowser(GetGame().GetBackendApi().GetLinkItem(REGISTER_LINK));
245  }
246 
247  //------------------------------------------------------------------------------------------------
248  protected void OnSuccess(SCR_BackendCallback callback)
249  {
250  CreateLoginSuccessDialog();
251  Close();
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  protected void OnFail(SCR_BackendCallback callback, int code, int restCode, int apiCode)
256  {
257  GetGame().GetCallqueue().Remove(OnTimeoutScripted);
258 
259  // Add a delay to prevent the backend from being overwhelmed
260  // TODO: change this into a cooldown after the response has been received to make the UI as responsive as possible
261  GetGame().GetCallqueue().Remove(OnFailDelayed);
262  GetGame().GetCallqueue().CallLater(OnFailDelayed, ON_FAIL_DELAY, false, callback, code, restCode, apiCode);
263  }
264 
265  //------------------------------------------------------------------------------------------------
266  protected void OnTimeout(SCR_BackendCallback callback)
267  {
268  GetGame().GetCallqueue().Remove(OnTimeoutScripted);
269 
270  ShowLoadingAnim(false);
271  ShowWarningMessage(false);
272 
273  CreateLoginTimeoutDialog();
274  }
275 
276  //------------------------------------------------------------------------------------------------
277  protected void OnFailDelayed(SCR_BackendCallback callback, int code, int restCode, int apiCode)
278  {
279  GetGame().GetCallqueue().Remove(OnFailDelayed);
280 
281  ShowLoadingAnim(false);
282  ShowWarningMessage(false);
283 
284  // Based on restCode
285  // wrong credentials: 401
286  if (restCode == SCR_ELoginFailReason.INVALID_CREDENTIALS)
287  {
288  ShowWarningMessage(true);
289  return;
290  }
291 
292  // bad request: 400
293  // user not found: EApiCode.EACODE_ERROR_USER_NOT_FOUND -> player wrote wrong credentials
294  if (apiCode == EApiCode.EACODE_ERROR_USER_NOT_FOUND)
295  ShowWarningMessage(true);
296 
297  // account locked: EApiCode.EACODE_ERROR_USER_LOCKED
298  else if (apiCode == EApiCode.EACODE_ERROR_USER_LOCKED)
299  CreateAccountLockedDialog();
300 
301  else
302  CreateLoginTimeoutDialog();
303  }
304 
305  //------------------------------------------------------------------------------------------------
306  protected void OnTimeoutScripted()
307  {
308  OnTimeout(m_Callback);
309  }
310 }
311 
312 //------------------------------------------------------------------------------------------------
313 class SCR_AccountLockedDialogUi : SCR_ConfigurableDialogUi
314 {
315  protected const string MAIN_MESSAGE = "#AR-Account_Locked_Message";
316  protected const string CONTENT_MESSAGE = "#AR-CoreMenus_Support";
317  protected const string MINUTES = "#AR-ValueUnit_Short_Minutes";
318  protected const string SECONDS = "#AR-ValueUnit_Short_Seconds";
319 
320  protected const string SUPPORT = "Link_SupportEmail";
321 
322  //------------------------------------------------------------------------------------------------
324  {
325  super.OnMenuOpen(preset);
326 
327  if (!SCR_ServicesStatusHelper.IsBackendConnectionAvailable())
328  return;
329 
330  RichTextWidget widget = RichTextWidget.Cast(GetContentWidget(m_wRoot).FindAnyWidget("ContentText"));
331  if (!widget)
332  return;
333 
334  string message = string.Format("<color rgba=%1>%2</color>", UIColors.SRGBAFloatToInt(UIColors.CONTRAST_COLOR), GetGame().GetBackendApi().GetLinkItem(SUPPORT));
335  widget.SetText(WidgetManager.Translate(CONTENT_MESSAGE, message));
336 
337  UpdateMessage();
338  GetGame().GetCallqueue().CallLater(UpdateMessage, 1000, true);
339  }
340 
341  //------------------------------------------------------------------------------------------------
342  override void OnMenuClose()
343  {
344  super.OnMenuClose();
345 
346  GetGame().GetCallqueue().Remove(UpdateMessage);
347  }
348 
349  //------------------------------------------------------------------------------------------------
350  protected void UpdateMessage()
351  {
352  int seconds = GetGame().GetBackendApi().RemainingAccountLockedTime();
353  int minutes = seconds / 60;
354 
355  string time = WidgetManager.Translate(MINUTES, minutes) + " " + WidgetManager.Translate(SECONDS, seconds - (60 * minutes));
356  if (seconds < 60)
357  time = WidgetManager.Translate(SECONDS, seconds);
358 
359  SetMessage(WidgetManager.Translate(MAIN_MESSAGE, time));
360  }
361 }
362 
363 //------------------------------------------------------------------------------------------------
365 {
366  BAD_REQUEST = 400,
369 }
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
SCR_PlayerProfileDialogUI
Definition: SCR_PlayerProfileDialogUI.c:2
SCR_SimpleWarningComponent
Definition: SCR_SimpleWarningComponent.c:2
SetMessage
bool SetMessage(string message)
Definition: SCR_BrowserHoverTooltipComponent.c:255
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetContentWidget
Widget GetContentWidget()
Definition: SCR_ScriptedWidgetTooltip.c:329
SCR_LoginDialogUI
Definition: LoginDialogUI.c:2
INVALID_CREDENTIALS
@ INVALID_CREDENTIALS
Definition: SCR_LoginProcessDialogUI.c:367
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
IsPlatformGameConsole
bool IsPlatformGameConsole()
Definition: game.c:1393
SCR_Login2FADialogUI
void SCR_Login2FADialogUI(string name, string code)
Definition: Login2FADialogUI.c:14
m_Callback
protected ref CampaignCallback m_Callback
Definition: SCR_PlayerProfileManagerComponent.c:25
SCR_LoadingOverlay
Definition: SCR_LoadingOverlay.c:49
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
BAD_REQUEST
@ BAD_REQUEST
Definition: SCR_LoginProcessDialogUI.c:366
m_LoadingOverlay
protected SCR_LoadingOverlay m_LoadingOverlay
Definition: SCR_BackendImageComponent.c:250
UpdateMessage
protected void UpdateMessage()
Definition: SCR_LoginProcessDialogUI.c:350
MAIN_MESSAGE
SCR_LoginProcessDialogUI MAIN_MESSAGE
UIColors
Definition: Constants.c:16
TWO_FACTOR_AUTHENTICATION
@ TWO_FACTOR_AUTHENTICATION
Definition: SCR_LoginProcessDialogUI.c:368
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_Login2FADialogUI
Definition: Login2FADialogUI.c:2
SCR_ELoginFailReason
SCR_ELoginFailReason
Definition: SCR_LoginProcessDialogUI.c:364
GetDialogBaseOverlay
override OverlayWidget GetDialogBaseOverlay()
Definition: LoginDialogUI.c:151
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
MINUTES
const protected string MINUTES
Definition: SCR_LoginProcessDialogUI.c:317
OnMenuClose
override void OnMenuClose()
Definition: SCR_LoginProcessDialogUI.c:342
CONTENT_MESSAGE
const protected string CONTENT_MESSAGE
Definition: SCR_LoginProcessDialogUI.c:316
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SECONDS
const protected string SECONDS
Definition: SCR_LoginProcessDialogUI.c:318
callback
DownloadConfigCallback callback
SUPPORT
const protected string SUPPORT
Definition: SCR_LoginProcessDialogUI.c:320
SCR_ButtonImageComponent
Definition: SCR_ButtonImageComponent.c:2
FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition: SCR_BrowserHoverTooltipComponent.c:116
SCR_LoginProcessDialogUI
Definition: SCR_LoginProcessDialogUI.c:5
OnMenuOpen
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
Definition: SCR_LoginProcessDialogUI.c:323
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1