Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
Login2FADialogUI.c
Go to the documentation of this file.
1
// TODO: make the number of edit boxes procedural
2
class
SCR_Login2FADialogUI
:
SCR_LoginProcessDialogUI
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
10
protected
Widget
m_wCodeWrapper
;
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
//------------------------------------------------------------------------------------------------
23
override
void
OnMenuOpen
(
SCR_ConfigurableDialogUiPreset
preset)
24
{
25
super.OnMenuOpen(preset);
26
27
// Find all edit boxes
28
m_wCodeWrapper
=
m_wRoot
.FindAnyWidget(
"CodeWrapper"
);
29
if
(
m_wCodeWrapper
)
30
{
31
array<ref Widget> editBoxes = {};
32
SCR_WidgetHelper
.GetAllChildren(
m_wCodeWrapper
, editBoxes);
33
34
foreach
(
Widget
w : editBoxes)
35
{
36
SCR_EditBoxComponent
comp =
SCR_EditBoxComponent
.Cast(w.FindHandler(
SCR_EditBoxComponent
));
37
if
(!comp)
38
continue
;
39
40
m_aEditBoxComponents
.Insert(comp);
41
BindEditBoxInputEvent
(comp);
42
}
43
}
44
45
//TODO: there is something resetting the focus to null somewhere, so we need to delay the activation. FIX!
46
GetGame
().GetCallqueue().CallLater(
ActivateFirstEditBox
,
EDIT_BOX_INITIAL_FOCUS_DELAY
);
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
{
68
ShowWarningMessage
(
true
);
69
return
;
70
}
71
BohemiaAccountApi
.Link(
m_Callback
,
m_sName
,
m_sCode
, code);
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
//------------------------------------------------------------------------------------------------
121
protected
void
BindEditBoxInputEvent
(
SCR_EditBoxComponent
comp)
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
135
foreach
(
SCR_EditBoxComponent
comp :
m_aEditBoxComponents
)
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
163
foreach
(
SCR_EditBoxComponent
comp :
m_aEditBoxComponents
)
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
174
ActivateFirstEditBox
();
175
}
176
}
177
178
//------------------------------------------------------------------------------------------------
179
class
SCR_Login2FADialogConsoleUI :
SCR_Login2FADialogUI
180
{
181
//------------------------------------------------------------------------------------------------
182
override
void
BindEditBoxInputEvent
(SCR_EditBoxComponent comp)
183
{
184
comp.
m_OnWriteModeLeave
.Insert(
OnTextChange
);
185
}
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();
192
}
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
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
OnTextChange
void OnTextChange(string text)
If number was inserted into current EditBox, add that number to the string and go to next EditBox....
Definition
Login2FADialogUI.c:307
m_s2FAText
string m_s2FAText
Definition
Login2FADialogUI.c:183
m_aEditBoxComponents
ref array< SCR_EditBoxComponent > m_aEditBoxComponents
Definition
Login2FADialogUI.c:187
BackendCallback
Definition
Backend_Storage.c:5
BohemiaAccountApi
Definition
BohemiaAccountApi.c:19
Color
Definition
Color.c:13
SCR_ConfigurableDialogUi::GetRootWidget
Widget GetRootWidget()
Definition
SCR_ConfigurableDialogUI.c:227
SCR_ConfigurableDialogUi::m_wRoot
Widget m_wRoot
Definition
SCR_ConfigurableDialogUI.c:66
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition
SCR_ConfigurableDialogUI.c:764
SCR_EditBoxComponent
Definition
SCR_EditBoxComponent.c:9
SCR_EditBoxComponent::m_OnWriteModeLeave
ref ScriptInvokerString m_OnWriteModeLeave
Definition
SCR_EditBoxComponent.c:83
SCR_EditBoxComponent::m_OnTextChange
ref ScriptInvokerString m_OnTextChange
Definition
SCR_EditBoxComponent.c:84
SCR_Login2FADialogUI
Definition
Login2FADialogUI.c:3
SCR_Login2FADialogUI::BindEditBoxInputEvent
void BindEditBoxInputEvent(SCR_EditBoxComponent comp)
Overridden in console version.
Definition
Login2FADialogUI.c:121
SCR_Login2FADialogUI::IsCodeComplete
bool IsCodeComplete()
We have a number of single digit edit boxes. Overridden in console version.
Definition
Login2FADialogUI.c:153
SCR_Login2FADialogUI::Clear
void Clear()
Definition
Login2FADialogUI.c:159
SCR_Login2FADialogUI::OnMenuClose
override void OnMenuClose()
Definition
Login2FADialogUI.c:50
SCR_Login2FADialogUI::VerifyFormatting
override bool VerifyFormatting(string text)
Definition
Login2FADialogUI.c:94
SCR_Login2FADialogUI::OnTextChange
void OnTextChange(string text)
If number was inserted into current EditBox, add that number to the string and go to next EditBox....
Definition
Login2FADialogUI.c:128
SCR_Login2FADialogUI::m_sName
string m_sName
Definition
Login2FADialogUI.c:5
SCR_Login2FADialogUI::m_wCodeWrapper
Widget m_wCodeWrapper
Definition
Login2FADialogUI.c:10
SCR_Login2FADialogUI::OnConfirm
override void OnConfirm()
Definition
Login2FADialogUI.c:59
SCR_Login2FADialogUI::OnMenuOpen
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
Definition
Login2FADialogUI.c:23
SCR_Login2FADialogUI::m_aEditBoxComponents
ref array< SCR_EditBoxComponent > m_aEditBoxComponents
Definition
Login2FADialogUI.c:8
SCR_Login2FADialogUI::OnFailDelayed
override void OnFailDelayed(BackendCallback callback)
Definition
Login2FADialogUI.c:85
SCR_Login2FADialogUI::m_s2FAText
string m_s2FAText
Definition
Login2FADialogUI.c:4
SCR_Login2FADialogUI::EDIT_BOX_FLICKER_TIME
const int EDIT_BOX_FLICKER_TIME
Definition
Login2FADialogUI.c:13
SCR_Login2FADialogUI::m_sCode
string m_sCode
Definition
Login2FADialogUI.c:6
SCR_Login2FADialogUI::OnTimeout
override void OnTimeout()
Definition
Login2FADialogUI.c:77
SCR_Login2FADialogUI::EDIT_BOX_INITIAL_FOCUS_DELAY
const int EDIT_BOX_INITIAL_FOCUS_DELAY
Definition
Login2FADialogUI.c:12
SCR_Login2FADialogUI::ActivateFirstEditBox
void ActivateFirstEditBox()
Overridden in console version.
Definition
Login2FADialogUI.c:113
SCR_Login2FADialogUI::SCR_Login2FADialogUI
void SCR_Login2FADialogUI(string name, string code)
Definition
Login2FADialogUI.c:16
SCR_LoginProcessDialogUI
Definition
SCR_LoginProcessDialogUI.c:6
SCR_LoginProcessDialogUI::m_Callback
ref BackendCallback m_Callback
Definition
SCR_LoginProcessDialogUI.c:32
SCR_LoginProcessDialogUI::ShowWarningMessage
void ShowWarningMessage(bool show)
Definition
SCR_LoginProcessDialogUI.c:199
SCR_LoginProcessDialogUI::m_bIsLoading
bool m_bIsLoading
Definition
SCR_LoginProcessDialogUI.c:30
SCR_WidgetHelper
Definition
SCR_WidgetHelper.c:2
UIColors
Definition
Constants.c:17
Widget
Definition
Widget.c:13
scripts
Game
UI
Menu
Login2FADialogUI.c
Generated by
1.17.0