dev #17

Merged
JacobTech merged 29 commits from dev into main 2024-04-11 15:50:14 -04:00
7 changed files with 199 additions and 28 deletions
Showing only changes of commit b2f0fdc64f - Show all commits

View File

@ -1,6 +1,3 @@
using System.ComponentModel;
using System.Reflection;
using GraphicsManager;
using GraphicsManager.Enums; using GraphicsManager.Enums;
using GraphicsManager.Interfaces; using GraphicsManager.Interfaces;
using GraphicsManager.Objects; using GraphicsManager.Objects;
@ -31,9 +28,9 @@ public class MainScreen : Window
}; };
private TabControl tc; private TabControl tc;
private FlowLayout? channelpicker, friends; private FlowLayout? channelpicker, friends, friend_request;
private RoundedButton? FriendManagerBtn; private RoundedButton? FriendManagerBtn;
private Chat? chat; public Chat? chat;
public MainScreen() : base(Settings) public MainScreen() : base(Settings)
{ {
@ -54,6 +51,21 @@ public class MainScreen : Window
private readonly List<Friend> fr = new(); private readonly List<Friend> fr = new();
private List<IChannelPick> chans = new(); private List<IChannelPick> chans = new();
private Dictionary<long, int> FR_Index = new();
public void AddFriendRequest(SocketRemoteUser user)
{
FriendRequest frui = new(this, user);
FR_Index.Add(user.Id, friend_request!.Controls.Length);
friend_request.Controls.Add(frui);
}
public void RemoveFriendRequest(SocketRemoteUser user)
{
if (!FR_Index.ContainsKey(user.Id)) return;
friend_request!.Controls.Remove(friend_request!.Controls[FR_Index[user.Id]]);
}
public void AddFriend(SocketRemoteUser user) public void AddFriend(SocketRemoteUser user)
{ {
Friend friend2 = new(user); Friend friend2 = new(user);
@ -70,6 +82,8 @@ public class MainScreen : Window
} }
private Task ChannelOnClickCon(IChannelPick arg) private Task ChannelOnClickCon(IChannelPick arg)
{
try
{ {
if (!chat.Visible) if (!chat.Visible)
{ {
@ -83,12 +97,19 @@ public class MainScreen : Window
{ {
chat.AddMessage(message); chat.AddMessage(message);
} }
DrawFrame();
}
catch (Exception e)
{
Console.WriteLine(e);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
private Task LoginOnChangeToApp() private Task LoginOnChangeToApp()
{ {
Controls.Clear(); Controls.Clear();
BlockDraw = true;
Title = "Luski"; Title = "Luski";
Size = new(2048, 1334); Size = new(2048, 1334);
WindowBorder = WindowBorder.Resizable; WindowBorder = WindowBorder.Resizable;
@ -112,16 +133,15 @@ public class MainScreen : Window
Anchor = ObjectAnchor.All, Anchor = ObjectAnchor.All,
Visible = false Visible = false
}); });
UserControl f; tc.AddPage("Frineds", friends = new FlowLayout()
tc.AddPage("Frineds", f= new UserControl());
tc.AddPage("Friend Request", new UserControl());
tc.AddPage("Add Friend", new UserControl());
f.Controls.Add(friends = new FlowLayout()
{ {
Size = f.Size, BackgroundColor = new(45,45,45,255)
BackgroundColor = new(45,45,45,255),
Anchor = ObjectAnchor.All
}); });
tc.AddPage("Friend Request", friend_request = new FlowLayout()
{
BackgroundColor = new(45,45,45,255)
});
tc.AddPage("Add Friend", new AddFriendPage(this));
ser.Controls.Add(new Rectangle(Globals.LuskiTexture) ser.Controls.Add(new Rectangle(Globals.LuskiTexture)
{ {
Size = new(80,80), Size = new(80,80),
@ -152,11 +172,45 @@ public class MainScreen : Window
{ {
chat.AddMessage(message); chat.AddMessage(message);
} }
Globals.Luski.OnError += LuskiOnOnError;
Globals.Luski.UserStatusUpdate += LuskiOnUserStatusUpdate; Globals.Luski.UserStatusUpdate += LuskiOnUserStatusUpdate;
Globals.Luski.ReceivedFriendRequest += LuskiOnReceivedFriendRequest;
Globals.Luski.FriendRequestResult += LuskiOnFriendRequestResult;
foreach (SocketRemoteUser cufr in Globals.Luski.CurrentUser.FriendRequests)
{
AddFriendRequest(cufr);
}
BlockDraw = false;
DrawFrame(); DrawFrame();
return Task.CompletedTask; return Task.CompletedTask;
} }
private Task LuskiOnOnError(Exception arg)
{
Console.WriteLine(arg);
return Task.CompletedTask;
}
private Task LuskiOnFriendRequestResult(SocketRemoteUser arg1, bool arg2)
{
Invoke(new Action(() =>
{
RemoveFriendRequest(arg1);
if (arg2) AddFriend(arg1);
}));
return Task.CompletedTask;
}
private Task LuskiOnReceivedFriendRequest(SocketRemoteUser arg)
{
Invoke(new Action(() =>
{
AddFriendRequest(arg);
}));
return Task.CompletedTask;
}
private Task LuskiOnUserStatusUpdate(IUser before, IUser After) private Task LuskiOnUserStatusUpdate(IUser before, IUser After)
{ {
if (before is not SocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends) return Task.CompletedTask; if (before is not SocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends) return Task.CompletedTask;

View File

@ -0,0 +1,45 @@
using GraphicsManager.Enums;
using GraphicsManager.Objects;
using Luski.net.JsonTypes;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.GraphicsLibraryFramework;
namespace Luski.GUI.MainScreen.UI;
public class AddFriendPage : FlowLayout
{
private MainScreen Screen;
private Textbox Input;
public AddFriendPage(MainScreen Parent)
{
this.Screen = Parent;
Size = new(400, 96);
BackgroundColor = new(45,45,45,255);
Controls.Add(Input = new Textbox() { Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Location = new(15,15), Size = new(370,40), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan });
Input.KeyPress += InputOnKeyPress;
}
private Task InputOnKeyPress(KeyboardKeyEventArgs arg)
{
if (Input.BorderColor == Color4.Red) Input.BorderColor = Color4.DarkCyan;
if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask;
if (!long.TryParse(Input.Text, out long code))
{
Input.BorderColor = Color4.Red;
return Task.CompletedTask;
}
SocketRemoteUser? result = Globals.Luski.SendFriendRequest(code).Result;
if (result is null) Input.BorderColor = Color4.Red;
else
{
if (result.Channel is null)
Screen.AddFriendRequest(result);
else
Screen.AddFriend(result);
}
return Task.CompletedTask;
}
}

View File

@ -55,11 +55,12 @@ public class Chat : UserControl
private void Thr() private void Thr()
{ {
Globals.Luski.SendMessage(tb.Text, id); Globals.Luski.SendMessage(tb.Text, id);
tb.Text = string.Empty; Window!.Invoke(new Action(() => { tb.Text = string.Empty; }));
} }
private Task LuskiOnMessageReceived(SocketMessage arg) private Task LuskiOnMessageReceived(SocketMessage arg)
{ {
Console.WriteLine(arg);
if (id != arg.ChannelID) return Task.CompletedTask; if (id != arg.ChannelID) return Task.CompletedTask;
AddMessage(arg); AddMessage(arg);
return Task.CompletedTask; return Task.CompletedTask;

View File

@ -0,0 +1,56 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.net.Enums;
using Luski.net.JsonTypes;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI;
public class FriendRequest : UserControl
{
private MainScreen Screen;
public SocketRemoteUser User;
public Rectangle Accept, Reject;
public FriendRequest(MainScreen Parent, SocketRemoteUser User)
{
this.User = User;
this.Screen = Parent;
Size = new(400, 96);
BackgroundColor = new(34, 34, 34, 255);
Controls.Add(new Rectangle(new Texture(User.GetAvatar().Result)) { Location = new(15,17), Size = new(58,58)});
Controls.Add(new Label() { Text = User.Username, Location = new(77,20)});
Controls.Add(new Label() { Text = User.FriendStatus.ToString(), Location = new(77,48)});
if (User.FriendStatus == FriendStatus.PendingIn)
{
Controls.Add(Accept = new Rectangle()
{
Anchor = ObjectAnchor.Top | ObjectAnchor.Right, BackgroundColor = Color4.Green, Location = new(254, 17),
Size = new(58, 58)
});
Controls.Add(Reject = new Rectangle()
{
Anchor = ObjectAnchor.Top | ObjectAnchor.Right, BackgroundColor = Color4.Red, Location = new(327, 17),
Size = new(58, 58)
});
Accept.Clicked += AcceptOnClicked;
Reject.Clicked += RejectOnClicked;
}
}
private Task RejectOnClicked(IRenderObject arg)
{
_ = Globals.Luski.SendFriendResult(User.Id, false).Result;
Screen.RemoveFriendRequest(User);
return Task.CompletedTask;
}
private Task AcceptOnClicked(IRenderObject arg)
{
Screen.AddFriend(Globals.Luski.SendFriendResult(User.Id, true).Result);
Screen.RemoveFriendRequest(User);
return Task.CompletedTask;
}
}

View File

@ -22,15 +22,23 @@ public class Login : UserControl
Controls.Add(new Rectangle(Globals.LuskiTexture) { Location = new(103,8), Size = new(276, 289)}); 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(173,305), Text = "Luski", Color = new(243, 119, 53, 255) });
Controls.Add(new Label() { Location = new(41,395), Text = "Email"}); 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(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(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(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(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 }); 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; Password.KeyPress += PasswordOnKeyPress;
Email.KeyPress += EmailOnKeyPress;
button.Clicked += ButtonOnClicked; button.Clicked += ButtonOnClicked;
} }
private Task EmailOnKeyPress(KeyboardKeyEventArgs arg)
{
if (arg.Key != Keys.Tab) return Task.CompletedTask;
Password.Focus();
return Task.CompletedTask;
}
private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg) private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg)
{ {
if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask; if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask;

View File

@ -8,8 +8,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.0.0-alpha99999999999999996" /> <PackageReference Include="GraphicsManager" Version="1.0.0-alpha9999999999999999996" />
<PackageReference Include="Luski.net" Version="1.0.0-alpha5" /> <PackageReference Include="Luski.net" Version="1.0.0-alpha91" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,5 +1,12 @@
using Luski.GUI.MainScreen; using Luski.GUI.MainScreen;
MainScreen t = new MainScreen(); try
t.StartRender(); {
t.Dispose(); MainScreen t = new MainScreen();
t.StartRender();
t.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}