diff --git a/Luski/GUI/MainScreen.cs b/Luski/GUI/MainScreen.cs index 5fcb92b..9df4b06 100644 --- a/Luski/GUI/MainScreen.cs +++ b/Luski/GUI/MainScreen.cs @@ -31,16 +31,28 @@ public class MainScreen : Window private FlowLayout? channelpicker, friends, friend_request; private RoundedButton? FriendManagerBtn; public Chat? chat; + Login login; + CreateAccount ca; public MainScreen() : base(Settings) { - Login login; + Controls.Add(ca = new CreateAccount() {Visible = false}); + ca.ChangeToApp += LoginOnChangeToApp; Controls.Add(login = new Login()); login.ChangeToApp += LoginOnChangeToApp; + login.ChangeToCa += LoginOnChangeToCa; Thread t = new(_ => Encryption.GenerateKeys()); t.Start(); } + private Task LoginOnChangeToCa() + { + Title = "Create Account"; + ca.Visible = true; + login.Visible = false; + return Task.CompletedTask; + } + public void AddGroup(SocketGroupChannel group) { Group friend = new(group); diff --git a/Luski/GUI/StartPage/UI/CreateAccount.cs b/Luski/GUI/StartPage/UI/CreateAccount.cs new file mode 100644 index 0000000..97dde3a --- /dev/null +++ b/Luski/GUI/StartPage/UI/CreateAccount.cs @@ -0,0 +1,101 @@ +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using Luski.net; +using Luski.net.Enums; +using OpenTK.Mathematics; +using OpenTK.Windowing.Common; +using OpenTK.Windowing.GraphicsLibraryFramework; + +namespace Luski.GUI.StartPage.UI; + +public class CreateAccount : UserControl +{ + private RoundedButton button; + private Textbox Password, Email, Username; + private Rectangle rec; + private string pfp = null; + + public event Func ChangeToApp; + + public CreateAccount() + { + Size = new(481, 838); + Controls.Add(new Rectangle(Globals.LuskiTexture) { Location = new(103,8), Size = new(276, 289)}); + Controls.Add(new Label() { Scale = 1.4f, Location = new(173,305), Text = "Luski", Color = new(243, 119, 53, 255) }); + Controls.Add(new Label() { Location = new(41,395), Text = "Email"}); + Controls.Add(Email = new Textbox() { Location = new(41,431), Size = new(401,41), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); + Controls.Add(new Label() { Location = new(41,490), Text = "Password" }); + Controls.Add(Password = new Textbox() { PasswordChar = '●', Location = new(41,531), Size = new(401, 41), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(new Label() { Location = new(41,580), Text = "Display Name" }); + Controls.Add(Username = new Textbox() { Location = new(41,616), Size = new(300, 41), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(button = new() { Text = "Create Account", Location = new(41, 700), Size = new(401, 71), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(rec = new Rectangle(){ Location = new(350, 585), Size = new(100), BackgroundColor = Color4.Red}); + Password.KeyPress += PasswordOnKeyPress; + Email.KeyPress += EmailOnKeyPress; + button.Clicked += ButtonOnClicked; + Username.KeyPress += UsernameOnKeyPress; + rec.FilesDroped += RecOnFilesDroped; + } + + private Task UsernameOnKeyPress(KeyboardKeyEventArgs arg) + { + if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; + if (arg.Key == Keys.Tab && arg.Shift) { Password.Focus(); return Task.CompletedTask; } + if (arg.Key == Keys.Enter || arg.Key == Keys.KeyPadEnter) ButtonOnClicked(Username); + return Task.CompletedTask; + } + + private Task RecOnFilesDroped(string[] arg) + { + if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask; + Controls.Remove(rec); + pfp = arg[0]; + rec = new(new(File.ReadAllBytes(arg[0]))){ Location = new(350, 585), Size = new(100) }; + Controls.Add(rec); + Window!.DrawFrame(); + return Task.CompletedTask; + } + + private bool tab; + private Task EmailOnKeyPress(KeyboardKeyEventArgs arg) + { + if (arg.Key != Keys.Tab) return Task.CompletedTask; + if (arg.Key == Keys.Tab){ Password.Focus(); tab = true;} + return Task.CompletedTask; + } + + private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg) + { + if (tab) + { + tab = false; + return Task.CompletedTask; + }; + if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; + if (arg.Key == Keys.Tab && arg.Shift) { Email.Focus(); return Task.CompletedTask; } + if (arg.Key == Keys.Tab ){ Username.Focus(); return Task.CompletedTask; } + return Task.CompletedTask; + } + + private Task ButtonOnClicked(IRenderObject arg) + { + try + { + string[] arr = new string[] + { + Email.Text, + Password.Text, + Username.Text, + pfp + }; + if (arr.Any(s => string.IsNullOrEmpty(s))) return Task.CompletedTask; + Globals.Luski = Server.CreateAccount(Email.Text, Password.Text, Username.Text, pfp, Globals.Branch); + ChangeToApp.Invoke(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/Luski/GUI/StartPage/UI/Login.cs b/Luski/GUI/StartPage/UI/Login.cs index 79c1f84..9593b29 100644 --- a/Luski/GUI/StartPage/UI/Login.cs +++ b/Luski/GUI/StartPage/UI/Login.cs @@ -1,10 +1,6 @@ -using System.Reflection; -using GraphicsManager; using GraphicsManager.Interfaces; using GraphicsManager.Objects; -using GraphicsManager.Objects.Core; using Luski.net; -using Luski.net.Enums; using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.GraphicsLibraryFramework; @@ -15,21 +11,37 @@ public class Login : UserControl { private RoundedButton button; private Textbox Password, Email; + private Label ca; public event Func ChangeToApp; + public event Func ChangeToCa; public Login() { Size = new(481, 838); Controls.Add(new Rectangle(Globals.LuskiTexture) { Location = new(103,8), Size = new(276, 289)}); - Controls.Add(new Label() { Location = new(173,305), Text = "Luski", Color = new(243, 119, 53, 255) }); + Controls.Add(new Label() { Scale = 1.4f, Location = new(173,305), Text = "Luski", Color = new(243, 119, 53, 255) }); Controls.Add(new Label() { Location = new(41,395), Text = "Email"}); Controls.Add(Email = new Textbox() { Location = new(41,431), Size = new(401,41), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); Controls.Add(new Label() { Location = new(41,521), Text = "Password" }); Controls.Add(Password = new Textbox() { PasswordChar = '●', Location = new(41,562), Size = new(401, 41), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); - Controls.Add(new Label() { Location = new(41,664), Text = "Create Account" }); + Controls.Add(ca = new Label() { Location = new(41,664), Text = "Create Account" }); Controls.Add(button = new() { Text = "Login", Location = new(41, 700), Size = new(401, 71), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); Password.KeyPress += PasswordOnKeyPress; Email.KeyPress += EmailOnKeyPress; button.Clicked += ButtonOnClicked; + ca.Clicked += CaOnClicked; + this.WindowLoaded += OnWindowLoaded; + } + + private Task OnWindowLoaded(IRenderObject arg) + { + Email.Focus(); + return Task.CompletedTask; + } + + private Task CaOnClicked(IRenderObject arg) + { + ChangeToCa.Invoke(); + return Task.CompletedTask; } private Task EmailOnKeyPress(KeyboardKeyEventArgs arg) @@ -41,8 +53,9 @@ public class Login : UserControl private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg) { - if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask; - ButtonOnClicked(Password); + if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; + if (arg.Key == Keys.Tab && arg.Shift) Email.Focus(); + if (arg.Key != Keys.Tab ) ButtonOnClicked(Password); return Task.CompletedTask; } @@ -50,7 +63,7 @@ public class Login : UserControl { try { - Globals.Luski = Server.Login(Email.Text, Password.Text, Branch.Dev).Result; + Globals.Luski = Server.Login(Email.Text, Password.Text, Globals.Branch).Result; ChangeToApp.Invoke(); } catch (Exception e) diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 7d0c55e..18c4dcc 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -2,6 +2,7 @@ using System.Reflection; using GraphicsManager; using GraphicsManager.Objects.Core; using Luski.net; +using Luski.net.Enums; namespace Luski; @@ -10,4 +11,33 @@ public class Globals public static Server Luski = null!; public static Texture LuskiTexture = new(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Luski.png")); + + public static string JT + { + get + { + string tmp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "JacobTech"); + if (OperatingSystem.IsLinux()) + { + tmp = Path.Combine(Environment.GetEnvironmentVariable("HOME")!, ".config/"); + tmp += "JacobTech"; + } + return tmp; + } + } + + public static Branch Branch + { + get + { + if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "branch.txt"))) File.WriteAllText(Path.Combine(Environment.CurrentDirectory, "branch.txt"), ((int)Branch.Beta).ToString()); + return File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "branch.txt")) switch + { + "0" => Branch.Dev, + "1" => Branch.Beta, + "2" => Branch.Master, + _ => Branch.Beta + }; + } + } } \ No newline at end of file diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index 77a2e2e..02ca044 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -8,8 +8,8 @@ - - + +