diff --git a/Luski/GUI/MainScreen/UI/ChatMessage.cs b/Luski/GUI/MainScreen/UI/ChatMessage.cs new file mode 100644 index 0000000..a6e3ee5 --- /dev/null +++ b/Luski/GUI/MainScreen/UI/ChatMessage.cs @@ -0,0 +1,131 @@ +using GraphicsManager.Enums; +using GraphicsManager.Interfaces; +using GraphicsManager.Objects; +using GraphicsManager.Objects.Core; +using Luski.net.Interfaces; +using Luski.net.JsonTypes; + +namespace Luski.GUI.MainScreen.UI; + +public class ChatMessage : UserControl +{ + readonly int padding = 2; + private SocketMessage Msg { get; } + private Label label1, label2; + + public ChatMessage(SocketMessage message) + { + Msg = message; + IUser user = message.GetAuthor().Result; + Anchor = ObjectAnchor.Left | ObjectAnchor.Right; + + Controls.Add(label1 = new Label() {Location = new(83, 9), Text = user.Username}); + Controls.Add(label2 = new Label() {Location = new(83, 40), Text = message.Context}); + + if (Msg.Files != null && Msg.Files.Length > 0) + { + /* + for (int i = 0; i < Msg.Files.Length; i++) + { + File file = Msg.Files[i]; + ContentEmbed button = new(file, Msg.ChannelID); + if (InvokeRequired) + { + Invoke(new Action(() => + { + Controls.Add(button); + })); + } + else + { + Controls.Add(button); + } + }*/ + } + + 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() {Location = new(label1.Location.X + label1.Size.X + 4, 17), Text = timestr}); + Controls.Add(new Label() {Location = new(129, 17), Text = message.Context}); + Controls.Add(new Rectangle(new Texture(user.GetAvatar().Result)) { Location = new(15, 3), Size = new(58, 58) }); + } + + public void AddMessage(SocketMessage msg) + { + Label newLabel = new() + { + 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 != null && msg.Files.Length > 0) + { + for (int i = 0; i < msg.Files.Length; i++) + { + //files example + /* + File file = msg.Files[i]; + ContentEmbed button = new(file, Msg.ChannelID); + if (InvokeRequired) + { + Invoke(new Action(() => + { + Controls.Add(button); + })); + } + else + { + Controls.Add(button); + }*/ + } + } + } + readonly List