dev #17

Merged
JacobTech merged 29 commits from dev into main 2024-04-11 15:50:14 -04:00
9 changed files with 289 additions and 32 deletions
Showing only changes of commit 049cbe6f5b - Show all commits

View File

@ -9,6 +9,8 @@ using Luski.GUI.MainScreen.Interfaces;
using Luski.GUI.MainScreen.UI; using Luski.GUI.MainScreen.UI;
using Luski.GUI.StartPage.UI; using Luski.GUI.StartPage.UI;
using Luski.net; using Luski.net;
using Luski.net.Enums;
using Luski.net.Interfaces;
using Luski.net.JsonTypes; using Luski.net.JsonTypes;
using OpenTK.Graphics.OpenGL4; using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics; using OpenTK.Mathematics;
@ -28,12 +30,16 @@ public class MainScreen : Window
Size = new OpenTK.Mathematics.Vector2i(481, 838), Size = new OpenTK.Mathematics.Vector2i(481, 838),
}; };
FlowLayout? channelpicker; FlowLayout? channelpicker;
private RoundedButton? FriendManagerBtn;
private Chat? chat;
public MainScreen() : base(Settings) public MainScreen() : base(Settings)
{ {
Login login; Login login;
Controls.Add(login = new Login()); Controls.Add(login = new Login());
login.ChangeToApp += LoginOnChangeToApp; login.ChangeToApp += LoginOnChangeToApp;
Thread t = new(_ => Encryption.GenerateKeys());
t.Start();
} }
public void AddGroup(SocketGroupChannel group) public void AddGroup(SocketGroupChannel group)
@ -61,7 +67,13 @@ public class MainScreen : Window
private Task ChannelOnClickCon(IChannelPick arg) private Task ChannelOnClickCon(IChannelPick arg)
{ {
//show their channel chat!.UpdateTitle(arg);
chat.Clear();
IReadOnlyList<SocketMessage> messages = arg.Channel.GetMessages(200).Result;
foreach (SocketMessage message in messages.Reverse())
{
chat.AddMessage(message);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -72,16 +84,28 @@ public class MainScreen : Window
Size = new(2048, 1334); Size = new(2048, 1334);
WindowBorder = WindowBorder.Resizable; WindowBorder = WindowBorder.Resizable;
BackgroundColor = new Color4(34, 34, 34, 255); BackgroundColor = new Color4(34, 34, 34, 255);
Controls.Add(new Rectangle(new Texture(Globals.Luski.CurrentUser.GetAvatar().Result)) { Size = new(70, 70), Location = new(146, 78 + 1170)}); Controls.Add(new Rectangle(new Texture(Globals.Luski.CurrentUser.GetAvatar().Result)) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new(70, 70), Location = new(94, 1248)});
Controls.Add(new Label(){Location = new(132 + 92, 39 + 62+1170), Text = Globals.Luski.CurrentUser.Username}); Controls.Add(new Label(){ Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new(172, 1271), Text = Globals.Luski.CurrentUser.Username});
FlowLayout ser;
Controls.Add(ser = new FlowLayout()
{
BackgroundColor = new(26, 26, 26, 255),
Size = new(80,1334),
Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom,
});
ser.Controls.Add(new Rectangle(Globals.LuskiTexture)
{
Size = new(80,80)
});
Controls.Add(channelpicker = new FlowLayout() Controls.Add(channelpicker = new FlowLayout()
{ {
BackgroundColor = new(34,34,34,255), BackgroundColor = new(34,34,34,255),
Size = new(448, 1240), Size = new(448, 1232),
Location = new(132, 0), Location = new(80, 0),
Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom
}); });
channelpicker.Controls.Add(FriendManagerBtn = new RoundedButton() {Text = "Friends", Size = new(50, 80), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan});
FriendManagerBtn.Clicked += FriendManagerBtnOnClicked;
foreach (SocketGroupChannel ch in Globals.Luski.CurrentUser.Channels.Where(s => s is SocketGroupChannel).Cast<SocketGroupChannel>()) foreach (SocketGroupChannel ch in Globals.Luski.CurrentUser.Channels.Where(s => s is SocketGroupChannel).Cast<SocketGroupChannel>())
{ {
AddGroup(ch); AddGroup(ch);
@ -90,7 +114,33 @@ public class MainScreen : Window
{ {
if (item.Channel is not null) AddFriend(item); if (item.Channel is not null) AddFriend(item);
} }
Controls.Add(chat = new() {Location = new(528,0)});
SocketTextChannel chan = Globals.Luski.GetChannel<SocketTextChannel>(Globals.Luski.CurrentUser.SelectedChannel).Result;
chat.UpdateTitle(chans.First(s => s.Channel.Id == chan.Id));
IReadOnlyList<SocketMessage> messages = chan.GetMessages(200).Result;
foreach (SocketMessage message in messages.Reverse())
{
chat.AddMessage(message);
}
Globals.Luski.UserStatusUpdate += LuskiOnUserStatusUpdate;
DrawFrame(); DrawFrame();
return Task.CompletedTask; return Task.CompletedTask;
} }
private Task LuskiOnUserStatusUpdate(IUser before, IUser After)
{
if (before is not SocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends) return Task.CompletedTask;
Label stat = fr.Where(s => s.User.Id == before.Id).First()!.Status;
Invoke(new Action(() =>
{
stat.Text = After.Status.ToString();
}));
return Task.CompletedTask;
}
private Task FriendManagerBtnOnClicked(IRenderObject arg)
{
//open the friend UI
return Task.CompletedTask;
}
} }

