55 lines
2.1 KiB
C#

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;
namespace Luski.GUI.StartPage.UI;
public class Login : UserControl
{
private RoundedButton button;
private Textbox Password, Email;
public event Func<Task> ChangeToApp;
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() { 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(button = new() { Text = "Login", Location = new(41, 700), Size = new(401, 71), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan });
Password.KeyPress += PasswordOnKeyPress;
button.Clicked += ButtonOnClicked;
}
private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg)
{
if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask;
ButtonOnClicked(Password);
return Task.CompletedTask;
}
private Task ButtonOnClicked(IRenderObject arg)
{
try
{
Globals.Luski = Server.Login(Email.Text, Password.Text, Branch.Dev).Result;
ChangeToApp.Invoke();
}
catch (Exception e)
{
Console.WriteLine(e);
}
return Task.CompletedTask;
}
}