From f47dd7c3a0aecc8bb265d715882c38a066004608 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Mon, 18 Nov 2024 22:27:43 -0500 Subject: [PATCH] Files Example --- .../UI/PublicServers/ChatMessage.cs | 56 +++++++++---------- .../MainScreen/UI/PublicServers/PublicChat.cs | 30 +++++++--- Luski/GUI/MainScreenWindow.cs | 40 +++++++++++++ Luski/Luski.csproj | 2 +- 4 files changed, 91 insertions(+), 37 deletions(-) diff --git a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs index 422695b..d7eaad7 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/ChatMessage.cs @@ -26,7 +26,7 @@ public class ChatMessage : UserControl private LabelBase FirstL; public readonly double HorPadding = 12.ScaleDouble(), - VerticalPadding = 0.ScaleDouble(); + VerticalPadding = 5.ScaleDouble(); private static Dictionary> Messages = new(); @@ -159,23 +159,14 @@ public class ChatMessage : UserControl if (Msg.Files.Count > 0) { - int row = 1; - int files_on_row = 0; for (int i = 0; i < Msg.Files.Count; i++) { - double lx = (HorPadding * files_on_row) + LastObject.Location.X + (333 * (files_on_row + 1)); - if (lx > base.Size.X) - { - row++; - files_on_row = 0; - lx = (HorPadding * files_on_row) + LastObject.Location.X + (333 * (files_on_row + 1)); - } - - files_on_row++; - 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; - Controls.Add(cem); + 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); } } @@ -233,27 +224,36 @@ public class ChatMessage : UserControl if (msg.Files.Count > 0) { - int row = 1; - int filesonrow = 0; + /*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 + }; + Controls.Add(cf); + */ + + 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)))); + cem.Location = new(FirstL.Location.X, + (int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding)); LastObject = cem; Controls.Add(cem); } + + // LastObject = 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); + } BlockDraw = false; //if (Parent is not null) Globals.ms.pc.MessageFlow.ReportSizeUpdate(this); TryDraw(); diff --git a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs index 2f1f7fc..856e1d6 100644 --- a/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs +++ b/Luski/GUI/MainScreen/UI/PublicServers/PublicChat.cs @@ -102,11 +102,8 @@ public class PublicChat : UserControl tb.OnRemoveLine += TbOnOnRemoveLine; tb.OnNewLine += TbOnOnNewLine; tb.ForceDistanceUpdate(this); - //tb.KeyPress += TbOnKeyPress; - //Globals.Luski.MainServer.MessageReceived += LuskiOnMessageReceived; + CollectUpperFiles = true; FilesDroped += OnFilesDroped; - tb.FilesDroped += OnFilesDroped; - MessageFlow.FilesDroped += OnFilesDroped; FileFlow = new() { BackgroundColor = base.BackgroundColor, @@ -114,6 +111,7 @@ public class PublicChat : UserControl Location = new(MessageFlow.Location.X, MessageFlow.Location.Y + MessageFlow.Size.Y), Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right }; + FileFlow.SizeUpdateNotIgnored += CFOnSizeChanged; Controls.Add(FileFlow); } @@ -185,8 +183,15 @@ public class PublicChat : UserControl { if (arg.Key == Keys.Enter && !arg.Shift) { - //SocketFile file = await Channel!.Server.UploadFile("/home/jacob/Pictures/Points.png"); - await Channel!.SendMessage(tb.Text, Profile: Globals.ServerProfile, files: Array.Empty()); + List FilesList = new(); + foreach (FileUpload fileUpload in FilesToUpload) + { + await fileUpload.StartUpload(); + FilesList.Add(fileUpload.PublicSF!); + } + + ClearFiles(); + await Channel!.SendMessage(tb.Text, Profile: Globals.ServerProfile, files: FilesList.ToArray()); tb.Text = string.Empty; tb.CursorLocation = 0; } @@ -393,8 +398,9 @@ public class PublicChat : UserControl public void AddFile(string FilePath, bool ReloadUI = true) { - FileFlow.SizeUpdateNotIgnored += CFOnSizeChanged; + FileUpload FU = new(Channel!.Server, FilePath); + FilesToUpload.Add(FU); FileFlow.Controls.Add(FU); FU.BackgroundColor = Color4.Red; if (ReloadUI) TryDraw(); @@ -404,15 +410,23 @@ public class PublicChat : UserControl private Task CFOnSizeChanged(IRenderObject arg) { - Console.WriteLine(arg.Size); FileFlow.BackgroundColor = Color4.Green; arg.Location = new(arg.Location.X, arg.Location.Y + OldSize - arg.Size.Y); + MessageFlow.Size = new(MessageFlow.Size.X, FileFlow.Location.Y - MessageFlow.Location.Y); OldSize = arg.Size.Y; return Task.CompletedTask; } + public void ClearFiles() + { + FilesToUpload.Clear(); + FileFlow.Controls.Clear(); + MessageFlow.Size = new(MessageFlow.Size.X, FileFlow.Location.Y - MessageFlow.Location.Y); + } + public void RemoveFile(FileUpload FU) { + MessageFlow.Size = new(MessageFlow.Size.X, FileFlow.Location.Y - MessageFlow.Location.Y); } public async Task LoadChannel(SocketChannel channel) diff --git a/Luski/GUI/MainScreenWindow.cs b/Luski/GUI/MainScreenWindow.cs index 9673733..f1dba4d 100644 --- a/Luski/GUI/MainScreenWindow.cs +++ b/Luski/GUI/MainScreenWindow.cs @@ -405,6 +405,46 @@ public class MainScreenWindow : Window BlockDraw = false; } + + protected override void OnFileDrop(FileDropEventArgs obj) + { + void CheckFileDrop(IParent p, Vector2i diff) + { + bool found = false; + for (int i = p.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 (p.Controls[i] is IParent pp) + { + if (pp.CollectUpperFiles) + { + found = true; + p.Controls[i].SendFilesEvent(obj.FileNames); + } + else + { + CheckFileDrop(pp, pp.Controls[i].Location + diff); + } + } + else + { + found = true; + p.Controls[i].SendFilesEvent(obj.FileNames); + } + } + } + + if (!found && p is IRenderObject renderObject) + { + renderObject.SendFilesEvent(obj.FileNames); + } + } + CheckFileDrop(this, new(0)); + } private FlowLayout? ProfileFlow; diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index d5a6119..291ca3a 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -22,7 +22,7 @@ - +