11using Intersect . Client . Core ;
22using Intersect . Client . Framework . File_Management ;
3+ using Intersect . Client . Framework . Graphics ;
4+ using Intersect . Client . Framework . Gwen ;
35using Intersect . Client . Framework . Gwen . Control ;
46using Intersect . Client . Framework . Gwen . Control . EventArguments ;
57using Intersect . Client . Framework . Input ;
@@ -14,58 +16,114 @@ namespace Intersect.Client.Interface.Menu;
1416
1517public partial class LoginWindow : ImagePanel , IMainMenuWindow
1618{
19+ private readonly GameFont ? _defaultFont ;
20+
1721 private readonly MainMenu _mainMenu ;
18- private readonly TextBox _txtUsername ;
19- private readonly TextBoxPassword _txtPassword ;
20- private readonly LabeledCheckBox _chkSavePass ;
22+ private readonly ImagePanel _usernamePanel ;
23+ private readonly Label _usernameLabel ;
24+ private readonly TextBox _usernameInput ;
25+ private readonly ImagePanel _passwordPanel ;
26+ private readonly TextBoxPassword _passwordInput ;
27+ private readonly LabeledCheckBox _savePasswordCheckbox ;
2128 private readonly Button _btnForgotPassword ;
2229 private readonly Button _btnLogin ;
2330 private bool _useSavedPass ;
2431 private string _savedPass = string . Empty ;
32+ private readonly Label _passwordLabel ;
2533
2634 //Init
2735 public LoginWindow ( Canvas parent , MainMenu mainMenu ) : base ( parent , "LoginWindow" )
2836 {
2937 //Assign References
3038 _mainMenu = mainMenu ;
3139
40+ _defaultFont = GameContentManager . Current . GetFont ( name : "sourcesansproblack" , 10 ) ;
41+
3242 //Menu Header
3343 _ = new Label ( this , "LoginHeader" )
3444 {
3545 Text = Strings . LoginWindow . Title ,
3646 } ;
3747
3848 //Login Username Label/Textbox
39- var usernameBackground = new ImagePanel ( this , "UsernamePanel" ) ;
40- _ = new Label ( usernameBackground , "UsernameLabel" )
49+ _usernamePanel = new ImagePanel ( this , nameof ( _usernamePanel ) )
50+ {
51+ X = 14 ,
52+ Y = 61 ,
53+ Width = 308 ,
54+ Height = 22 ,
55+ Margin = new Margin ( 14 , 0 , 0 , 0 ) ,
56+ } ;
57+ _usernameLabel = new Label ( _usernamePanel , nameof ( _usernameLabel ) )
4158 {
59+ AutoSizeToContents = false ,
60+ Dock = Pos . Left ,
61+ Font = _defaultFont ,
4262 Text = Strings . LoginWindow . Username ,
63+ TextAlign = Pos . Right | Pos . CenterV ,
64+ TextPadding = new Padding ( 0 , 0 , 10 , 0 ) ,
65+ } ;
66+ _usernameInput = new TextBox ( _usernamePanel , nameof ( _usernameInput ) )
67+ {
68+ Dock = Pos . Fill ,
69+ Font = _defaultFont ,
70+ TextAlign = Pos . Left | Pos . CenterV ,
71+ TextPadding = new Padding ( 2 , 0 ) ,
4372 } ;
44- _txtUsername = new TextBox ( usernameBackground , "UsernameField" ) ;
45- _txtUsername . SubmitPressed += ( s , e ) => TryLogin ( ) ;
46- _txtUsername . Clicked += _txtUsername_Clicked ;
73+ _usernameInput . SubmitPressed += ( s , e ) => TryLogin ( ) ;
74+ _usernameInput . Clicked += UsernameInputClicked ;
75+ _usernameInput . SetSound ( TextBox . Sounds . AddText , "octave-tap-resonant.wav" ) ;
76+ _usernameInput . SetSound ( TextBox . Sounds . RemoveText , "octave-tap-professional.wav" ) ;
77+ _usernameInput . SetSound ( TextBox . Sounds . Submit , "octave-tap-warm.wav" ) ;
4778
4879 //Login Password Label/Textbox
49- var passwordBackground = new ImagePanel ( this , "PasswordPanel" ) ;
50- _ = new Label ( passwordBackground , "PasswordLabel" )
80+ _passwordPanel = new ImagePanel ( this , nameof ( _passwordPanel ) )
5181 {
82+ X = 14 ,
83+ Y = 96 ,
84+ Width = 308 ,
85+ Height = 22 ,
86+ Margin = new Margin ( 14 , 0 , 0 , 0 ) ,
87+ } ;
88+ _passwordLabel = new Label ( _passwordPanel , nameof ( _passwordLabel ) )
89+ {
90+ AutoSizeToContents = false ,
91+ Dock = Pos . Left ,
92+ Font = _defaultFont ,
5293 Text = Strings . LoginWindow . Password ,
94+ TextAlign = Pos . Right | Pos . CenterV ,
95+ TextPadding = new Padding ( 0 , 0 , 10 , 0 ) ,
5396 } ;
54- _txtPassword = new TextBoxPassword ( passwordBackground , "PasswordField" ) ;
55- _txtPassword . SubmitPressed += ( s , e ) => TryLogin ( ) ;
56- _txtPassword . TextChanged += _txtPassword_TextChanged ;
57- _txtPassword . Clicked += _txtPassword_Clicked ;
97+ _passwordInput = new TextBoxPassword ( _passwordPanel , nameof ( _passwordInput ) )
98+ {
99+ Dock = Pos . Fill ,
100+ Font = _defaultFont ,
101+ TextAlign = Pos . Left | Pos . CenterV ,
102+ TextPadding = new Padding ( 2 , 0 ) ,
103+ } ;
104+ _passwordInput . SubmitPressed += ( s , e ) => TryLogin ( ) ;
105+ _passwordInput . TextChanged += PasswordInputTextChanged ;
106+ _passwordInput . Clicked += PasswordInputClicked ;
107+ _passwordInput . SetSound ( TextBox . Sounds . AddText , "octave-tap-resonant.wav" ) ;
108+ _passwordInput . SetSound ( TextBox . Sounds . RemoveText , "octave-tap-professional.wav" ) ;
109+ _passwordInput . SetSound ( TextBox . Sounds . Submit , "octave-tap-warm.wav" ) ;
58110
59111 //Login Save Pass Checkbox
60- _chkSavePass = new LabeledCheckBox ( this , "SavePassCheckbox" )
112+ _savePasswordCheckbox = new LabeledCheckBox ( this , nameof ( _savePasswordCheckbox ) )
61113 {
114+ X = 13 ,
115+ Y = 124 ,
116+ Width = 160 ,
117+ Height = 24 ,
118+ Font = _defaultFont ,
62119 Text = Strings . LoginWindow . SavePassword ,
63120 } ;
64121
65122 //Forgot Password Button
66123 _btnForgotPassword = new Button ( this , "ForgotPasswordButton" )
67124 {
68- IsHidden = true , Text = Strings . LoginWindow . ForgotPassword ,
125+ IsHidden = true ,
126+ Text = Strings . LoginWindow . ForgotPassword ,
69127 } ;
70128 _btnForgotPassword . Clicked += _btnForgotPassword_Clicked ;
71129
@@ -89,29 +147,29 @@ public LoginWindow(Canvas parent, MainMenu mainMenu) : base(parent, "LoginWindow
89147
90148 #region Input Handling
91149
92- private void _txtUsername_Clicked ( Base sender , MouseButtonState arguments )
150+ private void UsernameInputClicked ( Base sender , MouseButtonState arguments )
93151 {
94152 Globals . InputManager . OpenKeyboard (
95153 KeyboardType . Normal ,
96- text => _txtUsername . Text = text ?? string . Empty ,
154+ text => _usernameInput . Text = text ?? string . Empty ,
97155 Strings . LoginWindow . Username ,
98- _txtUsername . Text ,
99- inputBounds : _txtUsername . BoundsGlobal
156+ _usernameInput . Text ,
157+ inputBounds : _usernameInput . BoundsGlobal
100158 ) ;
101159 }
102160
103- private void _txtPassword_TextChanged ( Base sender , EventArgs arguments )
161+ private void PasswordInputTextChanged ( Base sender , EventArgs arguments )
104162 {
105163 _useSavedPass = false ;
106164 }
107165
108- private void _txtPassword_Clicked ( Base sender , MouseButtonState arguments )
166+ private void PasswordInputClicked ( Base sender , MouseButtonState arguments )
109167 {
110168 Globals . InputManager . OpenKeyboard (
111169 KeyboardType . Password ,
112- text => _txtPassword . Text = text ?? string . Empty ,
170+ text => _passwordInput . Text = text ?? string . Empty ,
113171 Strings . LoginWindow . Password ,
114- _txtPassword . Text
172+ _passwordInput . Text
115173 ) ;
116174 }
117175
@@ -154,13 +212,13 @@ public override void Show()
154212 }
155213
156214 // Set focus to the appropriate elements.
157- if ( ! string . IsNullOrWhiteSpace ( _txtUsername . Text ) )
215+ if ( ! string . IsNullOrWhiteSpace ( _usernameInput . Text ) )
158216 {
159- _txtPassword . Focus ( ) ;
217+ _passwordInput . Focus ( ) ;
160218 }
161219 else
162220 {
163- _txtUsername . Focus ( ) ;
221+ _usernameInput . Focus ( ) ;
164222 }
165223 }
166224
@@ -177,13 +235,13 @@ private void TryLogin()
177235 return ;
178236 }
179237
180- if ( ! FieldChecking . IsValidUsername ( _txtUsername . Text , Strings . Regex . Username ) )
238+ if ( ! FieldChecking . IsValidUsername ( _usernameInput . Text , Strings . Regex . Username ) )
181239 {
182240 Interface . ShowError ( Strings . Errors . UsernameInvalid ) ;
183241 return ;
184242 }
185243
186- if ( ! FieldChecking . IsValidPassword ( _txtPassword . Text , Strings . Regex . Password ) )
244+ if ( ! FieldChecking . IsValidPassword ( _passwordInput . Text , Strings . Regex . Password ) )
187245 {
188246 if ( ! _useSavedPass )
189247 {
@@ -195,17 +253,19 @@ private void TryLogin()
195253 var password = _savedPass ;
196254 if ( ! _useSavedPass )
197255 {
198- password = PasswordUtils . ComputePasswordHash ( _txtPassword . Text . Trim ( ) ) ;
256+ password = PasswordUtils . ComputePasswordHash ( _passwordInput . Text . Trim ( ) ) ;
199257 }
200258
201259 Globals . WaitingOnServer = true ;
202260 _btnLogin . Disable ( ) ;
203261
204- PacketSender . SendLogin ( _txtUsername . Text , password ) ;
262+ PacketSender . SendLogin ( _usernameInput . Text , password ) ;
205263 SaveCredentials ( ) ;
206264 ChatboxMsg . ClearMessages ( ) ;
207265 }
208266
267+ private const string DefaultPasswordInputMask = "****************" ;
268+
209269 private void LoadCredentials ( )
210270 {
211271 var name = Globals . Database . LoadPreference ( "Username" ) ;
@@ -214,27 +274,28 @@ private void LoadCredentials()
214274 return ;
215275 }
216276
217- _txtUsername . Text = name ;
277+ _usernameInput . Text = name ;
218278 var pass = Globals . Database . LoadPreference ( "Password" ) ;
219279 if ( string . IsNullOrEmpty ( pass ) )
220280 {
221281 return ;
222282 }
223283
224- _txtPassword . Text = "****************" ;
284+ _passwordInput . Text = DefaultPasswordInputMask ;
285+ _passwordInput . CursorPos = DefaultPasswordInputMask . Length ;
225286 _savedPass = pass ;
226287 _useSavedPass = true ;
227- _chkSavePass . IsChecked = true ;
288+ _savePasswordCheckbox . IsChecked = true ;
228289 }
229290
230291 private void SaveCredentials ( )
231292 {
232- string username = string . Empty , password = string . Empty ;
293+ string ? username = default , password = default ;
233294
234- if ( _chkSavePass . IsChecked )
295+ if ( _savePasswordCheckbox . IsChecked )
235296 {
236- username = _txtUsername . Text . Trim ( ) ;
237- password = _useSavedPass ? _savedPass : PasswordUtils . ComputePasswordHash ( _txtPassword . Text . Trim ( ) ) ;
297+ username = _usernameInput . Text ? . Trim ( ) ;
298+ password = _useSavedPass ? _savedPass : PasswordUtils . ComputePasswordHash ( _passwordInput . Text ? . Trim ( ) ) ;
238299 }
239300
240301 Globals . Database . SavePreference ( "Username" , username ) ;
0 commit comments