From c178ec62cf2c9b3cbe3845a31b3cfdad7b22d8e2 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Mon, 21 Aug 2023 10:55:03 -0400 Subject: [PATCH] Public Servers. Added a bunch of controls to use in public servers. --- Luski/Clesses/ServerInfo.cs | 19 + Luski/Clesses/ServerList.cs | 30 ++ Luski/Clesses/Settings.cs | 6 - Luski/GUI/MainScreen.cs | 425 ++++++++++++------ .../MainScreen/Interfaces/IChannelAdder.cs | 12 + Luski/GUI/MainScreen/UI/AddFriendPage.cs | 2 +- Luski/GUI/MainScreen/UI/Chat.cs | 15 +- Luski/GUI/MainScreen/UI/ChatMessage.cs | 22 +- Luski/GUI/MainScreen/UI/ContentEmbed.cs | 6 +- Luski/GUI/MainScreen/UI/Friend.cs | 14 +- Luski/GUI/MainScreen/UI/FriendRequest.cs | 6 +- Luski/GUI/MainScreen/UI/Group.cs | 10 +- .../MainScreen/UI/PublicServers/Category.cs | 203 +++++++++ .../MainScreen/UI/PublicServers/Channel.cs | 183 ++++++++ .../UI/PublicServers/ChannelSelector.cs | 104 +++++ .../UI/PublicServers/ChatMessage.cs | 224 +++++++++ .../UI/PublicServers/ContentEmbed.cs | 117 +++++ .../MainScreen/UI/PublicServers/PublicChat.cs | 126 ++++++ Luski/GUI/MainScreen/UI/ServerIcon.cs | 86 ++++ Luski/GUI/StartPage/UI/CreateAccount.cs | 16 +- Luski/GUI/StartPage/UI/Login.cs | 10 +- Luski/GUI/UpdateWindow.cs | 14 +- Luski/Globals.cs | 64 ++- Luski/Interfaces/IThemeObject.cs | 8 + Luski/Luski.csproj | 7 +- Luski/Program.cs | 51 ++- Luski/Resources/Textures/ac.png | Bin 0 -> 406 bytes Luski/Resources/Textures/al.png | Bin 0 -> 943 bytes Luski/Resources/Textures/ar.png | Bin 0 -> 845 bytes Luski/Resources/Textures/rc.png | Bin 0 -> 1561 bytes Luski/Temp.cs | 242 ++++++++++ 31 files changed, 1807 insertions(+), 215 deletions(-) create mode 100644 Luski/Clesses/ServerInfo.cs create mode 100644 Luski/Clesses/ServerList.cs create mode 100644 Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/Category.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/Channel.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs create mode 100644 Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs create mode 100644 Luski/GUI/MainScreen/UI/ServerIcon.cs create mode 100644 Luski/Interfaces/IThemeObject.cs create mode 100644 Luski/Resources/Textures/ac.png create mode 100644 Luski/Resources/Textures/al.png create mode 100644 Luski/Resources/Textures/ar.png create mode 100644 Luski/Resources/Textures/rc.png create mode 100644 Luski/Temp.cs diff --git a/Luski/Clesses/ServerInfo.cs b/Luski/Clesses/ServerInfo.cs new file mode 100644 index 0000000..479e808 --- /dev/null +++ b/Luski/Clesses/ServerInfo.cs @@ -0,0 +1,19 @@ +using System.Text.Json.Serialization; + +namespace Luski.Clesses; + +public class ServerInfo +{ + [JsonInclude] + [JsonPropertyName("domain")] + public string Domain { get; set; } = default!; + [JsonInclude] + [JsonPropertyName("version")] + public string Version { get; set; } = "v1"; + [JsonInclude] + [JsonPropertyName("is_main")] + public bool Main { get; set; } = false; + [JsonInclude] + [JsonPropertyName("is_secure")] + public bool Secure { get; set; } = true; +} \ No newline at end of file diff --git a/Luski/Clesses/ServerList.cs b/Luski/Clesses/ServerList.cs new file mode 100644 index 0000000..f2c74fb --- /dev/null +++ b/Luski/Clesses/ServerList.cs @@ -0,0 +1,30 @@ +using System.Text.Json.Serialization; + +namespace Luski.Clesses; + +public class ServerList +{ + [JsonInclude] + [JsonPropertyName("servers")] + public ServerInfo[] Server { get; set; } = new [] + { + new ServerInfo() + { + Domain = "10.100.0.10:5287", + Version = "v1", + Main = false, + Secure = false + } + }; +} + +[JsonSerializable(typeof(ServerList))] +[JsonSourceGenerationOptions( + GenerationMode = JsonSourceGenerationMode.Default, + PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified, + WriteIndented = true, + DefaultIgnoreCondition = JsonIgnoreCondition.Never)] +internal partial class ServerListContext : JsonSerializerContext +{ + +} \ No newline at end of file diff --git a/Luski/Clesses/Settings.cs b/Luski/Clesses/Settings.cs index 462e75f..f9fef7f 100644 --- a/Luski/Clesses/Settings.cs +++ b/Luski/Clesses/Settings.cs @@ -8,12 +8,6 @@ public class Settings [JsonPropertyName("scale")] public double Scale { get; set; } = 1; [JsonInclude] - [JsonPropertyName("api_domain")] - public string Domain { get; set; } = "api.beta.luski.jacobtech.com"; - [JsonInclude] - [JsonPropertyName("api_v")] - public string Version { get; set; } = "v1"; - [JsonInclude] [JsonPropertyName("perscrollpixels")] public uint PerScrollPixels { get; set; } = 20; [JsonInclude] diff --git a/Luski/GUI/MainScreen.cs b/Luski/GUI/MainScreen.cs index 87df501..33dec9e 100644 --- a/Luski/GUI/MainScreen.cs +++ b/Luski/GUI/MainScreen.cs @@ -9,6 +9,7 @@ using GraphicsManager.Objects.Core; using JacobTechEncryption; using Luski.GUI.MainScreen.Interfaces; using Luski.GUI.MainScreen.UI; +using Luski.GUI.MainScreen.UI.PublicServers; using Luski.GUI.StartPage.UI; using Luski.net; using Luski.net.Enums; @@ -16,6 +17,7 @@ using Luski.net.Enums.Main; using Luski.net.Interfaces; using Luski.net.JsonTypes; using Luski.net.Structures.Main; +using Luski.net.Structures.Public; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; using OpenTK.Windowing.Desktop; @@ -35,7 +37,7 @@ public class MainScreen : Window StartFocused = true, Size = new Vector2i((int)(312 * Globals.Settings.Scale), (int)(545 * Globals.Settings.Scale)), Icon = Globals.Icon, - SharedContext = null + SharedContext = null, }; public TabControl? tc; @@ -61,53 +63,68 @@ public class MainScreen : Window // The rest of the function is up to you to implement, however a debug output // is always useful. - - switch (severity) + + if (false) { - case DebugSeverity.DebugSeverityHigh: - Console.ForegroundColor = ConsoleColor.DarkRed; - Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message); - Console.ResetColor(); - break; - case DebugSeverity.DebugSeverityMedium: - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message); - Console.ResetColor(); - break; - default: - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine(message); - Console.ResetColor(); - break; + switch (severity) + { + case DebugSeverity.DebugSeverityHigh: + Console.ForegroundColor = ConsoleColor.DarkRed; + Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message); + Console.ResetColor(); + break; + case DebugSeverity.DebugSeverityMedium: + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message); + Console.ResetColor(); + break; + default: + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine(message); + Console.ResetColor(); + break; + } } } public MainScreen() : base(Settings) { VSync = VSyncMode.On; + this.TryGetCurrentMonitorScale(out var h, out var v); GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero); GL.Enable(EnableCap.DebugOutput); - Globals.DefaultFont = - Font.MakeEmbeddedFont("Luski.Resources.Fonts.OpenSans-Regular.ttf", Assembly.GetExecutingAssembly()); - //Globals.DefaultFont = Font.MakeFontFromFile(@"C:\Users\techn\Downloads\tahoma.ttf"); + Globals.DefaultFontFamly = FontFamily.LoadFontFamily("Noto Sans").Result; + Globals.DefaultFont = FontInteraction.Load(Globals.DefaultFontFamly); Globals.DefaultFont.PixelHeight = (uint)(20 * Globals.Settings.Scale); - Globals.LuskiTexture = TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), + Globals.DefaultFont.FontSize = FontSize.Regular; + Globals.TopTimeFont = Globals.DefaultFont.Clone(); + Globals.TopTimeFont.PixelHeight = (uint)(12 * Globals.Settings.Scale); + Globals.TopTimeFont.FontSize = FontSize.Regular; + Globals.MessageFont = Globals.DefaultFont.Clone(); + Globals.MessageFont.PixelHeight = (uint)(17 * Globals.Settings.Scale); + Globals.MessageFont.ExtraLinePixels = (uint)(5 * Globals.Settings.Scale); + Globals.MessageFont.FontSize = FontSize.Regular; + Globals.SmallTimeFont = Globals.DefaultFont.Clone(); + Globals.LuskiTexture = TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Luski.png")); CenterWindow(0); - Controls.Add(ca = new CreateAccount()); - ca.Visible = false; - ca.ChangeToApp += LoginOnChangeToApp; - Controls.Add(login = new Login()); - - login.ChangeToApp += LoginOnChangeToApp; - login.ChangeToCa += LoginOnChangeToCa; - - Thread t = new(_ => + if ((Globals.Luski.MainServer is not null && !Globals.Luski.MainServer.IsLogedIn) || !Globals.Luski.LoadedServers.Any(s => s.IsLogedIn)) { - Globals.Luski.MainServer.EncryptionHandler.GenerateKeys(); + Controls.Add(ca = new CreateAccount()); + ca.Visible = false; + ca.ChangeToApp += LoginOnChangeToApp; + Controls.Add(login = new Login()); + + login.ChangeToApp += LoginOnChangeToApp; + login.ChangeToCa += LoginOnChangeToCa; + Thread t = new(_ => + { + if (Globals.Luski.MainServer is not null)Globals.Luski.MainServer.EncryptionHandler.GenerateKeys(); - }); - t.Start(); + }); + t.Start(); + + } WindowLoaded += OnWindowLoaded; } @@ -123,6 +140,9 @@ public class MainScreen : Window Close(); } } + + if ((Globals.Luski.MainServer is not null && Globals.Luski.MainServer.IsLogedIn) || Globals.Luski.LoadedServers.Any(s => s.IsLogedIn)) Invoke(() => LoginOnChangeToApp()); + return Task.CompletedTask; } @@ -235,133 +255,274 @@ public class MainScreen : Window Console.WriteLine(e); } } + public FlowLayout ser; + private UserControl? SerBox; + public PublicChat pc; + + public async Task LoadPublicServer(PublicServer? Server) + { + if (Server is null) return; + BlockDraw = true; + try + { + #region Box Init + if (SerBox is null) + { + SerBox = new() + { + Location = new(ser.Size.X, 0), + Size = new(Size.X - ser.Size.X, Size.Y), + Anchor = ObjectAnchor.All, + BackgroundColor = Color4.DarkRed + }; + Controls.Add(SerBox); + SerBox.LoadToParent(this, this); + } + + SerBox.Controls.Clear(); + #endregion + + #region Channel Selector Init + SocketChannel currentchannel = await Server.User.GetSelectedChannel(CancellationToken.None); + List parents = new(); + SocketCategory? cur = await currentchannel.GetParent(); + while (cur is not null) + { + parents.Add(cur); + cur = await cur.GetParent(); + } - private Task LoginOnChangeToApp() + parents.Reverse(); + ChannelSelector cs = new(parents[0]) + { + BackgroundColor = new(34, 34, 34, 255), + Size = new((int)(307 * Globals.Settings.Scale), SerBox.Size.Y - 150), + Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom + }; + parents.RemoveAt(0); + SerBox.Controls.Add(cs); + cs.LoadToParent(SerBox, this); + cs.ForceDistanceUpdate(); + Channel.SelectedTextures[0] = Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.al.png")); + Channel.SelectedTextures[1] = Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.ac.png")); + Channel.SelectedTextures[2] = Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.ar.png")); + #endregion + + #region Chat Init + pc = new() + { + Anchor = ObjectAnchor.All, + Location = new(cs.Size.X, 0), + Size = new(SerBox.Size.X - cs.Size.X, SerBox.Size.Y), + }; + SerBox.Controls.Add(pc); + pc.LoadToParent(SerBox, this); + pc.ForceDistanceUpdate(); + pc.MessageFlow.ForceDistanceUpdate(pc); + #endregion + + #region Channel Selector Loader + _ = cs.Load(currentchannel, parents); + #endregion + + #region User Icon + Role[] ra = await Server.User.GetRoles(); + Color c = ra[0].Color; + Color4 c4 = new(c.R, c.G, c.B, c.A); + Rectangle u=new Rectangle(TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), + "Luski.Resources.Textures.Status.png"))) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(46 * Globals.Settings.Scale)), Location = new((int)(4 * Globals.Settings.Scale), (int)(812 * Globals.Settings.Scale))}; + u.Shader = Rectangle.DefaultAlphaTextureShader[Context]; + u.Textures.Add(await Server.User.GetIcon()); + SerBox.Controls.Add(u); + u.LoadToParent(SerBox, this); + u.ForceDistanceUpdate(); + Label ul = new Label(Globals.DefaultFont) + { + Anchor = u.Anchor, + Text = Server.User.DisplayName, + Color = c4 + }; + + ul.Location = new(u.Location.X + u.Size.X + (int)(5 * Globals.Settings.Scale), + (u.Location.Y + (u.Size.Y / 2) - (ul.PostiveTrueHeight / 2) - ul.Size.Y + ul.TrueHeight)); + SerBox.Controls.Add(ul); + #endregion + + + } + catch (Exception e) + { + Console.WriteLine(e); + } + BlockDraw = false; + } + + public async Task LoadMainServer(MainServer Server) + { + if (SerBox is null) SerBox = new() + { + Location = new(ser.Size.X, 0), + Size = new(Size.X - ser.Size.X, Size.Y), + Anchor = ObjectAnchor.All + }; + Controls.Add(SerBox); + SerBox.ForceDistanceUpdate(); + SerBox.Controls.Clear(); + } + + private async Task LoginOnChangeToApp() { Controls.Clear(); BlockDraw = true; Title = "Luski"; - // string Public, Private; - // using (RSACryptoServiceProvider cryptoServiceProvider = new RSACryptoServiceProvider(Encryption.NewKeySize)) - //{ - // Private = cryptoServiceProvider.ToXmlString(true); - // Public = cryptoServiceProvider.ToXmlString(false); - //} - // Luski.net.Encryption.File.Channels.AddKey(69, Private); - //Clip - // Console.WriteLine(Public); - //Globals.Luski.SetMultiThreadPercent(Globals.Settings.MultiThreadPercent); 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); - 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.MainServer.User.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.MainServer.User.DisplayName }; - FlowLayout ser; - 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)(52 * Globals.Settings.Scale),(int)(868 * Globals.Settings.Scale)), + Size = new((int)(68 * Globals.Settings.Scale), (int)(868 * Globals.Settings.Scale)), Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom, - + }); - Controls.Add(tc = new()// this is here to showcase my good friend TCLL + // PublicServer? SelectedPublicServer; + DrawFrame(); + if (Globals.Luski.MainServer is not null) { - Location = chat.Location, - Size = chat.Size, - BackgroundColor = chat.BackgroundColor, - Anchor = ObjectAnchor.All, - Visible = false, - TitleFont = Globals.DefaultFont, - Border = (int)( 10 * Globals.Settings.Scale), - TabSpace = (int)(5 * Globals.Settings.Scale), - }); - tc.AddPage("Friends", friends = new FlowLayout() - { - BackgroundColor = new(45,45,45,255) - }); - 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) - { - Size = new((int)(52 * Globals.Settings.Scale)), - }); - Controls.Add(channelpicker = new FlowLayout() - { - BackgroundColor = new(34,34,34,255), - 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)(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 (MainSocketGroupChannel ch in Globals.Luski.MainServer.User.Channels.Where(s => s is MainSocketGroupChannel).Cast()) - { - AddGroup(ch); - } - foreach (MainSocketRemoteUser item in Globals.Luski.MainServer.User.Friends) - { - if (item.Channel is not null) AddFriend(item); - } - Console.WriteLine("Channels done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - - MainSocketTextChannel chan = Globals.Luski.MainServer.GetChannel(Globals.Luski.MainServer.User.SelectedChannel, CancellationToken.None).Result; - chat.UpdateTitle(chans.First(s => s.Channel.Id == chan.Id)); - chat.MessageFlow.BlockDraw = true; - try - { - IReadOnlyList messages = chan.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; - Console.WriteLine("Messages done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - foreach (MainSocketMessage message in messages.Reverse()) + Texture uut = + TextureManager.AddTexture(Globals.Luski.MainServer.User.GetAvatar(CancellationToken.None).Result); + uut.Unit = TextureUnit.Texture1; + // u.Shader = Rectangle.DefaultAlphaTextureShader[Context]; + //u.Textures.Add(uut); + //Controls.Add(u); + Label ul = new Label(Globals.DefaultFont) { - chat.AddMessage(TextureManager, message); + Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, + Location = new(0, (int)(826 * Globals.Settings.Scale)), Text = Globals.Luski.MainServer.User.DisplayName + }; + + // 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(tc = new(Globals.DefaultFont) // this is here to showcase my good friend TCLL + { + Location = chat.Location, + Size = chat.Size, + BackgroundColor = chat.BackgroundColor, + Anchor = ObjectAnchor.All, + Visible = false, + Border = (int)(10 * Globals.Settings.Scale), + TabSpace = (int)(5 * Globals.Settings.Scale), + }); + tc.AddPage("Friends", friends = new FlowLayout() + { + BackgroundColor = new(45, 45, 45, 255) + }); + 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) + { + Size = new((int)(52 * Globals.Settings.Scale)), + }); + + + Controls.Add(channelpicker = new FlowLayout() + { + BackgroundColor = new(34, 34, 34, 255), + 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(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"); + MainSocketChannel sssss = Globals.Luski.MainServer.GetChannel(0, CancellationToken.None) + .Result; + _ = Globals.Luski.MainServer.User.Channels; + foreach (MainSocketGroupChannel ch in Globals.Luski.MainServer.User.Channels + .Where(s => s is MainSocketGroupChannel).Cast()) + { + AddGroup(ch); } - chat.MessageFlow.ScrollToBottom(); - } - catch (Exception e) - { - Console.WriteLine(e); - ChannelOnClickCon(chans.Where(s => s.Channel.Id == 0).First()); + + foreach (MainSocketRemoteUser item in Globals.Luski.MainServer.User.Friends) + { + if (item.Channel is not null) AddFriend(item); + } + + Console.WriteLine("Channels done in " + (DateTime.Now - start).TotalSeconds + " seconds"); + + MainSocketTextChannel chan = Globals.Luski.MainServer + .GetChannel(Globals.Luski.MainServer.User.SelectedChannel, + CancellationToken.None).Result; + chat.UpdateTitle(chans.First(s => s.Channel.Id == chan.Id)); + chat.MessageFlow.BlockDraw = true; + try + { + IReadOnlyList messages = + chan.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; + Console.WriteLine("Messages done in " + (DateTime.Now - start).TotalSeconds + " seconds"); + foreach (MainSocketMessage message in messages.Reverse()) + { + chat.AddMessage(TextureManager, message); + } + + chat.MessageFlow.ScrollToBottom(); + } + catch (Exception e) + { + Console.WriteLine(e); + ChannelOnClickCon(chans.Where(s => s.Channel.Id == 0).First()); + } + + chat.MessageFlow.BlockDraw = false; + + Console.WriteLine("Messages Fonts done in " + (DateTime.Now - start).TotalSeconds + " seconds"); + foreach (MainSocketRemoteUser cufr in Globals.Luski.MainServer.User.FriendRequests) + { + AddFriendRequest(cufr); + } + + Console.WriteLine("FR done in " + (DateTime.Now - start).TotalSeconds + " seconds"); + BlockDraw = false; + DrawFrame(); + Console.WriteLine("GUI done in " + (DateTime.Now - start1).TotalSeconds + " seconds"); } - chat.MessageFlow.BlockDraw = false; - - Console.WriteLine("Messages Fonts done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - foreach (MainSocketRemoteUser cufr in Globals.Luski.MainServer.User.FriendRequests) + foreach (PublicServer pser in Globals.Luski.LoadedServers) { - AddFriendRequest(cufr); + ser.Controls.Add(new ServerIcon(pser)); } - Console.WriteLine("FR done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - BlockDraw = false; - DrawFrame(); - Console.WriteLine("GUI done in " + (DateTime.Now - start1).TotalSeconds + " seconds"); + + await (ser.Controls[0] as ServerIcon)!.LoadServer(); + MainShow += OnMainShow; - MainShow.Invoke(); return Task.CompletedTask; } private Task OnMainShow() { - Globals.Luski.MainServer.OnError += LuskiOnOnError; - Globals.Luski.MainServer.UserStatusUpdate += LuskiOnUserStatusUpdate; - Globals.Luski.MainServer.ReceivedFriendRequest += LuskiOnReceivedFriendRequest; - Globals.Luski.MainServer.FriendRequestResult += LuskiOnFriendRequestResult; + if (Globals.Luski.MainServer is not null && Globals.Luski.MainServer.IsLogedIn) + { + Globals.Luski.MainServer.OnError += LuskiOnOnError; + Globals.Luski.MainServer.UserStatusUpdate += LuskiOnUserStatusUpdate; + Globals.Luski.MainServer.ReceivedFriendRequest += LuskiOnReceivedFriendRequest; + Globals.Luski.MainServer.FriendRequestResult += LuskiOnFriendRequestResult; + } + return Task.CompletedTask; } diff --git a/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs b/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs new file mode 100644 index 0000000..68a3ea4 --- /dev/null +++ b/Luski/GUI/MainScreen/Interfaces/IChannelAdder.cs @@ -0,0 +1,12 @@ +using Luski.GUI.MainScreen.UI.PublicServers; +using Luski.net.Structures.Public; + +namespace Luski.GUI.MainScreen.Interfaces; + +public interface IChannelAdder +{ + public bool Extended { get; set; } + public SocketCategory CurrentCategory { get; } + public Task AddChannel(SocketChannel chan); + public Task AddCategory(SocketCategory Cat, DateTime? dt = null); +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddFriendPage.cs b/Luski/GUI/MainScreen/UI/AddFriendPage.cs index c98bfe1..765078b 100644 --- a/Luski/GUI/MainScreen/UI/AddFriendPage.cs +++ b/Luski/GUI/MainScreen/UI/AddFriendPage.cs @@ -17,7 +17,7 @@ public class AddFriendPage : FlowLayout this.Screen = Parent; Size = new((int)(200 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)); BackgroundColor = new(45,45,45,255); - Controls.Add(Input = new Textbox() { Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Location = new((int)(7.5 * Globals.Settings.Scale)), Size = new((int)(185 * Globals.Settings.Scale),(int)(20 * Globals.Settings.Scale)), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); + Controls.Add(Input = new Textbox(Globals.DefaultFont, Globals.DefaultFont) { Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Location = new((int)(7.5 * Globals.Settings.Scale)), Size = new((int)(185 * Globals.Settings.Scale),(int)(20 * Globals.Settings.Scale)), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); Input.KeyPress += InputOnKeyPress; } diff --git a/Luski/GUI/MainScreen/UI/Chat.cs b/Luski/GUI/MainScreen/UI/Chat.cs index 3647e32..342700c 100644 --- a/Luski/GUI/MainScreen/UI/Chat.cs +++ b/Luski/GUI/MainScreen/UI/Chat.cs @@ -35,16 +35,15 @@ public class Chat : UserControl HScrollPixels = Globals.Settings.PerScrollPixels }); 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() + titlecon.Controls.Add(title = new Label(Globals.DefaultFont) { - Font = Globals.DefaultFont, Location = new( - (int)((26 - (Globals.DefaultFont.PixelHeight / 2)) * Globals.Settings.Scale), - (int)((26 * Globals.Settings.Scale) - (Globals.DefaultFont.PixelHeight/2.0))) + //Location = new( + // (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)}); - Controls.Add(tb = new Textbox() + titlecon.Controls.Add(desc = new Label(Globals.DefaultFont){ Color = new(161,161,161,255), Location = new(title.Location.X + title.Size.X + 5, title.Location.Y)}); + Controls.Add(tb = new Textbox(Globals.DefaultFont, Globals.DefaultFont) { - Font = Globals.DefaultFont, InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, Location = new((int)(10 * Globals.Settings.Scale), (int)(824 * Globals.Settings.Scale)), @@ -92,7 +91,7 @@ public class Chat : UserControl if (Channel is not null && Channel!.Id == channelPick.Channel.Id) return; Channel = channelPick.Channel; title.Text = channelPick.Channel.Title; - tb.WatermarkFont = Globals.DefaultFont; + //tb.WatermarkFont = Globals.DefaultFont; if (channelPick.Channel.Type == ChannelType.DM) title.Text = (channelPick.Channel as MainSocketDMChannel)!.User.DisplayName; tb.WatermarkText = "Message " + title.Text; diff --git a/Luski/GUI/MainScreen/UI/ChatMessage.cs b/Luski/GUI/MainScreen/UI/ChatMessage.cs index b3428a7..89fe564 100644 --- a/Luski/GUI/MainScreen/UI/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/ChatMessage.cs @@ -18,7 +18,7 @@ namespace Luski.GUI.MainScreen.UI; public class ChatMessage : UserControl { readonly int padding = 2; - private static Font TimeFont = Font.MakeFontFromSystem(13); + private static Font TimeFont;// = Font.MakeFontFromSystem(13); private MainSocketMessage Msg { get; } private Label label2, lastm; private static Dictionary Menues = new(); @@ -34,7 +34,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)(54 * Globals.Settings.Scale), (int)(6 * Globals.Settings.Scale)), Text = user.DisplayName}); + Controls.Add(label1 = new Label(Globals.DefaultFont) { Location = new((int)(54 * Globals.Settings.Scale), (int)(6 * Globals.Settings.Scale)), Text = user.DisplayName}); @@ -52,15 +52,15 @@ public class ChatMessage : UserControl { timestr = $"{time:M/dd/yyyy h:mm tt}"; } - 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(), + Controls.Add(new Label(Globals.DefaultFont) { Scale = 0.8f, Location = new(label1.Location.X + label1.Size.X + 4, label1.Location.Y), Text = timestr}); + Rectangle r = new Rectangle(tm.AddTexture(Tools.GetResourceStream(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}); + Controls.Add(label2 = new Label(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) { @@ -91,10 +91,10 @@ public class ChatMessage : UserControl { ContextMenu m = new((int)(150 * Globals.Settings.Scale)); RoundedButton d; - m.Items.Add(d = new RoundedButton() + m.Items.Add(d = new RoundedButton(Globals.DefaultFont) { InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, - Size = new((int)(25 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Add Friend" + Size = new((int)(25 * Globals.Settings.Scale)), Text = "Add Friend" }); d.Tag = this; Menues.Add(u,m); @@ -133,9 +133,8 @@ public class ChatMessage : UserControl public void AddMessage(MainSocketMessage msg) { - Label newLabel = new() + Label newLabel = new(Globals.DefaultFont) { - Font = Globals.DefaultFont, Text = msg.Context, Tag = msg, Location = new(label2.Location.X, Size.Y) @@ -189,11 +188,10 @@ public class ChatMessage : UserControl if (sender is not Label label) return Task.CompletedTask; if (label.Tag is not MainSocketMessage Message) return Task.CompletedTask; DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime(); - Label m = new() + Label m = new(Globals.DefaultFont) { - Font = TimeFont, Text = time.ToString("h:mm tt"), - Location = new((int)(7.5 * Globals.Settings.Scale), label.Location.Y - (int)TimeFont.PixelHeight + (int)label.Font.PixelHeight), + Location = new((int)(7.5 * Globals.Settings.Scale), label.Location.Y - 13 + (int)label.Font.PixelHeight), }; Controls.Add(m); diff --git a/Luski/GUI/MainScreen/UI/ContentEmbed.cs b/Luski/GUI/MainScreen/UI/ContentEmbed.cs index a8bcb99..00df437 100644 --- a/Luski/GUI/MainScreen/UI/ContentEmbed.cs +++ b/Luski/GUI/MainScreen/UI/ContentEmbed.cs @@ -27,10 +27,10 @@ public class ContentEmbed : UserControl else if (size < 1000000000000) fst = Math.Round(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(fileNameLabel = new Label() { Color = new(102/(float)255,227/(float)255,170/(float)255, 1), Text = file.Name, Location = new(64, 6)}); + Controls.Add(fileSizeLabel = new Label(Globals.DefaultFont) {Text = fst, Location = new(64, 39)}); + Controls.Add(fileNameLabel = new Label(Globals.DefaultFont) { Color = new(102/(float)255,227/(float)255,170/(float)255, 1), Text = file.Name, Location = new(64, 6)}); fileNameLabel.Clicked += FileNameLabelOnClicked; - byte[] tempp = Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Download.png"); + Stream tempp = Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Download.png"); Controls.Add(new Rectangle(Globals.ms.TextureManager.AddTexture(tempp)) { Location = new(8, 6), Size = new(50, 50)}); int temp = fileNameLabel.Size.X + fileNameLabel.Location.X; int temp2 = fileSizeLabel.Size.X + fileSizeLabel.Location.X; diff --git a/Luski/GUI/MainScreen/UI/Friend.cs b/Luski/GUI/MainScreen/UI/Friend.cs index e19b113..e4f03a4 100644 --- a/Luski/GUI/MainScreen/UI/Friend.cs +++ b/Luski/GUI/MainScreen/UI/Friend.cs @@ -34,11 +34,11 @@ public class Friend : UserControl, IChannelPick Size = new((int)(240 * Globals.Settings.Scale), (int)(62* Globals.Settings.Scale)); BackgroundColor = new(34, 34, 34, 255); - Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = person.DisplayName, Location = new((int)(58 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); - Controls.Add(Status = new Label() { Scale = 0.8f, Font = Globals.DefaultFont, Text = person.Status.ToString(), Location = new((int)(58 * Globals.Settings.Scale),(int)(34* Globals.Settings.Scale))}); + Controls.Add(Username = new Label(Globals.DefaultFont) { Text = person.DisplayName, Location = new((int)(58 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); + Controls.Add(Status = new Label(Globals.DefaultFont) { Scale = 0.8f, Text = person.Status.ToString(), Location = new((int)(58 * Globals.Settings.Scale),(int)(34* Globals.Settings.Scale))}); - Controls.Add(this.rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), + Controls.Add(this.rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Status.png"))) { Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], Location = new((int)(10 * Globals.Settings.Scale), (int)(10 * Globals.Settings.Scale)), Size = new ((int)(42 * Globals.Settings.Scale)) @@ -64,15 +64,15 @@ public class Friend : UserControl, IChannelPick this.Clicked += AllOnClicked; ContextMenu = new((int)(196 * Globals.Settings.Scale)); RoundedButton rrr, rr2; - ContextMenu.Items.Add(rrr=new() + ContextMenu.Items.Add(rrr=new(Globals.DefaultFont) { InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, - Size = new((int)(32 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Export Keys" + Size = new((int)(32 * Globals.Settings.Scale)), Text = "Export Keys" }); - ContextMenu.Items.Add(rr2=new() + ContextMenu.Items.Add(rr2=new(Globals.DefaultFont) { InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, - Size = new((int)(32 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Open In New Window" + Size = new((int)(32 * Globals.Settings.Scale)), Text = "Open In New Window" }); rr2.Clicked += Rr2OnClicked; rrr.Clicked += RrOnClicked; diff --git a/Luski/GUI/MainScreen/UI/FriendRequest.cs b/Luski/GUI/MainScreen/UI/FriendRequest.cs index 8413951..3119c00 100644 --- a/Luski/GUI/MainScreen/UI/FriendRequest.cs +++ b/Luski/GUI/MainScreen/UI/FriendRequest.cs @@ -28,7 +28,7 @@ public class FriendRequest : UserControl BackgroundColor = new(34, 34, 34, 255); // Controls.Add(new Rectangle(Globals.ms.TextureManager.AddTexture(User.GetAvatar(CancellationToken.None).Result, true)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29 * Globals.Settings.Scale))}); Rectangle rr; - Controls.Add(rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), + Controls.Add(rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Status.png"))) { Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], Location = new((int)(10 * Globals.Settings.Scale), (int)(10 * Globals.Settings.Scale)), Size = new ((int)(42 * Globals.Settings.Scale)) @@ -38,8 +38,8 @@ public class FriendRequest : UserControl t.Unit = TextureUnit.Texture1; rr.Textures.Add(t); rr.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; - Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.DisplayName, Location = new((int)(50 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); - Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.FriendStatus.ToString(), Location = new((int)(50 * Globals.Settings.Scale),(int)(32 * Globals.Settings.Scale))}); + Controls.Add(new Label(Globals.DefaultFont) { Text = User.DisplayName, Location = new((int)(50 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); + Controls.Add(new Label(Globals.DefaultFont) { Text = User.FriendStatus.ToString(), Location = new((int)(50 * Globals.Settings.Scale),(int)(32 * Globals.Settings.Scale))}); if (User.FriendStatus == FriendStatus.PendingIn) { Controls.Add(Accept = new Rectangle() diff --git a/Luski/GUI/MainScreen/UI/Group.cs b/Luski/GUI/MainScreen/UI/Group.cs index 45bd51b..580c94d 100644 --- a/Luski/GUI/MainScreen/UI/Group.cs +++ b/Luski/GUI/MainScreen/UI/Group.cs @@ -21,7 +21,7 @@ public class Group : UserControl, IChannelPick Channel = chan; Size = new((int)(240 * Globals.Settings.Scale), (int)(62* Globals.Settings.Scale)); BackgroundColor = new(34, 34, 34, 255); - Controls.Add(rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), + Controls.Add(rr=new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Status.png"))) { Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], Location = new((int)(10 * Globals.Settings.Scale), (int)(10 * Globals.Settings.Scale)), Size = new ((int)(42 * Globals.Settings.Scale)), @@ -34,13 +34,13 @@ public class Group : UserControl, IChannelPick r.Textures.Add(tex); r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; Controls.Add(r); - Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = chan.Title}); + Controls.Add(Username = new Label(Globals.DefaultFont) { Text = chan.Title}); string sl = "Online"; if (chan.Id != 0) { sl = chan.Members.Count + " Members"; } - Controls.Add(Status = new Label() { Scale = 0.7f, Font = Globals.DefaultFont, Text = sl, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))}); + Controls.Add(Status = new Label(Globals.DefaultFont) { Scale = 0.7f, Text = sl, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))}); this.Clicked += AllOnClicked; Username.Location = new((int)(58 * Globals.Settings.Scale), (rr.Location.Y + (rr.Size.Y / 2) - ((Username.TrueHeight + 5 + Status.TrueHeight) / 2) - @@ -50,10 +50,10 @@ public class Group : UserControl, IChannelPick if (chan.Id == 0) return; ContextMenu = new((int)(150 * Globals.Settings.Scale)); RoundedButton rrr; - ContextMenu.Items.Add(rrr=new() + ContextMenu.Items.Add(rrr=new(Globals.DefaultFont) { InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, - Size = new((int)(25 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Export Keys" + Size = new((int)(25 * Globals.Settings.Scale)), Text = "Export Keys" }); rrr.Clicked += RrOnClicked; } diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Category.cs b/Luski/GUI/MainScreen/UI/PublicServers/Category.cs new file mode 100644 index 0000000..6d00d57 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/Category.cs @@ -0,0 +1,203 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using Luski.GUI.MainScreen.Interfaces; +using Luski.net.Structures.Public; +using OpenTK.Windowing.Common.Input; + +namespace Luski.GUI.MainScreen.UI.PublicServers; + +public class Category : UserControl, IChannelAdder +{ + public FlowLayout Members; + public SocketCategory CurrentCategory { get; set; } + private List cc = new(); + private List cl = new(); + private Label ee; + private ChannelSelector CS; + + public event Func? AddY; + + private Label Name; + public UserControl tmp; + + public static Task MakeCat(SocketCategory cat, ChannelSelector cs) + { + Category c = new(); + c.CurrentCategory = cat; + c.CS = cs; + c.Anchor = ObjectAnchor.All; + c.Size = new((int)(307 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + c.tmp = new() + { + Size = c.Size, + Anchor = ObjectAnchor.Top | ObjectAnchor.Left + }; + c.tmp.Clicked += c.TmpOnClicked; + c.tmp.HoverMouse = MouseCursor.Hand; + c.Controls.Add(c.tmp); + c.tmp.Controls.Add(c.ee = new(Globals.DefaultFont) + { + Text = ">", + Location = new((int)(5*Globals.Settings.Scale)), + Color = cat.Color.ToColor4(), + DIR = new(1,0) + }); + c.tmp.Controls.Add(c.Name = new Label(Globals.DefaultFont) + { + Text = cat.Name, + Color = c.ee.Color + + }); + c.Clicked += c.AllOnClicked; + c.Name.Location = new((int)(26 * Globals.Settings.Scale), ((c.Size.Y/2) - (c.Name.TrueHeight/ 2) - (c.Name.Size.Y - c.Name.TrueHeight))); + c.Members = new() + { + Anchor = ObjectAnchor.All, + Location = new((int)(20 * Globals.Settings.Scale), c.Size.Y) + }; + c.ee.Location = new(c.ee.Location.X, c.Name.Location.Y); + c.Members.Size = new(c.Size.X - c.Members.Location.X, 0); + c.Controls.Add(c.Members); + c.Members.ForceDistanceUpdate(c); + c.tmp.HoverMouse = MouseCursor.Hand; + return Task.FromResult(c); + } + + private Category() + { + } + private async Task TmpOnClicked(IRenderObject arg) + { + BlockDraw = true; + if (!Extended) + { + DateTime dt = DateTime.UtcNow; + SocketChannel[] Channels = await CurrentCategory.GetChannels(); + Console.WriteLine(DateTime.UtcNow - dt); + foreach (SocketChannel v in Channels) + { + Channel c = await AddChannel(v); + c.LoadToParent(Members, Window!); + _ = CatOnAddY(c.Size.Y); + } + Console.WriteLine(DateTime.UtcNow - dt); + + SocketCategory[] cats = await CurrentCategory.GetCategories(); + Console.WriteLine(DateTime.UtcNow - dt); + foreach (SocketCategory v in cats) + { + var c = await AddCategory(v, dt); + c.LoadToParent(Members, Window!); + _ = CatOnAddY(c.Size.Y); + } + Console.WriteLine(DateTime.UtcNow - dt); + } + else + { + if (AddY is not null) await AddY.Invoke(-Members.Size.Y); + this.Size = new(this.Size.X, this.Size.Y -Members.Size.Y); + Members.Size = new(Members.Size.X, 0); + //Members.Controls.Clear(false); + } + + BlockDraw = false; + + Extended = !Extended; + + Window!.ForceUpdate(new(Window.Size)); + } + + private bool e; + public bool Extended + { + get => e; + set + { + if (value) + { + ee.DIR = new(0,1); + ee.Location = new(ee.Location.X, (ee.Location.Y - ee.PostiveTrueHeight)); + } + else + { + ee.DIR = new(1,0); + ee.Location = new(ee.Location.X, (ee.Location.Y + ee.PostiveTrueHeight)); + } + e = value; + } + } + + private Task AllOnClicked(IRenderObject arg) + { + if (ClickCon is not null) _ = ClickCon.Invoke(this); + return Task.CompletedTask; + } + + public event Func? ClickCon; + + public async Task AddCategory(SocketCategory Cat, DateTime? dt = null) + { + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + Category[] tc = cc.Where(s => s.CurrentCategory.ID == Cat.ID).ToArray(); + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + if (tc.Length > 0) + { + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + var cat2 = tc[0]; + if (!Members.Controls.Contains(cat2)) + { + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + Members.Controls.Add(cat2); + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + //Size = new(Size.X, Size.Y + cat2.Size.Y); + _ = CatOnAddY(cat2.Size.Y); + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + if (AddY is not null) _ = AddY.Invoke(cat2.Size.Y); + if (dt is not null) Console.WriteLine("c: {0}",DateTime.UtcNow - dt); + } + + return cat2; + } + var cat = await Category.MakeCat(Cat, CS); + cc.Add(cat); + Members.Controls.Add(cat); + cat.Size = new(this.Size.X, cat.Size.Y); + cat.Members.BackgroundColor = BackgroundColor; + cat.BackgroundColor = BackgroundColor; + cat.tmp.BackgroundColor = BackgroundColor; + Size = new(Size.X, Size.Y + cat.Size.Y); + cat.AddY += CatOnAddY; + if (AddY is not null) await AddY.Invoke(cat.Size.Y); + return cat; + } + + private async Task CatOnAddY(int arg) + { + this.Size = new(Size.X, Size.Y + arg); + } + + public async Task AddChannel(SocketChannel chan) + { + Channel[] tc = cl.Where(s => s.CurrentChannel.ID == chan.ID).ToArray(); + if (tc.Length > 0) + { + Channel cat2 = tc[0]; + if (!Members.Controls.Contains(cat2)) + { + Members.Controls.Add(cat2); + Size = new(Size.X, Size.Y + cat2.Size.Y); + if (AddY is not null) _ = AddY.Invoke(cat2.Size.Y); + } + + return cat2; + } + Channel cat = await Channel.MakeChannel(chan, CS); + cl.Add(cat); + cat.BackgroundColor = BackgroundColor; + Size = new(Size.X, Size.Y + cat.Size.Y); + Members.Controls.Add(cat); + if (AddY is not null) await AddY.Invoke(cat.Size.Y); + return cat; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs b/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs new file mode 100644 index 0000000..b1944ad --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/Channel.cs @@ -0,0 +1,183 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using Luski.net.Structures.Public; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; +using OpenTK.Windowing.Common.Input; + +namespace Luski.GUI.MainScreen.UI.PublicServers; + +public class Channel : UserControl +{ + private Rectangle SelectedRct, SelectedRctL, SelectedRctR; + private ChannelSelector CS; + public readonly static Texture[] SelectedTextures = new Texture[] {null!, null!, null!}; + + public SocketChannel CurrentChannel { get; set; } + public new Color4 BackgroundColor + { + get => base.BackgroundColor; + set + { + if (!Selected) + { + SelectedRct.BackgroundColor = value; + SelectedRctL.BackgroundColor = value; + SelectedRctR.BackgroundColor = value; + } + base.BackgroundColor = value; + } + } + + private Channel(Stream UserIcon, ChannelSelector cs, SocketChannel chan) + { + CS = cs; + CurrentChannel = chan; + Size = new((int)(307 * Globals.Settings.Scale), (int)(40* Globals.Settings.Scale)); + #region Selected Texture + SelectedRct = new(SelectedTextures[1]) + { + Location = new(Size.Y, 0), + Size = new(Size.X - (Size.Y * 2), Size.Y), + Anchor = ObjectAnchor.All, + BackgroundColor = BackgroundColor, + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], + Visible = true + }; + Controls.Add(SelectedRct); + SelectedRctL = new(SelectedTextures[0]) + { + Location = new(0), + Size = new(Size.Y), + Anchor = ObjectAnchor.Left, + BackgroundColor = SelectedRct.BackgroundColor, + Shader = SelectedRct.Shader, + Visible = true + }; + Controls.Add(SelectedRctL); + SelectedRctR = new(SelectedTextures[2]) + { + Location = new(Size.X - Size.Y, 0), + Size = SelectedRctL.Size, + Anchor = ObjectAnchor.Right, + BackgroundColor = SelectedRct.BackgroundColor, + Shader = SelectedRct.Shader, + Visible = true + }; + Controls.Add(SelectedRctR); + #endregion + + r = new Rectangle(Globals.ms.TextureManager.GetAlphaCircle()) + { + Location = new((int)(4 * Globals.Settings.Scale)), + Size = new ((int)(32 * Globals.Settings.Scale)) + }; + Texture tex; + tex = Globals.ms.TextureManager.AddTexture(UserIcon); + GC.Collect(); + UserIcon.Dispose(); + tex.Unit = TextureUnit.Texture1; + r.Textures.Add(tex); + r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; + Controls.Add(r); + ChannelName = new Label(Globals.DefaultFont) + { + Text = chan.Name, + Color = chan.Color.ToColor4() + }; + Controls.Add(ChannelName); + Clicked += AllOnClicked; + ChannelName.Location = new((int)(40 * Globals.Settings.Scale), + (Size.Y / 2) - ((int)ChannelName.Font.PixelHeight) + (ChannelName.PostiveTrueHeight / 2) + ); + ContextMenu = new((int)(150 * Globals.Settings.Scale)); + RoundedButton ExportKeysButton, EdditChannelButton; + ContextMenu.Items.Add(ExportKeysButton=new(Globals.DefaultFont) + { + InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, + Size = new((int)(25 * Globals.Settings.Scale)), Text = "Export Keys" + }); + ContextMenu.Items.Add(EdditChannelButton=new(Globals.DefaultFont) + { + InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, + Size = new((int)(25 * Globals.Settings.Scale)), Text = "Edit Channel" + }); + EdditChannelButton.Clicked += EditChannelButtonOnClicked; + ExportKeysButton.Clicked += ExportKeysButtonOnClicked; + HoverMouse = MouseCursor.Hand; + } + + public bool Selected { get; private set; } + + public async Task ToggleSelected() + { + try + { + Color4 bc = new(141,151,165,51); + if (Selected) + { + bc = BackgroundColor; + } + + BlockDraw = true; + Selected = !Selected; + + if (CS.Selected is not null && CS.Selected != this) + { + await CS.Selected.ToggleSelected(); + } + + if (Selected) + { + CS.Selected = this; + IReadOnlyList m; + m = await CurrentChannel.GetMessages(CancellationToken.None, 200); + //m = Array.Empty(); + Globals.ms.pc.ClearChat(); + await Globals.ms.pc.LoadChannel(CurrentChannel); + _ = Globals.ms.pc.AddMessages(m); + if (m.Count > 0)Globals.ms.pc.MessageFlow.ScrollToBottom(); + } + SelectedRct.BackgroundColor = bc; + SelectedRctL.BackgroundColor = bc; + BlockDraw = false; + SelectedRctR.BackgroundColor = bc; + TryDraw(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + public Label ChannelName; + public Rectangle r; + + public static async Task MakeChannel(SocketChannel chan, ChannelSelector cs) + { + Channel c = new(await chan.GetPicture(CancellationToken.None), cs, chan); + return c; + } + + private Task EditChannelButtonOnClicked(IRenderObject arg) + { + arg.ContextMenu!.HideContext(Window!); + return Task.CompletedTask; + } + + private Task ExportKeysButtonOnClicked(IRenderObject arg) + { + //_ = CurrentChannel.SendKeysToUsers(CancellationToken.None); + ContextMenu!.HideContext(Window!); + return Task.CompletedTask; + } + + private async Task AllOnClicked(IRenderObject arg) + { + if (!Selected) await ToggleSelected(); + //if (ClickCon is not null) _ = ClickCon.Invoke(this); + } + + //public event Func? ClickCon; +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs new file mode 100644 index 0000000..b56481c --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChannelSelector.cs @@ -0,0 +1,104 @@ +using GraphicsManager.Objects; +using Luski.GUI.MainScreen.Interfaces; +using Luski.net.Structures.Public; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.PublicServers; + +public class ChannelSelector : FlowLayout, IChannelAdder +{ + public SocketCategory CurrentCategory { get; } + private readonly List cc = new(); + private readonly List LoadedChannels = new(); + public Channel? Selected; + + public ChannelSelector(SocketCategory Cat) + { + CurrentCategory = Cat; + } + + public async Task Load(SocketChannel currentchannel, List parents) + { + IChannelAdder b = this; + SocketChannel[] chanspp = await b.CurrentCategory.GetChannels(); + foreach (SocketChannel v in chanspp) + { + Channel f = await b.AddChannel(v); + if (v.ID == currentchannel.ID) + { + await f.ToggleSelected(); + } + } + SocketCategory[] cats = await b.CurrentCategory.GetCategories(); + foreach (SocketCategory v in cats) + { + await b.AddCategory(v); + Globals.ms.DrawFrame(); + } + foreach (SocketCategory par in parents) + { + b.Extended = true; + b = await b.AddCategory(par); + Globals.ms.DrawFrame(); + chanspp = await par.GetChannels(); + foreach (SocketChannel v in chanspp) + { + Channel f = await b.AddChannel(v); + if (v.ID == currentchannel.ID) + { + await f.ToggleSelected(); + } + } + cats = await par.GetCategories(); + foreach (SocketCategory v in cats) + { + await b.AddCategory(v); + Globals.ms.DrawFrame(); + } + } + } + + public async Task AddChannel(SocketChannel chan) + { + Channel[] tc = LoadedChannels.Where(s => s.CurrentChannel.ID == chan.ID).ToArray(); + if (tc.Length > 0) + { + Channel cat23 = tc[0]; + if (!Controls.Contains(cat23)) + { + Controls.Add(cat23); + } + + return cat23; + } + Channel cat2 = await Channel.MakeChannel(chan, this); + LoadedChannels.Add(cat2); + cat2.BackgroundColor = BackgroundColor; + Controls.Add(cat2); + return cat2; + } + + public bool Extended { get; set; } = true; + + public async Task AddCategory(SocketCategory Cat, DateTime? dt = null) + { + Category[] tc = cc.Where(s => s.CurrentCategory.ID == Cat.ID).ToArray(); + if (tc.Length > 0) + { + Category cat23 = tc[0]; + if (!Controls.Contains(cat23)) + { + Controls.Add(cat23); + } + + return cat23; + } + Category cat = await Category.MakeCat(Cat, this); + cc.Add(cat); + cat.BackgroundColor = BackgroundColor; + cat.tmp.BackgroundColor = BackgroundColor; + cat.Members.BackgroundColor = BackgroundColor; + Controls.Add(cat); + return cat; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs new file mode 100644 index 0000000..310f6e8 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -0,0 +1,224 @@ +using System.Diagnostics; +using System.Reflection; +using GraphicsManager; +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using Luski.net.Interfaces; +using Luski.net.Structures.Main; +using Luski.net.Structures.Public; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; +using OpenTK.Windowing.Common.Input; + +namespace Luski.GUI.MainScreen.UI.PublicServers; + +public class ChatMessage : UserControl +{ + //readonly int padding = 10; + private static Font TimeFont;// = Font.MakeFontFromSystem(13); + private SocketMessage Msg { get; } + private SocketChannel ch { get; } + + private IRenderObject LastObject; + private Label FirstL; + + private readonly double HorPadding = (12 * Globals.Settings.Scale), + VerticalPadding = (12 * Globals.Settings.Scale); + + private static Dictionary Menues = new(); + private static Dictionary> Messages = new(); + + public static async Task MakeChatMessage(SocketMessage message) + { + IUser auth = await message.GetAuthor(CancellationToken.None); + Role[] ra = await ((SocketUser)auth).GetRoles(); + Color c = ra[0].Color; + Color4 c4 = new(c.R, c.G, c.B, c.A); + return new ChatMessage(message, await message.GetParent(CancellationToken.None), auth, await auth.GetIcon(), c4); + } + + + private ChatMessage(SocketMessage message, SocketChannel chan, IUser Author, Texture UserIcon, Color4 UserNameColor) + { + Label label1; + Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale)); + ch = chan; + BackgroundColor = new(40, 40, 40, 255); + Msg = message; + Anchor = ObjectAnchor.Left | ObjectAnchor.Right; + + DateTime time = chan.Epoch.AddMilliseconds(Msg.ID >> 20).ToLocalTime(); + string timestr; + if (time.Date == DateTime.Now.ToLocalTime().Date) + { + timestr = $"Today at {time.ToShortTimeString()}"; + } + else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date) + { + timestr = $"Yesterday at {time.ToShortTimeString()}"; + } + else + { + timestr = $"{time:M/dd/yyyy h:mm tt}"; + } + + Rectangle r = new Rectangle(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(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)) }; + //UserIcon.Unit = TextureUnit.Texture1; + r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; + r.Textures.Add(UserIcon); + Controls.Add(r); + Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor, Text = Author.DisplayName }); + label1.Location = new( + (int)(54 * Globals.Settings.Scale), + (int)(r.Location.Y + (r.Size.Y / 2) - (label1.Font.CurrentFont.Fonts[0].Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight)); + LastObject = label1; + FirstL = label1; + Controls.Add(new Label(Globals.TopTimeFont) { Location = new(label1.Location.X + label1.Size.X + (int)(8 * Globals.Settings.Scale), (int)(label1.Location.Y + label1.Font.PixelHeight - Globals.TopTimeFont.PixelHeight)), Text = timestr}); + if (!string.IsNullOrWhiteSpace(Msg.Context)) + { + Label l; + Controls.Add(l = new Label(Globals.MessageFont) { Location = new(LastObject.Location.X, (int)(LastObject.Location.Y + (LastObject as Label)!.Size.Y + VerticalPadding)), Text = message.Context}); + LastObject = l; + } + + if (Msg.Files.Count > 0) + { + int row = 1; + int filesonrow = 0; + for (int i = 0; i < Msg.Files.Count; i++) + { + double lx = (HorPadding * filesonrow) + LastObject.Location.X + (333 * (filesonrow + 1)); + if (lx > Size.X) + { + row++; + filesonrow = 0; + lx = (HorPadding * filesonrow) + LastObject.Location.X + (333 * (filesonrow + 1)); + } + + filesonrow++; + IRenderObject cem = ContentEmbed.GetEmbed(this, Msg.Files[i], Msg.ChannelID).Result; + cem.Location = new((int)(lx - 333), (int)(LastObject.Location.Y + 2 + LastObject.Size.Y + (HorPadding * row) + (66 * (row - 1)))); + LastObject = cem; + //lo = cem.Location; + // si = cem.Size; + Controls.Add(cem); + } + } + + if (LastObject is Label ll) Size = new(Size.X, (int)(ll.Location.Y + ll.Size.Y + VerticalPadding)); + else Size = new(Size.X ,(int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); + } + + public async Task AddMessage(SocketMessage msg) + { + Label newLabel; + if (!string.IsNullOrWhiteSpace(msg.Context)) + { + newLabel = new(Globals.MessageFont) + { + Text = msg.Context, + Tag = msg + }; + if (LastObject is Label l) + { + newLabel.Location = new(FirstL.Location.X, (int)(l.Location.Y + l.Size.Y + VerticalPadding)); + } + else + { + newLabel.Location = new(FirstL.Location.X, Size.Y); + } + bool result = Uri.TryCreate(newLabel.Text, UriKind.Absolute, out Uri? uriResult) + && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); + if (result) + { + newLabel.HoverMouse = MouseCursor.Hand; + newLabel.Color = Color4.Aqua; + newLabel.Clicked += NewLabelOnClicked; + } + + newLabel.MouseEnter += NewLabel_MouseEnter; + newLabel.MouseLeave += NewLabel_MouseLeave; + Controls.Add(newLabel); + LastObject = newLabel; + } + + if (msg.Files.Count > 0) + { + int row = 1; + int filesonrow = 0; + for (int i = 0; i < msg.Files.Count; i++) + { + double lx = (HorPadding * filesonrow) + LastObject.Location.X + (333 * (filesonrow + 1)); + if (lx > Size.X) + { + row++; + filesonrow = 0; + lx = (HorPadding * filesonrow) + LastObject.Location.X + (333 * (filesonrow + 1)); + } + + filesonrow++; + IRenderObject cem = await ContentEmbed.GetEmbed(this, msg.Files[i], msg.ChannelID); + cem.Location = new((int)(lx - 333), (int)(LastObject.Location.Y + 2 + LastObject.Size.Y + (HorPadding * row) + (66 * (row - 1)))); + LastObject = cem; + Controls.Add(cem); + } + } + if (LastObject is Label ll) Size = new(Size.X, (int)(ll.Location.Y + ll.Size.Y + VerticalPadding)); + else Size = new(Size.X ,(int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); + } + + private Task NewLabelOnClicked(IRenderObject arg) + { + try + { + Label m = (arg as Label)!; + if (OperatingSystem.IsWindows()) + Process.Start(m.Text); + else if (OperatingSystem.IsLinux()) + if (m.Tag is string s) Process.Start("xdg-open",s); + else Process.Start("xdg-open", m.Text); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return Task.CompletedTask; + } + + readonly List