diff --git a/Luski/GUI/MainScreen.cs b/Luski/GUI/MainScreen.cs deleted file mode 100644 index 3dbe711..0000000 --- a/Luski/GUI/MainScreen.cs +++ /dev/null @@ -1,590 +0,0 @@ -using System.Diagnostics; -using System.Reflection; -using System.Runtime.InteropServices; -using GraphicsManager; -using GraphicsManager.Enums; -using GraphicsManager.Interfaces; -using GraphicsManager.Objects; -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; -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; -using OpenTK.Windowing.Common; -using Window = GraphicsManager.Window; - -namespace Luski.GUI.MainScreen; - -public class MainScreen : Window -{ - private static readonly NativeWindowSettings Settings = new() - { - Title = "Luski Login", - WindowBorder = WindowBorder.Fixed, - APIVersion = new Version(3, 2), - API = ContextAPI.OpenGL, - StartFocused = true, - Size = new Vector2i((int)(312 * Globals.Settings.Scale), (int)(545 * Globals.Settings.Scale)), - Icon = Globals.Icon, - SharedContext = null, - }; - - public TabControl? tc; - private FlowLayout? channelpicker, friends, friend_request; - private RoundedButton? FriendManagerBtn; - public Chat? chat; - Login login; - CreateAccount ca; - private static DebugProc DebugMessageDelegate = OnDebugMessage; - private static void OnDebugMessage( - DebugSource source, // Source of the debugging message. - DebugType type, // Type of the debugging message. - int id, // ID associated with the message. - DebugSeverity severity, // Severity of the message. - int length, // Length of the string in pMessage. - IntPtr pMessage, // Pointer to message string. - IntPtr pUserParam) // The pointer you gave to OpenGL, explained later. - { - // In order to access the string pointed to by pMessage, you can use Marshal - // class to copy its contents to a C# string without unsafe code. You can - // also use the new function Marshal.PtrToStringUTF8 since .NET Core 1.1. - string message = Marshal.PtrToStringAnsi(pMessage, length); - - // The rest of the function is up to you to implement, however a debug output - // is always useful. - - if (false) - { - 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.DefaultFontFamly = FontFamily.LoadFontFamily("Noto Sans").Result; - Globals.DefaultFont = FontInteraction.Load(Globals.DefaultFontFamly); - Globals.DefaultFont.PixelHeight = (uint)(20 * Globals.Settings.Scale); - 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); - if ((Globals.Luski.MainServer is not null && !Globals.Luski.MainServer.IsLogedIn) || !Globals.Luski.LoadedServers.Any(s => s.IsLogedIn)) - { - 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(); - - } - WindowLoaded += OnWindowLoaded; - } - - private Task OnWindowLoaded(Window arg) - { - if (Globals.UpdaterSettings.AutoUpdateCheck && new HttpClient().GetAsync($"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch={Globals.UpdaterSettings.Branch.ToString()}&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}").Result.Content.ReadAsStringAsync().Result != FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion) - { - var update = new UpdateWindow(); - var result = update.ShowDialogue(this); - if (result == UpdateWindow.DialogueResult.Yes) - { - Globals.Download = true; - Close(); - } - } - - if ((Globals.Luski.MainServer is not null && Globals.Luski.MainServer.IsLogedIn) || Globals.Luski.LoadedServers.Any(s => s.IsLogedIn)) Invoke(() => LoginOnChangeToApp()); - - return Task.CompletedTask; - } - - private Task LoginOnChangeToCa() - { - Title = "Create Account"; - ca.Visible = true; - login.Visible = false; - return Task.CompletedTask; - } - - public void AddGroup(MainSocketGroupChannel group) - { - Group friend = new(group); - friend.ClickCon += ChannelOnClickCon; - channelpicker!.Controls.Add(friend); - chans.Add(friend); - } - - private readonly List fr = new(); - private List chans = new(); - private Dictionary FR_Index = new(); - - public void AddFriendRequest(MainSocketRemoteUser user) - { - FriendRequest frui = new(this, user); - FR_Index.Add(user.Id, friend_request!.Controls.Length); - friend_request.Controls.Add(frui); - } - - public void RemoveFriendRequest(MainSocketRemoteUser user) - { - if (!FR_Index.ContainsKey(user.Id)) return; - friend_request!.Controls.Remove(friend_request!.Controls[FR_Index[user.Id]]); - } - - public void AddFriend(MainSocketRemoteUser user) - { - Friend friend2 = new(user); - friend2.ClickCon += ChannelOnClickCon; - friends!.Controls.Add(friend2); - if (user.Channel is not null) - { - Friend friend = new(user); - friend.ClickCon += ChannelOnClickCon; - fr.Add(friend); - channelpicker!.Controls.Add(friend); - chans.Add(friend); - } - } - - private CancellationTokenSource? channelCancellationToken = null; - private Task ChannelOnClickCon(IChannelPick arg) - { - try - { - BlockDraw = true; - Thread t = new(a => cc(a!)); - t.Start(arg); - } - catch (Exception e) - { - Console.WriteLine(e); - } - - return Task.CompletedTask; - } - - private void cc(object argg) - { - try - { - IChannelPick arg = (IChannelPick)argg; - Invoke(new Action(() => - { - chat!.UpdateTitle(arg); - })); - if (channelCancellationToken is not null) - { - channelCancellationToken.Cancel(false); - } - channelCancellationToken = new CancellationTokenSource(); - //Globals.Luski.ChangeChannel(arg.Channel.Id, channelCancellationToken.Token).Wait(); - Invoke(new Action(() => - { - chat!.Clear(); - })); - IReadOnlyList messages = arg.Channel.GetMessages(channelCancellationToken.Token, Globals.Settings.LoadPerChannel).Result; - - foreach (MainSocketMessage message in messages.Reverse()) - { - if (channelCancellationToken is null || channelCancellationToken.Token.IsCancellationRequested) return; - Invoke(new Action(() => - { - chat!.AddMessage(TextureManager, message); - })); - } - if (channelCancellationToken is null || channelCancellationToken.Token.IsCancellationRequested) return; - channelCancellationToken = null; - Invoke(new Action(() => - { - BlockDraw = false; - chat!.MessageFlow.ScrollToBottom(); - DrawFrame(); - })); - } - catch (Exception e) - { - if (e.Message.Contains("A task was canceled")) return; - 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 = new(20,20,20,255) - }; - Controls.Add(SerBox); - SerBox.LoadToParent(this, this); - } - - SerBox.Controls.Clear(); - #endregion - - #region Channel Selector Init - SocketChannel current_channel = await Server.User.GetSelectedChannel(CancellationToken.None); - 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")); - List parents = new(); - SocketCategory? cur = await current_channel.GetParent(); - while (cur is not null) - { - parents.Add(cur); - cur = await cur.GetParent(); - } - - parents.Reverse(); - ChannelSelector cs = new(parents[0]) - { - BackgroundColor = new(34, 34, 34, 255), - Size = new((int)(307 * Globals.Settings.Scale), SerBox.Size.Y - 106), - Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom - }; - parents.RemoveAt(0); - SerBox.Controls.Add(cs); - cs.ForceDistanceUpdate(SerBox); - - #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(current_channel, 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"; - 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(ser = new FlowLayout() - { - BackgroundColor = new(26, 26, 26, 255), - Size = new((int)(68 * Globals.Settings.Scale), (int)(868 * Globals.Settings.Scale)), - Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Bottom, - - }); - // PublicServer? SelectedPublicServer; - DrawFrame(); - if (Globals.Luski.MainServer is not null) - { - Texture uut = - TextureManager.AddTexture(Globals.Luski.MainServer.User.GetAvatar(CancellationToken.None).Result); - uut.Unit = TextureUnit.Texture1; - - Label ul = new Label(Globals.DefaultFont) - { - 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); - } - - 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"); - } - - foreach (PublicServer pser in Globals.Luski.LoadedServers) - { - ser.Controls.Add(new ServerIcon(pser)); - } - - await (ser.Controls[0] as ServerIcon)!.LoadServer(); - - MainShow += OnMainShow; - return Task.CompletedTask; - } - - private Task OnMainShow() - { - 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; - } - - public event Func? MainShow; - - private Task LuskiOnOnError(Exception arg) - { - Console.WriteLine(arg); - return Task.CompletedTask; - } - - private Task LuskiOnFriendRequestResult(MainSocketRemoteUser arg1, bool arg2) - { - Console.WriteLine("new result"); - Invoke(new Action(() => - { - RemoveFriendRequest(arg1); - if (arg2) AddFriend(arg1); - })); - return Task.CompletedTask; - } - - private Task LuskiOnReceivedFriendRequest(MainSocketRemoteUser arg) - { - Invoke(new Action(() => - { - AddFriendRequest(arg); - })); - return Task.CompletedTask; - } - - private Task LuskiOnUserStatusUpdate(IUser before, IUser After) - { - Console.WriteLine(before); - Console.WriteLine(After); - if (before is not MainSocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends || Before.Id == 0) return Task.CompletedTask; - 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; - } - - private Task FriendManagerBtnOnClicked(IRenderObject arg) - { - if (chat!.Visible) - { - chat.Visible = false; - tc!.Visible = true; - } - else - { - chat.Visible = true; - tc!.Visible = false; - } - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddFriendPage.cs b/Luski/GUI/MainScreen/UI/AddFriendPage.cs deleted file mode 100644 index 765078b..0000000 --- a/Luski/GUI/MainScreen/UI/AddFriendPage.cs +++ /dev/null @@ -1,45 +0,0 @@ -using GraphicsManager.Enums; -using GraphicsManager.Objects; -using Luski.net.Structures.Main; -using OpenTK.Mathematics; -using OpenTK.Windowing.Common; -using OpenTK.Windowing.GraphicsLibraryFramework; - -namespace Luski.GUI.MainScreen.UI; - -public class AddFriendPage : FlowLayout -{ - private MainScreen Screen; - private Textbox Input; - - public AddFriendPage(MainScreen Parent) - { - this.Screen = Parent; - Size = new((int)(200 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)); - BackgroundColor = new(45,45,45,255); - 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; - } - - private Task InputOnKeyPress(KeyboardKeyEventArgs arg) - { - - if (Input.BorderColor == Color4.Red) Input.BorderColor = Color4.DarkCyan; - if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter) return Task.CompletedTask; - if (!long.TryParse(Input.Text, out long code)) - { - Input.BorderColor = Color4.Red; - return Task.CompletedTask; - } - // MainSocketRemoteUser? result = Globals.Luski.MainServer.SendFriendRequest(code, CancellationToken.None).Result; - //if (result is null) Input.BorderColor = Color4.Red; - // else - // { - // if (result.Channel is null) - // Screen.AddFriendRequest(result); - // else - // Screen.AddFriend(result); - //} - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddServerIcon.cs b/Luski/GUI/MainScreen/UI/AddServerIcon.cs new file mode 100644 index 0000000..2e1d384 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/AddServerIcon.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using GraphicsManager; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using Luski.net; +using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI; + +public class AddServerIcon : UserControl +{ + public Rectangle Button; + public AddServerIcon() + { + Button = new(Globals.ms.TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), + "Luski.Resources.Textures.add.png"))) + { + Location = new((int)(18 * Globals.Settings.Scale), (int)(8 * Globals.Settings.Scale), 0), + Size = new((int)(32 * Globals.Settings.Scale)), + Shader = Rectangle.DefaultAlphaShader[Globals.ms.Context], + BackgroundColor = Color4.White + }; + Controls.Add(Button); + BackgroundColor = new(26, 26, 26, 255); + base.Size = new((int)(68 * Globals.Settings.Scale), (int)(48 * Globals.Settings.Scale)); + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddServerOverlay.cs b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs new file mode 100644 index 0000000..667ee44 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/AddServerOverlay.cs @@ -0,0 +1,15 @@ +using GraphicsManager.Enums; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; + +namespace Luski.GUI.MainScreen.UI; + +public class AddServerOverlay : UserControl +{ + public AddServerOverlay() + { + base.Size = Globals.ms.Size; + BackgroundColor = new(0, 0, 0, 130); + Anchor = ObjectAnchor.All; + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/Chat.cs b/Luski/GUI/MainScreen/UI/Chat.cs deleted file mode 100644 index 342700c..0000000 --- a/Luski/GUI/MainScreen/UI/Chat.cs +++ /dev/null @@ -1,147 +0,0 @@ -using GraphicsManager.Enums; -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.Enums.Main; -using Luski.net.JsonTypes; -using Luski.net.Structures.Main; -using OpenTK.Mathematics; -using OpenTK.Windowing.Common; -using OpenTK.Windowing.GraphicsLibraryFramework; - -namespace Luski.GUI.MainScreen.UI; - -public class Chat : UserControl -{ - public FlowLayout MessageFlow; - private Label title, desc; - private Textbox tb; - private MainSocketTextChannel? Channel; - public Chat() - { - 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(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)(980 * Globals.Settings.Scale), (int)(52 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor}); - titlecon.Controls.Add(title = new Label(Globals.DefaultFont) - { - //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(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) - { - InsideColor = new(28, 28, 28, 255), - BorderColor = Color4.DarkCyan, - 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.Bottom | ObjectAnchor.Left | ObjectAnchor.Right - }); - tb.KeyPress += TbOnKeyPress; - Globals.Luski.MainServer.MessageReceived += LuskiOnMessageReceived; - } - - 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.MainServer.SendMessage(tb.Text, Channel!.Id, CancellationToken.None); - Window!.Invoke(() => { tb.Text = string.Empty; }); - } - - private Task LuskiOnMessageReceived(MainSocketMessage arg) - { - if (Channel!.Id != arg.ChannelID) return Task.CompletedTask; - 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(() => { MessageFlow.ScrollToBottom();}); - - return Task.CompletedTask; - } - - public void Clear() - { - MessageFlow.Controls.Clear(); - lastm = null; - lastUser = null; - } - - public void UpdateTitle(IChannelPick channelPick) - { - if (Channel is not null && Channel!.Id == channelPick.Channel.Id) return; - Channel = channelPick.Channel; - title.Text = channelPick.Channel.Title; - //tb.WatermarkFont = Globals.DefaultFont; - if (channelPick.Channel.Type == ChannelType.DM) - title.Text = (channelPick.Channel as MainSocketDMChannel)!.User.DisplayName; - tb.WatermarkText = "Message " + title.Text; - 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 MainSocketMessage? lastm; - private long? lastUser; - private ChatMessage? LastChatMessage; - - public void AddMessage(TextureManager m, MainSocketMessage 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 || !Globals.ms.InvokeRequired) - { - MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m, Message)); - } - else - Globals.ms.Invoke(() => - { - MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m, Message)); - Window.DrawFrame(); - }); - } - else - { - if (Window is null || !Globals.ms.InvokeRequired) - { - LastChatMessage!.AddMessage(Message); - } - else - Globals.ms.Invoke(() => { LastChatMessage!.AddMessage(Message); Window!.DrawFrame(); }); - } - - lastUser = Message.AuthorID; - } -} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/ChatMessage.cs b/Luski/GUI/MainScreen/UI/ChatMessage.cs deleted file mode 100644 index 89fe564..0000000 --- a/Luski/GUI/MainScreen/UI/ChatMessage.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System.Reflection; -using GraphicsManager; -using GraphicsManager.Enums; -using GraphicsManager.Interfaces; -using GraphicsManager.Objects; -using GraphicsManager.Objects.Core; -using Luski.net; -using Luski.net.Enums; -using Luski.net.Enums.Main; -using Luski.net.Interfaces; -using Luski.net.JsonTypes; -using Luski.net.Structures.Main; -using OpenTK.Graphics.OpenGL4; -using OpenTK.Mathematics; - -namespace Luski.GUI.MainScreen.UI; - -public class ChatMessage : UserControl -{ - readonly int padding = 2; - private static Font TimeFont;// = Font.MakeFontFromSystem(13); - private MainSocketMessage Msg { get; } - private Label label2, lastm; - private static Dictionary Menues = new(); - private static Dictionary> Messages = new(); - - public ChatMessage(TextureManager tm, MainSocketMessage message) - { - Label label1; - Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale)); - - BackgroundColor = new(40, 40, 40, 255); - Msg = message; - IUser user = message.GetAuthor(CancellationToken.None).Result; - Anchor = ObjectAnchor.Left | ObjectAnchor.Right; - - Controls.Add(label1 = new Label(Globals.DefaultFont) { Location = new((int)(54 * Globals.Settings.Scale), (int)(6 * Globals.Settings.Scale)), Text = user.DisplayName}); - - - - DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Msg.Id >> 22).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}"; - } - 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(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) - { - 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))) - }); - } - } - - if (user is MainSocketRemoteUser u && u.FriendStatus == FriendStatus.NotFriends) - { - Tag = u; - if (!Menues.ContainsKey(u)) - { - ContextMenu m = new((int)(150 * Globals.Settings.Scale)); - RoundedButton d; - m.Items.Add(d = new RoundedButton(Globals.DefaultFont) - { - InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, - Size = new((int)(25 * Globals.Settings.Scale)), Text = "Add Friend" - }); - d.Tag = this; - Menues.Add(u,m); - Messages.Add(u, new()); - d.Clicked += DOnClicked; - } - Messages[u].Add(this); - this.ContextMenu = Menues[u]; - } - Size = new(Size.X, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + padding + 10); - } - - private Task DOnClicked(IRenderObject arg) - { - if (arg.Tag is ChatMessage u && u.Tag is MainSocketRemoteUser uu) - { - foreach (ChatMessage cm in Messages[uu]) - { - cm.ContextMenu!.IsVisible = false; - cm.ContextMenu!.Close(); - cm.ContextMenu = null; - } - - Messages.Remove(uu); - Menues.Remove(uu); - // MainSocketRemoteUser result = Globals.Luski.MainServer - // .SendFriendRequest(long.Parse(uu.friend_codes.First()), CancellationToken.None).Result; - // if (result.Channel is null) - // Globals.ms.AddFriendRequest(result); - // else - // Globals.ms.AddFriend(result); - } - - return Task.CompletedTask; - } - - public void AddMessage(MainSocketMessage msg) - { - Label newLabel = new(Globals.DefaultFont) - { - Text = msg.Context, - Tag = msg, - Location = new(label2.Location.X, Size.Y) - }; - - newLabel.MouseEnter += NewLabel_MouseEnter; - newLabel.MouseLeave += NewLabel_MouseLeave; - Controls.Add(newLabel); - 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++) - { - 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