View File

@ -0,0 +1,126 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using Luski.GUI.MainScreen.Interfaces;
using Luski.net.Enums;
using Luski.net.JsonTypes;
using OpenTK.Graphics.ES20;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.GraphicsLibraryFramework;
namespace Luski.GUI.MainScreen.UI;
public class Chat : UserControl
{
private FlowLayout MessageFlow;
private UserControl titlecon, typecon;
private Label title, desc;
private Textbox tb;
private long id = -1;
public Chat()
{
Size = new(1520, 1334);
BackgroundColor = new(50, 50, 50, 255);
Anchor = ObjectAnchor.All;
Controls.Add(MessageFlow = new()
{
Size = new(1520, 1172),
Location = new(0, 80),
BackgroundColor = new(40,40,40,255),
Anchor = ObjectAnchor.All
});
Controls.Add(titlecon = new UserControl(){Size = new(1520, 80), BackgroundColor = BackgroundColor});
Controls.Add(typecon = new UserControl(){Location = new(0, 1252), Size = new(1520, 82), BackgroundColor = BackgroundColor});
titlecon.Controls.Add(title = new Label(){Location = new(27, 40)});
titlecon.Controls.Add(desc = new Label(){Color = new(161,161,161,255), Location = new(title.Location.X + title.Size.X + 5, title.Location.Y)});
Globals.Luski.MessageReceived += LuskiOnMessageReceived;
typecon.Controls.Add(tb = new Textbox()
{
InsideColor = new(28, 28, 28, 255),
BorderColor = Color4.DarkCyan,
Location = new(15, 15),
Size = new(1490, 52)
});
tb.KeyPress += TbOnKeyPress;
}
private Task TbOnKeyPress(KeyboardKeyEventArgs arg)
{
if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask;
Thread t = new(() => Thr());
t.Start();
return Task.CompletedTask;
}
private void Thr()
{
Globals.Luski.SendMessage(tb.Text, id);
tb.Text = string.Empty;
}
private Task LuskiOnMessageReceived(SocketMessage arg)
{
if (id != arg.ChannelID) return Task.CompletedTask;
AddMessage(arg);
return Task.CompletedTask;
}
public void Clear()
{
MessageFlow.Controls.Clear();
lastm = null;
lastUser = null;
}
public void UpdateTitle(IChannelPick channelPick)
{
//if (channelPick.Channel.Title is null) throw new Exception("You dont have a key for this channel");
if (id == channelPick.Channel.Id) return;
id = channelPick.Channel.Id;
title.Text = channelPick.Channel.Title;
if (channelPick.Channel.Type == ChannelType.DM)
title.Text = (channelPick.Channel as SocketDMChannel)!.User.Username;
if (channelPick.Channel.Description is not null)
{
desc.Visible = true;
desc.Text = channelPick.Channel.Description;
desc.Location = new(title.Location.X + title.Size.X + 5, title.Location.Y);
}
else
{
desc.Visible = false;
}
}
private SocketMessage? lastm = null;
private long? lastUser = null;
private ChatMessage? LastChatMessage = null;
public void AddMessage(SocketMessage Message)
{
bool hasbeentenmin = false;
if (lastm is not null)
hasbeentenmin =
new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(lastm.Id >> 22).ToLocalTime().AddMinutes(10) <
new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime();
lastm = Message;
if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin)
{
if (Window is null || !Window.InvokeRequired)
MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(Message));
else
Window!.Invoke(new Action(() => { MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(Message)); Window.DrawFrame(); }));
}
else
{
if (Window is null || !Window.InvokeRequired)
LastChatMessage!.AddMessage(Message);
else
Window!.Invoke(new Action(() => { LastChatMessage!.AddMessage(Message); Window!.DrawFrame(); }));
}
lastUser = Message.AuthorID;
//Task.Delay(100);
}
}

