Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
Login2FADialogUI.c
Go to the documentation of this file.
1// TODO: make the number of edit boxes procedural
3{
4 protected string m_s2FAText;
5 protected string m_sName;
6 protected string m_sCode;
7
8 protected ref array<SCR_EditBoxComponent> m_aEditBoxComponents = {};
9
11
12 protected const int EDIT_BOX_INITIAL_FOCUS_DELAY = 100;
13 protected const int EDIT_BOX_FLICKER_TIME = 400;
14
15 //------------------------------------------------------------------------------------------------
16 void SCR_Login2FADialogUI(string name, string code)
17 {
18 m_sName = name;
19 m_sCode = code;
20 }
21
22 //------------------------------------------------------------------------------------------------
24 {
25 super.OnMenuOpen(preset);
26
27 // Find all edit boxes
28 m_wCodeWrapper = m_wRoot.FindAnyWidget("CodeWrapper");
30 {
31 array<ref Widget> editBoxes = {};
32 SCR_WidgetHelper.GetAllChildren(m_wCodeWrapper, editBoxes);
33
34 foreach (Widget w : editBoxes)
35 {
37 if (!comp)
38 continue;
39
40 m_aEditBoxComponents.Insert(comp);
42 }
43 }
44
45 //TODO: there is something resetting the focus to null somewhere, so we need to delay the activation. FIX!
47 }
48
49 //------------------------------------------------------------------------------------------------
50 override void OnMenuClose()
51 {
52 super.OnMenuClose();
53
54 GetGame().GetCallqueue().Remove(OnFailDelayed);
55 GetGame().GetCallqueue().Remove(ActivateFirstEditBox);
56 }
57
58 //------------------------------------------------------------------------------------------------
59 override void OnConfirm()
60 {
61 if (m_bIsLoading)
62 return;
63
64 string code = m_s2FAText.Trim();
65
66 if (!VerifyFormatting(code))
67 {
69 return;
70 }
72
73 super.OnConfirm();
74 }
75
76 //------------------------------------------------------------------------------------------------
77 override void OnTimeout()
78 {
79 super.OnTimeout();
80
81 Clear();
82 }
83
84 //------------------------------------------------------------------------------------------------
85 override void OnFailDelayed(BackendCallback callback)
86 {
87 super.OnFailDelayed(callback);
88
89 Clear();
90 }
91
92 //------------------------------------------------------------------------------------------------
93 // Code must be entirely made out of numbers
94 override bool VerifyFormatting(string text)
95 {
96 if (!IsCodeComplete() || text.Contains(" "))
97 return false;
98
99 for (int i = 0; i < text.Length(); i++)
100 {
101 string char = text[i];
102 int asciiCode = char.ToAscii();
103
104 if (asciiCode < 48 || asciiCode > 57)
105 return false;
106 }
107
108 return super.VerifyFormatting(text);
109 }
110
111 //------------------------------------------------------------------------------------------------
113 protected void ActivateFirstEditBox()
114 {
115 if (!m_aEditBoxComponents.IsEmpty())
116 m_aEditBoxComponents[0].ActivateWriteMode(true);
117 }
118
119 //------------------------------------------------------------------------------------------------
122 {
123 comp.m_OnTextChange.Insert(OnTextChange);
124 }
125
126 //------------------------------------------------------------------------------------------------
128 protected void OnTextChange(string text)
129 {
130 if (m_bIsLoading || text.IsEmpty())
131 return;
132
133 m_s2FAText = string.Empty;
134
136 {
137 string value = comp.GetValue();
138 if (value.IsEmpty())
139 {
140 comp.ActivateWriteMode(true);
141 break;
142 }
143
144 m_s2FAText += value;
145 }
146
147 if (IsCodeComplete())
148 OnConfirm();
149 }
150
151 //------------------------------------------------------------------------------------------------
153 protected bool IsCodeComplete()
154 {
155 return m_s2FAText.Length() >= m_aEditBoxComponents.Count();
156 }
157
158 //------------------------------------------------------------------------------------------------
159 protected void Clear()
160 {
161 m_s2FAText = string.Empty;
162
164 {
165 comp.SetValue(string.Empty);
166
167 // Flicker components
168 GetGame().GetCallqueue().Remove(comp.ResetOverlayColor);
169
170 comp.ChangeOverlayColor(Color.FromInt(UIColors.WARNING.PackToInt()));
171 GetGame().GetCallqueue().CallLater(comp.ResetOverlayColor, EDIT_BOX_FLICKER_TIME);
172 }
173
175 }
176}
177
178//------------------------------------------------------------------------------------------------
179class SCR_Login2FADialogConsoleUI : SCR_Login2FADialogUI
180{
181 //------------------------------------------------------------------------------------------------
182 override void BindEditBoxInputEvent(SCR_EditBoxComponent comp)
186
187 //------------------------------------------------------------------------------------------------
188 // We have a single edit box in which the whole code is inserted
189 override bool IsCodeComplete()
190 {
191 return !m_s2FAText.IsEmpty();
193
194 //------------------------------------------------------------------------------------------------
195 // We don't want to activate the edit box automatically or the dialog will be obscured by the virtual console, so we just focus it
196 override void ActivateFirstEditBox()
197 {
198 if (!m_aEditBoxComponents.IsEmpty())
199 GetGame().GetWorkspace().SetFocusedWidget(m_aEditBoxComponents[0].GetRootWidget());
200 }
201}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void OnTextChange(string text)
If number was inserted into current EditBox, add that number to the string and go to next EditBox....
string m_s2FAText
ref array< SCR_EditBoxComponent > m_aEditBoxComponents
Definition Color.c:13
ref ScriptInvokerString m_OnWriteModeLeave
ref ScriptInvokerString m_OnTextChange
void BindEditBoxInputEvent(SCR_EditBoxComponent comp)
Overridden in console version.
bool IsCodeComplete()
We have a number of single digit edit boxes. Overridden in console version.
override void OnMenuClose()
override bool VerifyFormatting(string text)
void OnTextChange(string text)
If number was inserted into current EditBox, add that number to the string and go to next EditBox....
override void OnConfirm()
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
ref array< SCR_EditBoxComponent > m_aEditBoxComponents
override void OnFailDelayed(BackendCallback callback)
override void OnTimeout()
const int EDIT_BOX_INITIAL_FOCUS_DELAY
void ActivateFirstEditBox()
Overridden in console version.
void SCR_Login2FADialogUI(string name, string code)