From cf238410d2fcb21b6ffc1dbc72d7f087344f4b51 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Sun, 24 Nov 2024 17:04:24 -0500 Subject: [PATCH] Pre GM clean --- Luski/Classes/Settings.cs | 8 ++ .../UI/LuskiControls/CompressedFlow.cs | 24 ++++- .../UI/LuskiControls/MessageCompressedFlow.cs | 90 +++++++++++++++++++ .../UI/PublicServers/ChatMessage.cs | 70 ++++++++------- .../UI/PublicServers/ContentEmbed.cs | 6 +- .../MainScreen/UI/PublicServers/PublicChat.cs | 23 ++++- Luski/GUI/MainScreenWindow.cs | 34 +++---- Luski/Luski.csproj | 4 +- Luski/Program.cs | 16 ++-- 9 files changed, 214 insertions(+), 61 deletions(-) create mode 100644 Luski/GUI/MainScreen/UI/LuskiControls/MessageCompressedFlow.cs diff --git a/Luski/Classes/Settings.cs b/Luski/Classes/Settings.cs index 726cdea..8982a29 100644 --- a/Luski/Classes/Settings.cs +++ b/Luski/Classes/Settings.cs @@ -5,6 +5,8 @@ using Luski.Classes.Attribs; using Luski.Classes.Attribs.NumberSlider; using Luski.Enums; using Luski.Enums.Strings; +using Luski.GUI; +using OpenTK.Windowing.GraphicsLibraryFramework; namespace Luski.Classes; @@ -60,6 +62,12 @@ public class Settings { Globals.ms.LogFrames = (_Logs & ConsoleLog.DrawFrames) == ConsoleLog.DrawFrames; Globals.ms.ShowMissingChar = (_Logs & ConsoleLog.ShowMissingChar) == ConsoleLog.ShowMissingChar; + if ((Globals.Settings.Logs & ConsoleLog.ShowErrorsForGLFW) == ConsoleLog.ShowErrorsForGLFW) + GLFW.SetErrorCallback(MainScreenWindow.OnGLFW_Error); + else + { + GLFW.SetErrorCallback(null); + } } } } diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs b/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs index e29f039..c8a588a 100644 --- a/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs +++ b/Luski/GUI/MainScreen/UI/LuskiControls/CompressedFlow.cs @@ -1,5 +1,7 @@ using GraphicsManager.Interfaces; using GraphicsManager.Objects; +using Luski.GUI.MainScreen.UI.PublicServers; +using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; namespace Luski.GUI.MainScreen.UI.LuskiControls; @@ -52,6 +54,8 @@ public class CompressedFlow : UserControl UpdateControlesFromIndex(arg1); return Task.CompletedTask; } + + private void UpdateControlesFromIndex(int index) { @@ -62,26 +66,40 @@ public class CompressedFlow : UserControl if (SizeUpdateNotIgnored is not null) _ = SizeUpdateNotIgnored.Invoke(this); return; } + int lasty = -1; + int rowheight = -1; + for (int i = 0; i <= Math.Min(index-1, Controls.Length-1); i++) + { + if (Controls[i].Location.Y > lasty) + { + lasty = Controls[i].Location.Y; + rowheight = 0; + } + if (Controls[i].Size.Y > rowheight) rowheight = Controls[i].Size.Y; + } if (index == 0) index++; for (int i = index; i < Controls.Length; i++) { if (Controls[i-1].Location.X + Controls[i-1].Size.X + Padding.Z + Controls[i].Size.X + ChildPadding.X > Size.X) { Controls[i].Location = new(Padding.X, - Controls[i - 1].Location.Y + Controls[i - 1].Size.Y + ChildPadding.Y); + lasty + rowheight + ChildPadding.Y); + lasty = Controls[i].Location.Y; + rowheight = Controls[i].Size.Y; } else { Controls[i].Location = new(ChildPadding.X + Controls[i - 1].Location.X + Controls[i - 1].Size.X, Controls[i - 1].Location.Y); + if (Controls[i].Size.Y > rowheight) rowheight = Controls[i].Size.Y; } } - if (Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + Padding.W != Size.Y) + if (lasty + rowheight + Padding.W != Size.Y) { IgnoreNextSizeChange = true; Size = new(Size.X, - Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + Padding.W); + lasty + rowheight + Padding.W); if (SizeUpdateNotIgnored is not null) _ = SizeUpdateNotIgnored.Invoke(this); } } diff --git a/Luski/GUI/MainScreen/UI/LuskiControls/MessageCompressedFlow.cs b/Luski/GUI/MainScreen/UI/LuskiControls/MessageCompressedFlow.cs new file mode 100644 index 0000000..ad05285 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/LuskiControls/MessageCompressedFlow.cs @@ -0,0 +1,90 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using OpenTK.Mathematics; + +namespace Luski.GUI.MainScreen.UI.LuskiControls; + +public class MessageCompressedFlow : UserControl +{ + public MessageCompressedFlow() + { + Controls.ControlAfterAdded += ControlsOnControlAdded; + Controls.ControlRemoved += ControlsOnControlRemoved; + SizeChanged += OnSizeChanged; + WallSpacing = new(5.ScaleInt()); + } + + public Vector4i WallSpacing { get; set; } + + public event Func? SizeUpdateNotIgnored; + + private bool IgnoreNextSizeChange; + + private Task OnSizeChanged(IRenderObject arg) + { + if (IgnoreNextSizeChange) + { + IgnoreNextSizeChange = false; + return Task.CompletedTask; + } + UpdateControlesFromIndex(0); + return Task.CompletedTask; + } + + private Task ControlsOnControlRemoved() + { + UpdateControlesFromIndex(0); + return Task.CompletedTask; + } + + private Task ControlsOnControlAdded(int arg1, IRenderObject arg2) + { + if (arg1 != 0) + { + arg2.Margins = new(0, 3.ScaleInt(), 0, 0); + arg2.Location = new(WallSpacing.X + arg2.Margins.X, Controls[arg1-1].Location.X + Controls[arg1-1].Size.Y + Controls[arg1-1].Margins.W + arg2.Margins.Y); + } + else + { + arg2.Location = new(WallSpacing.X + arg2.Margins.X, WallSpacing.Y + arg2.Margins.Y); + } + + if (arg2 is CompressedFlow c) + { + c.Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right; + c.SizeUpdateNotIgnored += o => + { + UpdateControlesFromIndex(arg1 + 1); + return Task.CompletedTask; + }; + } + UpdateControlesFromIndex(arg1); + return Task.CompletedTask; + } + + private void UpdateControlesFromIndex(int index) + { + if (Controls.Length == 0) + { + IgnoreNextSizeChange = true; + Size = new(Size.X, 0); + if (SizeUpdateNotIgnored is not null) _ = SizeUpdateNotIgnored.Invoke(this); + return; + } + if (index == 0) index++; + for (int i = index; i < Controls.Length; i++) + { + Controls[i].Location = new(WallSpacing.X + Controls[i].Margins.X, + Controls[i - 1].Location.Y + Controls[i - 1].Size.Y + Controls[i - 1].Margins.W + Controls[i].Margins.Y); + } + + if (Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + Controls[Controls.Length - 1].Margins.Z + WallSpacing.W != Size.Y) + { + IgnoreNextSizeChange = true; + Size = new(Size.X, + Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + Controls[Controls.Length - 1].Margins.Z + WallSpacing.W); + if (SizeUpdateNotIgnored is not null) _ = SizeUpdateNotIgnored.Invoke(this); + } + } +} \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs index d7eaad7..5e28220 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -24,6 +24,7 @@ public class ChatMessage : UserControl private IRenderObject LastObject; public List MessageObjs = new(); private LabelBase FirstL; + public MessageCompressedFlow MCF; public readonly double HorPadding = 12.ScaleDouble(), VerticalPadding = 5.ScaleDouble(); @@ -41,6 +42,7 @@ public class ChatMessage : UserControl private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, ServerProfile Author, IRenderObject UserIcon, Role r) { + pc = p; LuskiLabel label1; base.SetSize(723.5.ScaleInt(), 37.ScaleInt()); @@ -102,10 +104,22 @@ public class ChatMessage : UserControl LastObject = label1; FirstL = label1; Controls.Add(label2 = new(Globals.TopTimeFont) { Location = new(label1.Location.X + label1.Size.X + 8.ScaleInt(), (int)(label1.Location.Y + label1.Font.PixelHeight - Globals.TopTimeFont.PixelHeight)), Text = time_str}); + + MCF = new() + { + Location = new(LastObject.Location.X, (int)(UserIcon.Location.Y + UserIcon.Size.Y - Globals.MessageFont.PixelHeight)), + BackgroundColor = new(0,0,0,0), + Size = new(base.Size.X - LastObject.Location.X - 5.ScaleInt(), 0), + Anchor = ObjectAnchor.Top | ObjectAnchor.Left | ObjectAnchor.Right, + }; + MCF.SizeUpdateNotIgnored += MCFOnSizeUpdateNotIgnored; + MCF.ForceDistanceUpdate(this); + Controls.Add(MCF); + if (!string.IsNullOrWhiteSpace(Msg.Context)) { LuskiLabel l; - Controls.Add(l = new(Globals.MessageFont) { Location = new(LastObject.Location.X, (int)(UserIcon.Location.Y + UserIcon.Size.Y - Globals.MessageFont.PixelHeight)), Text = message.Context}); + MCF.Controls.Add(l = new(Globals.MessageFont) { Location = new(LastObject.Location.X, (int)(UserIcon.Location.Y + UserIcon.Size.Y - Globals.MessageFont.PixelHeight)), Text = message.Context}); LastObject = l; LuskiContextMenu lcm = new(); Label llllll = lcm.AddLabel("Copy Text"); @@ -159,21 +173,31 @@ public class ChatMessage : UserControl if (Msg.Files.Count > 0) { + CompressedFlow cf = new() + { + Size = new(base.Size.X - FirstL.Location.X, 0), + Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top, + BackgroundColor = new(0,0,0,50) + }; for (int i = 0; i < Msg.Files.Count; i++) { var cem = ContentEmbed.GetEmbed(this, Msg.Files[i], Msg.ChannelID); cem.Wait(); - cem.Result.Location = new(FirstL.Location.X, - (int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); - LastObject = cem.Result; - Controls.Add(cem.Result); + cf.Controls.Add(cem.Result); } + MCF.Controls.Add(cf); } - if (LastObject is Label ll) base.Size = new(base.Size.X, (int)(ll.Location.Y + ll.Size.Y + VerticalPadding)); - else base.Size = new(base.Size.X ,(int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); + base.Size = new(base.Size.X , MCF.Size.Y + MCF.Location.Y); + base.BackgroundColor = new(0,0,0,50); } - + + private Task MCFOnSizeUpdateNotIgnored(IRenderObject arg) + { + base.Size = new(base.Size.X , MCF.Size.Y + MCF.Location.Y); + return Task.CompletedTask; + } + public async Task AddMessage(SocketMessage msg) { @@ -205,7 +229,7 @@ public class ChatMessage : UserControl newLabel.MouseEnter += NewLabel_MouseEnter; newLabel.MouseLeave += NewLabel_MouseLeave; - Controls.Add(newLabel); + MCF.Controls.Add(newLabel); MessageObjs.Add(newLabel); LastObject = newLabel; LuskiContextMenu lcm = new(); @@ -221,41 +245,25 @@ public class ChatMessage : UserControl newLabel.ContextMenu = lcm; } - if (msg.Files.Count > 0) { - /*CompressedFlow cf = new() + CompressedFlow cf = new() { Size = new(base.Size.X - FirstL.Location.X, 0), Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top, - Location = new(FirstL.Location.X, (int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)), - BackgroundColor = base.BackgroundColor + BackgroundColor = new(0,0,0,0) }; - Controls.Add(cf); - */ - - for (int i = 0; i < msg.Files.Count; i++) { IRenderObject cem = await ContentEmbed.GetEmbed(this, msg.Files[i], msg.ChannelID); - cem.Location = new(FirstL.Location.X, - (int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); - LastObject = cem; - Controls.Add(cem); + cf.Controls.Add(cem); } - - // LastObject = cf; + MCF.Controls.Add(cf); } - - 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)); - if (LastObject is CompressedFlow) - { - LastObject.ForceDistanceUpdate(this); - } + Size = new(Size.X , MCF.Size.Y + MCF.Location.Y); + BlockDraw = false; - //if (Parent is not null) Globals.ms.pc.MessageFlow.ReportSizeUpdate(this); TryDraw(); } diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs b/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs index 60bb9c1..b249b19 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ContentEmbed.cs @@ -27,13 +27,13 @@ public class ContentEmbed : UserControl Rectangle r; double s = 322.ScaleDouble(); double scale = s / t.RawSize!.Value.X; - m.Controls.Add(r = new Rectangle(t) + r = new Rectangle(t) { Size = new((int)s, (int)(scale * t.RawSize.Value.Y)), Shader = Texture.TextureShader[Globals.ms.Context], HoverMouse = MouseCursor.Hand, Tag = m.pc - }); + }; r.Clicked += ROnClicked; return r; } @@ -116,6 +116,8 @@ public class ContentEmbed : UserControl int temp2 = fileSizeLabel.Size.X + fileSizeLabel.Location.X; //if (temp >= temp2) Size = new(temp + 4, Size.Y); //else Size = new(temp2 + 4, Size.Y); + //base.BackgroundColor = new(0, 0, 0, 50); + base.BackgroundColor = new(0, 0, 0, 0); } private Task FileNameLabelOnClicked(IRenderObject arg) diff --git a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs index be59d91..7b52ab8 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs @@ -189,9 +189,22 @@ public class PublicChat : UserControl await fileUpload.StartUpload(); FilesList.Add(fileUpload.PublicSF!); } + + Task m = Channel!.SendMessage(tb.Text, Profile: Globals.ServerProfile, files: FilesList.ToArray()); + Task taskA = new Task( () => + { + Console.WriteLine("Hello from taskA."); + return ""; + }); + // Start the task. + taskA.Start(); + // Output a message from the calling thread. + Console.WriteLine("Hello from thread '{0}'.", + Thread.CurrentThread.Name); + taskA.Wait(); ClearFiles(); - await Channel!.SendMessage(tb.Text, Profile: Globals.ServerProfile, files: FilesList.ToArray()); + m.Wait(); tb.Text = string.Empty; tb.CursorLocation = 0; } @@ -221,6 +234,7 @@ public class PublicChat : UserControl private async Task UserConOnClicked(IRenderObject arg) { + BlockDraw = true; um_open = !um_open; if (um_open) { @@ -368,6 +382,9 @@ public class PublicChat : UserControl tb.Size = new(tb.Size.X + memberflow.Size.X, tb.Size.Y); tb.ForceDistanceUpdate(); } + + BlockDraw = false; + TryDraw(); } private SocketMessage? lastm; @@ -422,9 +439,13 @@ public class PublicChat : UserControl public void ClearFiles() { + DateTime dt = DateTime.Now; FilesToUpload.Clear(); + Console.WriteLine("Clear 1 " + (DateTime.Now - dt)); FileFlow.Controls.Clear(); + Console.WriteLine("Clear 2 " + (DateTime.Now - dt)); MessageFlow.Size = new(MessageFlow.Size.X, FileFlow.Location.Y - MessageFlow.Location.Y); + Console.WriteLine("Size in " + (DateTime.Now - dt)); } public void RemoveFile(FileUpload FU) diff --git a/Luski/GUI/MainScreenWindow.cs b/Luski/GUI/MainScreenWindow.cs index 03f5d41..a385fba 100644 --- a/Luski/GUI/MainScreenWindow.cs +++ b/Luski/GUI/MainScreenWindow.cs @@ -39,16 +39,15 @@ public class MainScreenWindow : Window StartFocused = true, ClientSize = new Vector2i(624, 1090), Icon = Globals.Icon, - SharedContext = null, + SharedContext = null }; - public TabControl? tc; private FlowLayout? channelpicker, friends, friend_request; private RoundedButton? FriendManagerBtn; public static DebugProc DebugMessageDelegate = OnDebugMessage; - private static GLFWCallbacks.ErrorCallback GLFW_Error = OnGLFW_Error; - private static void OnGLFW_Error(ErrorCode e, string d) + + public static void OnGLFW_Error(ErrorCode e, string d) { if ((Globals.Settings.Logs & ConsoleLog.ShowErrorsForGLFW) != ConsoleLog.ShowErrorsForGLFW) return; Console.ForegroundColor = ConsoleColor.DarkRed; @@ -144,7 +143,8 @@ public class MainScreenWindow : Window VSync = VSyncMode.On; GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero); GL.Enable(EnableCap.DebugOutput); - GLFW.SetErrorCallback(GLFW_Error); + if ((Globals.Settings.Logs & ConsoleLog.ShowErrorsForGLFW) == ConsoleLog.ShowErrorsForGLFW) + GLFW.SetErrorCallback(OnGLFW_Error); try { Globals.DefaultFontFamly = FontFamily.LoadFontFamily(Globals.GetResource("Fonts.OpenSans.zip"), "OpenSans"); @@ -416,37 +416,37 @@ public class MainScreenWindow : Window protected override void OnFileDrop(FileDropEventArgs obj) { - void CheckFileDrop(IParent p, Vector2i diff) + void CheckFileDrop(IParent ParentToCheck, Vector2i diff) { bool found = false; - for (int i = p.Controls.Length - 1; i >= 0; i--) + for (int i = ParentToCheck.Controls.Length - 1; i >= 0; i--) { - if ((p.Controls[i].Location + diff).X <= (int)MousePosition.X && - (p.Controls[i].Location + diff).Y <= (int)MousePosition.Y && - (p.Controls[i].Location + p.Controls[i].Size + diff).X >= (int)MousePosition.X && - (p.Controls[i].Location + p.Controls[i].Size + diff).Y >= (int)MousePosition.Y) + if ((ParentToCheck.Controls[i].Location + diff).X <= (int)MousePosition.X && + (ParentToCheck.Controls[i].Location + diff).Y <= (int)MousePosition.Y && + (ParentToCheck.Controls[i].Location + ParentToCheck.Controls[i].Size + diff).X >= (int)MousePosition.X && + (ParentToCheck.Controls[i].Location + ParentToCheck.Controls[i].Size + diff).Y >= (int)MousePosition.Y) { - if (p.Controls[i] is IParent pp) + if (ParentToCheck.Controls[i] is IParent NextParentToCheck) { - if (pp.CollectUpperFiles) + if (NextParentToCheck.CollectUpperFiles) { found = true; - p.Controls[i].SendFilesEvent(obj.FileNames); + ParentToCheck.Controls[i].SendFilesEvent(obj.FileNames); } else { - CheckFileDrop(pp, pp.Controls[i].Location + diff); + CheckFileDrop(NextParentToCheck, ParentToCheck.Controls[i].Location + diff); } } else { found = true; - p.Controls[i].SendFilesEvent(obj.FileNames); + ParentToCheck.Controls[i].SendFilesEvent(obj.FileNames); } } } - if (!found && p is IRenderObject renderObject) + if (!found && ParentToCheck is IRenderObject renderObject) { renderObject.SendFilesEvent(obj.FileNames); } diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index 291ca3a..c1eff01 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -1,7 +1,7 @@ - Exe + WinExe net8.0 enable enable @@ -22,7 +22,7 @@ - + diff --git a/Luski/Program.cs b/Luski/Program.cs index 64ec162..e6d0802 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -1,8 +1,8 @@ -using System.Diagnostics; -using Luski; +using Luski; using Luski.Classes; using Luski.GUI; using OpenTK.Windowing.Common.Input; +using OpenTK.Windowing.GraphicsLibraryFramework; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using Updater; @@ -10,7 +10,11 @@ using Image = OpenTK.Windowing.Common.Input.Image; try { + Console.WriteLine("App Running"); + GLFW.SetErrorCallback(null); + Console.WriteLine("STOP ErrorCallback"); Globals.Settings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); + Console.WriteLine("load settings"); foreach (ExperimentInfo le in LuskiExperiments.LuskiExperimentsList) { Globals.RegisterExperiment(le); @@ -64,14 +68,14 @@ try } } } - + Console.WriteLine("Servers found"); Globals.UpdaterSettings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); Image Logo = SixLabors.ImageSharp.Image.Load(Globals.GetResource("Textures.Luski.png")); Logo.DangerousTryGetSinglePixelMemory(out Memory m); byte[] pixels = new byte[4 * Logo.Width * Logo.Height]; Logo.CopyPixelDataTo(pixels); Logo.Dispose(); - + GLFW.SetErrorCallback(null); Globals.Icon = new WindowIcon(new Image(Logo.Width, Logo.Height, pixels)); if (args is not null && args.Length > 0) @@ -98,8 +102,9 @@ try } - + Console.WriteLine("icon"); MainScreenWindow.Settings.Icon = Globals.Icon; + Globals.ms = new MainScreenWindow(); Globals.ms.CustomF11 = false; //Globals.ms.DrawFrame(); @@ -110,6 +115,7 @@ try } catch (Exception ex) { + Console.WriteLine("oh no, an error occured"); Console.WriteLine(ex); }