View File

@ -11,25 +11,21 @@ namespace Luski.GUI.MainScreen.UI;
public class ChatMessage : UserControl public class ChatMessage : UserControl
{ {
readonly int padding = 2; readonly int padding = 2;
private static Font TimeFont = Font.MakeFontFromSystem(13);
private SocketMessage Msg { get; } private SocketMessage Msg { get; }
private Label label1, label2; private Label label1, label2, lastm;
public ChatMessage(SocketMessage message) public ChatMessage(SocketMessage message)
{ {
Size = new(1467, 74);
BackgroundColor = new(40, 40, 40, 255);
Msg = message; Msg = message;
IUser user = message.GetAuthor().Result; IUser user = message.GetAuthor().Result;
Anchor = ObjectAnchor.Left | ObjectAnchor.Right; Anchor = ObjectAnchor.Left | ObjectAnchor.Right;
Controls.Add(label1 = new Label() {Location = new(83, 9), Text = user.Username}); Controls.Add(label1 = new Label() {Location = new(83, 9), Text = user.Username});
Controls.Add(label2 = new Label() {Location = new(83, 40), Text = message.Context});
if (Msg.Files != null && Msg.Files.Length > 0)
{
for (int i = 0; i < Msg.Files.Length; i++)
{
Controls.Add(new ContentEmbed(Msg.Files[i], Msg.ChannelID));
}
}
DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Msg.Id >> 22).ToLocalTime(); DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Msg.Id >> 22).ToLocalTime();
string timestr; string timestr;
@ -45,9 +41,33 @@ public class ChatMessage : UserControl
{ {
timestr = $"{time:M/dd/yyyy h:mm tt}"; timestr = $"{time:M/dd/yyyy h:mm tt}";
} }
Controls.Add(new Label() {Location = new(label1.Location.X + label1.Size.X + 4, 17), Text = timestr}); Controls.Add(new Label() {Location = new(label1.Location.X + label1.Size.X + 4, 9), Text = timestr});
Controls.Add(new Label() {Location = new(129, 17), Text = message.Context});
Controls.Add(new Rectangle(new Texture(user.GetAvatar().Result)) { Location = new(15, 3), Size = new(58, 58) }); Controls.Add(new Rectangle(new Texture(user.GetAvatar().Result)) { Location = new(15, 3), Size = new(58, 58) });
Controls.Add(label2 = new Label() {Location = new(83, 40), Text = message.Context});
lastm = label2;
if (Msg.Files != null && Msg.Files.Length > 0)
{
int row = 1;
int filesonrow = 0;
for (int i = 0; i < Msg.Files.Length; i++)
{
int lx = (padding * filesonrow) + lastm.Location.X + (333 * (filesonrow + 1));
if (lx > Size.X)
{
row++;
filesonrow = 0;
lx = (padding * filesonrow) + lastm.Location.X + (333 * (filesonrow + 1));
}
filesonrow++;
Controls.Add(new ContentEmbed(Msg.Files[i], Msg.ChannelID)
{
Location = new(lx - 333, lastm.Location.Y + 2 + lastm.Size.Y +(padding * row) + (66 * (row - 1)))
});
}
}
Size = new(Size.X, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + padding + 10);
} }
public void AddMessage(SocketMessage msg) public void AddMessage(SocketMessage msg)
@ -64,11 +84,26 @@ public class ChatMessage : UserControl
Controls.Add(newLabel); Controls.Add(newLabel);
if (msg.Files != null && msg.Files.Length > 0) if (msg.Files != null && msg.Files.Length > 0)
{ {
for (int i = 0; i < msg.Files.Length; i++) int row = 1;
int filesonrow = 0;
for (int i = 0; i < Msg.Files.Length; i++)
{ {
Controls.Add(new ContentEmbed(msg.Files[i], Msg.ChannelID)); int lx = (padding * filesonrow) + lastm.Location.X + (333 * (filesonrow + 1));
if (lx > Size.X)
{
row++;
filesonrow = 0;
lx = (padding * filesonrow) + lastm.Location.X + (333 * (filesonrow + 1));
}
filesonrow++;
Controls.Add(new ContentEmbed(Msg.Files[i], Msg.ChannelID)
{
Location = new(lx - 333, lastm.Location.Y + 2 + lastm.Size.Y +(padding * row) + (66 * (row - 1)))
});
} }
} }
Size = new(Size.X, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + padding + 10);
} }
readonly List<Label> Labels = new(); readonly List<Label> Labels = new();
private Task NewLabel_MouseLeave(IRenderObject sender) private Task NewLabel_MouseLeave(IRenderObject sender)
@ -83,7 +118,7 @@ public class ChatMessage : UserControl
Controls.Remove(l.First()); Controls.Remove(l.First());
Labels.Remove(l.First()); Labels.Remove(l.First());
} }
Window!.DrawFrame();
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -95,11 +130,13 @@ public class ChatMessage : UserControl
Label m = new() Label m = new()
{ {
Text = time.ToString("h:mm tt"), Text = time.ToString("h:mm tt"),
Location = new(15, label.Location.Y + 1), Location = new(15, label.Location.Y - (int)TimeFont.PixelHeight + (int)label.Font.PixelHeight),
Font = TimeFont
}; };
Controls.Add(m); Controls.Add(m);
Labels.Add(m); Labels.Add(m);
Window!.DrawFrame();
return Task.CompletedTask; return Task.CompletedTask;
} }
} }

