Files Example

This commit is contained in:
JacobTech 2024-11-18 22:27:43 -05:00
parent 7b8d0c8eb7
commit f47dd7c3a0
4 changed files with 91 additions and 37 deletions

View File

@ -26,7 +26,7 @@ public class ChatMessage : UserControl
private LabelBase FirstL; private LabelBase FirstL;
public readonly double HorPadding = 12.ScaleDouble(), public readonly double HorPadding = 12.ScaleDouble(),
VerticalPadding = 0.ScaleDouble(); VerticalPadding = 5.ScaleDouble();
private static Dictionary<MainSocketRemoteUser, List<ChatMessage>> Messages = new(); private static Dictionary<MainSocketRemoteUser, List<ChatMessage>> Messages = new();
@ -159,23 +159,14 @@ public class ChatMessage : UserControl
if (Msg.Files.Count > 0) if (Msg.Files.Count > 0)
{ {
int row = 1;
int files_on_row = 0;
for (int i = 0; i < Msg.Files.Count; i++) for (int i = 0; i < Msg.Files.Count; i++)
{ {
double lx = (HorPadding * files_on_row) + LastObject.Location.X + (333 * (files_on_row + 1)); var cem = ContentEmbed.GetEmbed(this, Msg.Files[i], Msg.ChannelID);
if (lx > base.Size.X) cem.Wait();
{ cem.Result.Location = new(FirstL.Location.X,
row++; (int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding));
files_on_row = 0; LastObject = cem.Result;
lx = (HorPadding * files_on_row) + LastObject.Location.X + (333 * (files_on_row + 1)); Controls.Add(cem.Result);
}
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);
} }
} }
@ -233,27 +224,36 @@ public class ChatMessage : UserControl
if (msg.Files.Count > 0) if (msg.Files.Count > 0)
{ {
int row = 1; /*CompressedFlow cf = new()
int filesonrow = 0; {
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++) 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); 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; LastObject = cem;
Controls.Add(cem); Controls.Add(cem);
} }
// LastObject = cf;
} }
if (LastObject is Label ll) Size = new(Size.X, (int)(ll.Location.Y + ll.Size.Y + VerticalPadding)); 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)); else Size = new(Size.X ,(int)(LastObject.Location.Y + LastObject.Size.Y + VerticalPadding));
if (LastObject is CompressedFlow)
{
LastObject.ForceDistanceUpdate(this);
}
BlockDraw = false; BlockDraw = false;
//if (Parent is not null) Globals.ms.pc.MessageFlow.ReportSizeUpdate(this); //if (Parent is not null) Globals.ms.pc.MessageFlow.ReportSizeUpdate(this);
TryDraw(); TryDraw();

View File

@ -102,11 +102,8 @@ public class PublicChat : UserControl
tb.OnRemoveLine += TbOnOnRemoveLine; tb.OnRemoveLine += TbOnOnRemoveLine;
tb.OnNewLine += TbOnOnNewLine; tb.OnNewLine += TbOnOnNewLine;
tb.ForceDistanceUpdate(this); tb.ForceDistanceUpdate(this);
//tb.KeyPress += TbOnKeyPress; CollectUpperFiles = true;
//Globals.Luski.MainServer.MessageReceived += LuskiOnMessageReceived;
FilesDroped += OnFilesDroped; FilesDroped += OnFilesDroped;
tb.FilesDroped += OnFilesDroped;
MessageFlow.FilesDroped += OnFilesDroped;
FileFlow = new() FileFlow = new()
{ {
BackgroundColor = base.BackgroundColor, BackgroundColor = base.BackgroundColor,
@ -114,6 +111,7 @@ public class PublicChat : UserControl
Location = new(MessageFlow.Location.X, MessageFlow.Location.Y + MessageFlow.Size.Y), Location = new(MessageFlow.Location.X, MessageFlow.Location.Y + MessageFlow.Size.Y),
Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right
}; };
FileFlow.SizeUpdateNotIgnored += CFOnSizeChanged;
Controls.Add(FileFlow); Controls.Add(FileFlow);
} }
@ -185,8 +183,15 @@ public class PublicChat : UserControl
{ {
if (arg.Key == Keys.Enter && !arg.Shift) if (arg.Key == Keys.Enter && !arg.Shift)
{ {
//SocketFile file = await Channel!.Server.UploadFile("/home/jacob/Pictures/Points.png"); List<SocketFile> FilesList = new();
await Channel!.SendMessage(tb.Text, Profile: Globals.ServerProfile, files: Array.Empty<SocketFile>()); 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.Text = string.Empty;
tb.CursorLocation = 0; tb.CursorLocation = 0;
} }
@ -393,8 +398,9 @@ public class PublicChat : UserControl
public void AddFile(string FilePath, bool ReloadUI = true) public void AddFile(string FilePath, bool ReloadUI = true)
{ {
FileFlow.SizeUpdateNotIgnored += CFOnSizeChanged;
FileUpload FU = new(Channel!.Server, FilePath); FileUpload FU = new(Channel!.Server, FilePath);
FilesToUpload.Add(FU);
FileFlow.Controls.Add(FU); FileFlow.Controls.Add(FU);
FU.BackgroundColor = Color4.Red; FU.BackgroundColor = Color4.Red;
if (ReloadUI) TryDraw(); if (ReloadUI) TryDraw();
@ -404,15 +410,23 @@ public class PublicChat : UserControl
private Task CFOnSizeChanged(IRenderObject arg) private Task CFOnSizeChanged(IRenderObject arg)
{ {
Console.WriteLine(arg.Size);
FileFlow.BackgroundColor = Color4.Green; FileFlow.BackgroundColor = Color4.Green;
arg.Location = new(arg.Location.X, arg.Location.Y + OldSize - arg.Size.Y); 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; OldSize = arg.Size.Y;
return Task.CompletedTask; 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) public void RemoveFile(FileUpload FU)
{ {
MessageFlow.Size = new(MessageFlow.Size.X, FileFlow.Location.Y - MessageFlow.Location.Y);
} }
public async Task LoadChannel(SocketChannel channel) public async Task LoadChannel(SocketChannel channel)

View File

@ -406,6 +406,46 @@ public class MainScreenWindow : Window
BlockDraw = false; 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; private FlowLayout? ProfileFlow;
public override void ForceUpdate(bool resize = false) public override void ForceUpdate(bool resize = false)

View File

@ -22,7 +22,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.1.1-alpha33" /> <PackageReference Include="GraphicsManager" Version="1.1.1-alpha35" />
<PackageReference Include="Luski.net" Version="2.0.1-alpha18" /> <PackageReference Include="Luski.net" Version="2.0.1-alpha18" />
<PackageReference Include="Updater" Version="1.0.0-alpha05" /> <PackageReference Include="Updater" Version="1.0.0-alpha05" />
</ItemGroup> </ItemGroup>