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;
public readonly double HorPadding = 12.ScaleDouble(),
VerticalPadding = 0.ScaleDouble();
VerticalPadding = 5.ScaleDouble();
private static Dictionary<MainSocketRemoteUser, List<ChatMessage>> 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();

View File

@ -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<SocketFile>());
List<SocketFile> 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)

View File

@ -406,6 +406,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;
public override void ForceUpdate(bool resize = false)

View File

@ -22,7 +22,7 @@
</PropertyGroup>
<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="Updater" Version="1.0.0-alpha05" />
</ItemGroup>