View File

@ -1,5 +1,6 @@
using System.Reflection; using System.Reflection;
using GraphicsManager; using GraphicsManager;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects; using GraphicsManager.Objects;
using GraphicsManager.Objects.Core; using GraphicsManager.Objects.Core;
using File = Luski.net.JsonTypes.File; using File = Luski.net.JsonTypes.File;
@ -32,12 +33,40 @@ public class ContentEmbed : UserControl
{ {
fst = Math.Round((double)size / (double)1000000000, 2) + " GB"; fst = Math.Round((double)size / (double)1000000000, 2) + " GB";
} }
Size = new(333, 66);
BackgroundColor = new(40, 40, 40, 255);
Controls.Add(fileSizeLabel = new Label() {Text = fst, Location = new(64, 39)}); Controls.Add(fileSizeLabel = new Label() {Text = fst, Location = new(64, 39)});
Controls.Add(fileNameLabel = new Label() {Text = file.Name, Location = new(64, 6)}); Controls.Add(fileNameLabel = new Label() { Color = new(102/(float)255,227/(float)255,170/(float)255, 1), Text = file.Name, Location = new(64, 6)});
Controls.Add(new Rectangle(new Texture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Download.png"))) { Location = new(8, 6), Size = new(50, 50)}); fileNameLabel.Clicked += FileNameLabelOnClicked;
fileNameLabel.MouseEnter += FileNameLabelOnMouseEnter;
fileNameLabel.MouseLeave += FileNameLabelOnMouseLeave;
byte[] tempp = Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Download.png");
Controls.Add(new Rectangle(new Texture(tempp)) { Location = new(8, 6), Size = new(50, 50)});
int temp = fileNameLabel.Size.X + fileNameLabel.Location.X; int temp = fileNameLabel.Size.X + fileNameLabel.Location.X;
int temp2 = fileSizeLabel.Size.X + fileSizeLabel.Location.X; ; int temp2 = fileSizeLabel.Size.X + fileSizeLabel.Location.X; ;
if (temp >= temp2) Size = new(temp + 4, Size.Y); if (temp >= temp2) Size = new(temp + 4, Size.Y);
else Size = new(temp2 + 4, Size.Y); else Size = new(temp2 + 4, Size.Y);
} }
private Task FileNameLabelOnMouseLeave(IRenderObject arg)
{
Console.WriteLine("leave");
return Task.CompletedTask;
}
private Task FileNameLabelOnMouseEnter(IRenderObject arg)
{
Console.WriteLine("enter");
return Task.CompletedTask;
}
private Task FileNameLabelOnClicked(IRenderObject arg)
{
Console.WriteLine("Click");
string dir = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Downloads", "LuskiDownloads");
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
Thread t = new(() => file.DownloadBytes(Path.Join(dir, file.Name), channel));
t.Start();
return Task.CompletedTask;
}
} }

