diff --git a/Luski/GUI/MainScreen.cs b/Luski/GUI/MainScreen.cs index 0a10586..2282b5d 100644 --- a/Luski/GUI/MainScreen.cs +++ b/Luski/GUI/MainScreen.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using System.Net; using System.Reflection; using System.Runtime.InteropServices; using GraphicsManager; @@ -29,13 +28,14 @@ public class MainScreen : Window Title = "Luski Login", WindowBorder = WindowBorder.Fixed, APIVersion = new Version(3, 2), + API = ContextAPI.OpenGL, StartFocused = true, - Size = new Vector2i((int)(240.5 * Globals.Settings.Scale), (int)(419 * Globals.Settings.Scale)), + Size = new Vector2i((int)(312 * Globals.Settings.Scale), (int)(545 * Globals.Settings.Scale)), Icon = Globals.Icon, SharedContext = null }; - private TabControl tc; + public TabControl? tc; private FlowLayout? channelpicker, friends, friend_request; private RoundedButton? FriendManagerBtn; public Chat? chat; @@ -59,7 +59,6 @@ public class MainScreen : Window // The rest of the function is up to you to implement, however a debug output // is always useful. -return; switch (severity) { case DebugSeverity.DebugSeverityHigh: @@ -87,11 +86,10 @@ return; GL.Enable(EnableCap.DebugOutput); Globals.DefaultFont = Font.MakeEmbeddedFont("Luski.Resources.Fonts.OpenSans-Regular.ttf", Assembly.GetExecutingAssembly()); - Globals.DefaultFont.PixelHeight = (uint)(12 * Globals.Settings.Scale); - //Font.MakeFontFromSystem((uint)(12 * Globals.Settings.Scale)); + //Globals.DefaultFont = Font.MakeFontFromFile(@"C:\Users\techn\Downloads\tahoma.ttf"); + Globals.DefaultFont.PixelHeight = (uint)(20 * Globals.Settings.Scale); Globals.LuskiTexture = TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Luski.png")); - CenterWindow(0); Controls.Add(ca = new CreateAccount()); ca.Visible = false; @@ -112,10 +110,6 @@ return; private Task OnWindowLoadedd(Window arg) { - Console.WriteLine(login.r.Location.Y); - Console.WriteLine(login.r.ScissorLocation.Y); - Console.WriteLine(login.r.Location.X); - Console.WriteLine(login.r.ScissorLocation.X); return Task.CompletedTask; } private Task OnWindowLoaded(Window arg) @@ -170,7 +164,7 @@ return; { Friend friend2 = new(user); friend2.ClickCon += ChannelOnClickCon; - friends.Controls.Add(friend2); + friends!.Controls.Add(friend2); if (user.Channel is not null) { Friend friend = new(user); @@ -182,18 +176,20 @@ return; } private CancellationTokenSource? channelCancellationToken = null; - private async Task ChannelOnClickCon(IChannelPick arg) + private Task ChannelOnClickCon(IChannelPick arg) { try { BlockDraw = true; - Thread t = new(a => cc(a)); + Thread t = new(a => cc(a!)); t.Start(arg); } catch (Exception e) { Console.WriteLine(e); } + + return Task.CompletedTask; } private void cc(object argg) @@ -205,10 +201,8 @@ return; { chat!.UpdateTitle(arg); })); - Console.WriteLine("Checking token"); if (channelCancellationToken is not null) { - Console.WriteLine("Cancling token"); channelCancellationToken.Cancel(false); } channelCancellationToken = new CancellationTokenSource(); @@ -258,20 +252,29 @@ return; //Clip // Console.WriteLine(Public); Globals.Luski.SetMultiThreadPercent(Globals.Settings.MultiThreadPercent); - Size = new((int)(1024 * Globals.Settings.Scale), (int)(667 * Globals.Settings.Scale)); + Size = new((int)(1332 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale)); DateTime start = DateTime.Now; CenterWindow(0); DateTime start1 = DateTime.Now; WindowBorder = WindowBorder.Resizable; BackgroundColor = new Color4(34, 34, 34, 255); - Controls.Add(new Rectangle(TextureManager.AddTexture(Globals.Luski.CurrentUser.GetAvatar(CancellationToken.None).Result, true)) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(35 * Globals.Settings.Scale)), Location = new((int)(47 * Globals.Settings.Scale), (int)(624 * Globals.Settings.Scale))}); - Controls.Add(new Label(){ Font = Globals.DefaultFont, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new((int)(86 * Globals.Settings.Scale), (int)(635.5 * Globals.Settings.Scale)), Text = Globals.Luski.CurrentUser.Username}); + Rectangle u=new Rectangle(TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), + "Luski.Resources.Textures.Status.png"))) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(46 * Globals.Settings.Scale)), Location = new((int)(62 * Globals.Settings.Scale), (int)(812 * Globals.Settings.Scale))}; + Texture uut = TextureManager.AddTexture(Globals.Luski.CurrentUser.GetAvatar(CancellationToken.None).Result); + uut.Unit = TextureUnit.Texture1; + u.Shader = Rectangle.DefaultAlphaTextureShader[Context]; + u.Textures.Add(uut); + Controls.Add(u); + Label ul = new Label(){ Font = Globals.DefaultFont, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new(0, (int)(826 * Globals.Settings.Scale)), Text = Globals.Luski.CurrentUser.Username}; FlowLayout ser; - Controls.Add(chat = new() {Location = new((int)(270 * Globals.Settings.Scale),0)}); + ul.Location = new((int)(112 * Globals.Settings.Scale), + (u.Location.Y + (u.Size.Y/2) - (ul.PostiveTrueHeight/2) - ul.Size.Y + ul.TrueHeight)); + Controls.Add(ul); + Controls.Add(chat = new() {Location = new((int)(352 * Globals.Settings.Scale),0)}); Controls.Add(ser = new FlowLayout() { BackgroundColor = new(26, 26, 26, 255), - Size = new((int)(40 * Globals.Settings.Scale),(int)(667 * Globals.Settings.Scale)), + Size = new((int)(52 * Globals.Settings.Scale),(int)(868 * Globals.Settings.Scale)), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom, }); @@ -297,16 +300,16 @@ return; tc.AddPage("Add Friend", new AddFriendPage(this)); ser.Controls.Add(new Rectangle(Globals.LuskiTexture) { - Size = new((int)(40 * Globals.Settings.Scale)), + Size = new((int)(52 * Globals.Settings.Scale)), }); Controls.Add(channelpicker = new FlowLayout() { BackgroundColor = new(34,34,34,255), - Size = new((int)(230 * Globals.Settings.Scale), (int)(616 * Globals.Settings.Scale)), - Location = new((int)(40 * Globals.Settings.Scale), 0), + Size = new((int)(300 * Globals.Settings.Scale), (int)(800 * Globals.Settings.Scale)), + Location = new((int)(52 * Globals.Settings.Scale), 0), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom }); - channelpicker.Controls.Add(FriendManagerBtn = new RoundedButton() { Font = Globals.DefaultFont, Text = "Friends", Size = new((int)(40* Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan}); + channelpicker.Controls.Add(FriendManagerBtn = new RoundedButton() { Font = Globals.DefaultFont, Text = "Friends", Size = new((int)(52* Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan}); FriendManagerBtn.Clicked += FriendManagerBtnOnClicked; Console.WriteLine("Templates loaded in " + (DateTime.Now - start).TotalSeconds + " seconds"); foreach (SocketGroupChannel ch in Globals.Luski.CurrentUser.Channels.Where(s => s is SocketGroupChannel).Cast()) @@ -363,7 +366,7 @@ return; return Task.CompletedTask; } - public event Func MainShow; + public event Func? MainShow; private Task LuskiOnOnError(Exception arg) { @@ -396,9 +399,17 @@ return; Console.WriteLine(before); Console.WriteLine(After); if (before is not SocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends || Before.Id == 0) return Task.CompletedTask; - Label stat = fr.Where(s => s.User.Id == before.Id).First()!.Status; + Friend per = fr.Where(s => s.User.Id == before.Id).First()!; + Label stat = per.Status; Invoke(new Action(() => { + per.rr.BackgroundColor = After.Status switch + { + UserStatus.Online => new(115, 255, 111, 255), + UserStatus.Idle => new(255, 229, 84, 255), + UserStatus.DoNotDisturb => new(255, 51, 79, 255), + UserStatus.Offline or UserStatus.Invisible or _ => Color4.LightGray + }; stat.Text = After.Status.ToString(); })); return Task.CompletedTask; @@ -406,15 +417,15 @@ return; private Task FriendManagerBtnOnClicked(IRenderObject arg) { - if (chat.Visible) + if (chat!.Visible) { chat.Visible = false; - tc.Visible = true; + tc!.Visible = true; } else { chat.Visible = true; - tc.Visible = false; + tc!.Visible = false; } return Task.CompletedTask; } diff --git a/Luski/GUI/MainScreen/UI/Chat.cs b/Luski/GUI/MainScreen/UI/Chat.cs index 65a68c6..3d349f5 100644 --- a/Luski/GUI/MainScreen/UI/Chat.cs +++ b/Luski/GUI/MainScreen/UI/Chat.cs @@ -3,7 +3,6 @@ using GraphicsManager.Interfaces; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using Luski.GUI.MainScreen.Interfaces; -using Luski.net; using Luski.net.Enums; using Luski.net.JsonTypes; using OpenTK.Mathematics; @@ -15,40 +14,38 @@ namespace Luski.GUI.MainScreen.UI; public class Chat : UserControl { public FlowLayout MessageFlow; - private UserControl titlecon;//, typecon; private Label title, desc; private Textbox tb; - private SocketTextChannel? Channel = null; + private SocketTextChannel? Channel; public Chat() { - Size = new((int)(754 * Globals.Settings.Scale), (int)(667 * Globals.Settings.Scale)); + UserControl titlecon; + Size = new((int)(980 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale)); BackgroundColor = new(50, 50, 50, 255); Anchor = ObjectAnchor.All; Controls.Add(MessageFlow = new() { - Size = new((int)(754 * Globals.Settings.Scale), (int)(586 * Globals.Settings.Scale)), - Location = new(0, (int)(40 * Globals.Settings.Scale)), + Size = new(Size.X, (int)(761 * Globals.Settings.Scale)), + Location = new(0, (int)(52 * Globals.Settings.Scale)), BackgroundColor = new(40,40,40,255), Anchor = ObjectAnchor.All, HScrollPixels = Globals.Settings.PerScrollPixels }); - Controls.Add(titlecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Size = new((int)(754 * Globals.Settings.Scale), (int)(40 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor}); - //Controls.Add(typecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right, Location = new(0, (int)(626 * Globals.Settings.Scale)), Size = new((int)(754 * Globals.Settings.Scale), (int)(41 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor}); + Controls.Add(titlecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Size = new((int)(980 * Globals.Settings.Scale), (int)(52 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor}); titlecon.Controls.Add(title = new Label() { Font = Globals.DefaultFont, Location = new( - (int)((20 - (Globals.DefaultFont.PixelHeight / 2)) * Globals.Settings.Scale), - (int)((20 * Globals.Settings.Scale) - (Globals.DefaultFont.PixelHeight / 2))) + (int)((26 - (Globals.DefaultFont.PixelHeight / 2)) * Globals.Settings.Scale), + (int)((26 * Globals.Settings.Scale) - (Globals.DefaultFont.PixelHeight/2.0))) }); titlecon.Controls.Add(desc = new Label(){ Font = Globals.DefaultFont, Color = new(161,161,161,255), Location = new(title.Location.X + title.Size.X + 5, title.Location.Y)}); - //typecon.Controls.Add(); Controls.Add(tb = new Textbox() { Font = Globals.DefaultFont, InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, - Location = new((int)(7.5 * Globals.Settings.Scale), (int)(633.5 * Globals.Settings.Scale)), - Size = new((int)(739 * Globals.Settings.Scale), (int)(26 * Globals.Settings.Scale)), + Location = new((int)(10 * Globals.Settings.Scale), (int)(824 * Globals.Settings.Scale)), + Size = new((int)(960 * Globals.Settings.Scale), (int)(34 * Globals.Settings.Scale)), Anchor = ObjectAnchor.All }); tb.KeyPress += TbOnKeyPress; @@ -66,7 +63,7 @@ public class Chat : UserControl private void Thr() { Globals.Luski.SendMessage(tb.Text, Channel!.Id, CancellationToken.None); - Window!.Invoke(new Action(() => { tb.Text = string.Empty; })); + Window!.Invoke(() => { tb.Text = string.Empty; }); } private Task LuskiOnMessageReceived(SocketMessage arg) @@ -75,7 +72,7 @@ public class Chat : UserControl IRenderObject? reff = null; if (MessageFlow.Controls.Length > 0) reff = MessageFlow.Controls[MessageFlow.Controls.Length - 1]; AddMessage(Window!.TextureManager, arg); - if (reff is null || (reff.Location.Y + reff.Size.Y <= MessageFlow.Size.Y && reff.Location.X >= 0)) Window.Invoke(new Action(() => { MessageFlow.ScrollToBottom();})); + if (reff is null || (reff.Location.Y + reff.Size.Y <= MessageFlow.Size.Y && reff.Location.X >= 0)) Window.Invoke(() => { MessageFlow.ScrollToBottom();}); return Task.CompletedTask; } @@ -108,9 +105,9 @@ public class Chat : UserControl } } - private SocketMessage? lastm = null; - private long? lastUser = null; - private ChatMessage? LastChatMessage = null; + private SocketMessage? lastm; + private long? lastUser; + private ChatMessage? LastChatMessage; public void AddMessage(TextureManager m, SocketMessage Message) { @@ -127,7 +124,11 @@ public class Chat : UserControl MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m, Message)); } else - Globals.ms!.Invoke(new Action(() => { MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m ,Message)); Window.DrawFrame(); })); + Globals.ms.Invoke(() => + { + MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m, Message)); + Window.DrawFrame(); + }); } else { @@ -136,7 +137,7 @@ public class Chat : UserControl LastChatMessage!.AddMessage(Message); } else - Globals.ms!.Invoke(new Action(() => { LastChatMessage!.AddMessage(Message); Window!.DrawFrame(); })); + Globals.ms.Invoke(() => { LastChatMessage!.AddMessage(Message); Window!.DrawFrame(); }); } lastUser = Message.AuthorID; diff --git a/Luski/GUI/MainScreen/UI/ChatMessage.cs b/Luski/GUI/MainScreen/UI/ChatMessage.cs index 80b81e0..7f6fdae 100644 --- a/Luski/GUI/MainScreen/UI/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/ChatMessage.cs @@ -1,3 +1,4 @@ +using System.Reflection; using GraphicsManager; using GraphicsManager.Enums; using GraphicsManager.Interfaces; @@ -6,8 +7,8 @@ using GraphicsManager.Objects.Core; using Luski.net.Enums; using Luski.net.Interfaces; using Luski.net.JsonTypes; +using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; -using File = Luski.net.JsonTypes.File; namespace Luski.GUI.MainScreen.UI; @@ -16,12 +17,13 @@ public class ChatMessage : UserControl readonly int padding = 2; private static Font TimeFont = Font.MakeFontFromSystem(13); private SocketMessage Msg { get; } - private Label label1, label2, lastm; + private Label label2, lastm; private static Dictionary Menues = new(); private static Dictionary> Messages = new(); public ChatMessage(TextureManager tm, SocketMessage message) { + Label label1; Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale)); BackgroundColor = new(40, 40, 40, 255); @@ -29,7 +31,7 @@ public class ChatMessage : UserControl IUser user = message.GetAuthor(CancellationToken.None).Result; Anchor = ObjectAnchor.Left | ObjectAnchor.Right; - Controls.Add(label1 = new Label() { Font = Globals.DefaultFont, Location = new((int)(42 * Globals.Settings.Scale), (int)(4.5 * Globals.Settings.Scale)), Text = user.Username}); + Controls.Add(label1 = new Label() { Font = Globals.DefaultFont, Location = new((int)(54 * Globals.Settings.Scale), (int)(6 * Globals.Settings.Scale)), Text = user.Username}); @@ -47,9 +49,15 @@ public class ChatMessage : UserControl { timestr = $"{time:M/dd/yyyy h:mm tt}"; } - Controls.Add(new Label() { Font = Globals.DefaultFont, Location = new(label1.Location.X + label1.Size.X + 4, (int)(4.5 * Globals.Settings.Scale)), Text = timestr}); - Controls.Add(new Rectangle(tm.AddTexture(user.GetAvatar(CancellationToken.None).Result, true)) { Location = new((int)(7.5 * Globals.Settings.Scale), (int)(1.5 * Globals.Settings.Scale)), Size = new((int)(29 * Globals.Settings.Scale)) }); - Controls.Add(label2 = new Label() { Font = Globals.DefaultFont, Location = new((int)(41.5 * Globals.Settings.Scale), (int)(20 * Globals.Settings.Scale)), Text = message.Context}); + Controls.Add(new Label() { Scale = 0.8f, Font = Globals.DefaultFont, Location = new(label1.Location.X + label1.Size.X + 4, label1.Location.Y), Text = timestr}); + Rectangle r = new Rectangle(tm.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), + "Luski.Resources.Textures.Status.png"))) { Location = new((int)(10 * Globals.Settings.Scale), (int)(2 * Globals.Settings.Scale)), Size = new((int)(38 * Globals.Settings.Scale)) }; + Texture tex = tm.AddTexture(user.GetAvatar(CancellationToken.None).Result); + tex.Unit = TextureUnit.Texture1; + r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; + r.Textures.Add(tex); + Controls.Add(r); + Controls.Add(label2 = new Label() { Font = Globals.DefaultFont, Location = new(label1.Location.X, (int)(label1.Location.Y + label1.Font.PixelHeight + (5 * Globals.Settings.Scale))), Text = message.Context}); lastm = label2; if (Msg.Files != null && Msg.Files.Length > 0) { @@ -109,7 +117,8 @@ public class ChatMessage : UserControl Messages.Remove(uu); Menues.Remove(uu); - SocketRemoteUser? result = Globals.Luski.SendFriendRequest(long.Parse(uu.friend_codes.First()), CancellationToken.None).Result; + SocketRemoteUser result = Globals.Luski + .SendFriendRequest(long.Parse(uu.friend_codes.First()), CancellationToken.None).Result; if (result.Channel is null) Globals.ms.AddFriendRequest(result); else @@ -132,11 +141,11 @@ public class ChatMessage : UserControl newLabel.MouseEnter += NewLabel_MouseEnter; newLabel.MouseLeave += NewLabel_MouseLeave; Controls.Add(newLabel); - if (msg.Files != null && msg.Files.Length > 0) + if (msg.Files is not null && msg.Files.Length > 0) { int row = 1; int filesonrow = 0; - for (int i = 0; i < Msg.Files.Length; i++) + for (int i = 0; i < msg.Files.Length; i++) { int lx = (padding * filesonrow) + lastm.Location.X + (333 * (filesonrow + 1)); if (lx > Size.X) @@ -147,7 +156,7 @@ public class ChatMessage : UserControl } filesonrow++; - Controls.Add(new ContentEmbed(Msg.Files[i], Msg.ChannelID) + 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))) }); @@ -162,8 +171,8 @@ public class ChatMessage : UserControl if (label.Tag is not SocketMessage Message) return Task.CompletedTask; DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime(); string b = time.ToString("h:mm tt"); - IEnumerable