View File

@ -18,7 +18,7 @@ public class Friend : UserControl, IChannelPick
} }
} }
private Rectangle r; private Rectangle r;
private Label Username, Status; public Label Username, Status;
public Friend(SocketRemoteUser person) public Friend(SocketRemoteUser person)
{ {
User = person; User = person;

View File

@ -6,6 +6,8 @@ using GraphicsManager.Objects.Core;
using Luski.net; using Luski.net;
using Luski.net.Enums; using Luski.net.Enums;
using OpenTK.Mathematics; using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.GraphicsLibraryFramework;
namespace Luski.GUI.StartPage.UI; namespace Luski.GUI.StartPage.UI;
@ -17,17 +19,25 @@ public class Login : UserControl
public Login() public Login()
{ {
Size = new(481, 838); Size = new(481, 838);
Controls.Add(new Rectangle(new Texture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Luski.png"))) { 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(0.9529f, 0.46666f, 0.203921569f, 1f) }); Controls.Add(new Label() { Location = new(173,305), Text = "Luski", Color = new(243, 119, 53, 255) });
Controls.Add(new Label() { Location = new(34,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(34,521), Text = "Password" }); Controls.Add(new Label() { Location = new(41,521), Text = "Password" });
Controls.Add(Password = new Textbox() { 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(36,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;
button.Clicked += ButtonOnClicked; 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) private Task ButtonOnClicked(IRenderObject arg)
{ {
try try

View File

@ -1,3 +1,6 @@
using System.Reflection;
using GraphicsManager;
using GraphicsManager.Objects.Core;
using Luski.net; using Luski.net;
namespace Luski; namespace Luski;
@ -5,4 +8,6 @@ namespace Luski;
public class Globals public class Globals
{ {
public static Server Luski = null!; public static Server Luski = null!;
public static Texture LuskiTexture = new(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Luski.png"));
} }

View File

@ -8,8 +8,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.0.0-alpha999993" /> <PackageReference Include="GraphicsManager" Version="1.0.0-alpha99999999994" />
<PackageReference Include="Luski.net" Version="1.1.0-alpha" /> <PackageReference Include="Luski.net" Version="1.0.0-alpha5" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB