From 75f444e4311203c4901ef9d6ef2a4ed18e06d047 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 00:44:58 +0300 Subject: [PATCH 01/12] Basic implementation --- osu.Game/Overlays/Chat/DrawableChannel.cs | 49 ++++++++++++++++++----- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index f831266b1b..34de149bc3 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -12,6 +12,8 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Cursor; using osu.Game.Online.Chat; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Overlays.Chat { @@ -74,17 +76,40 @@ namespace osu.Game.Overlays.Chat protected virtual ChatLine CreateChatLine(Message m) => new ChatLine(m); + protected virtual Drawable CreateDaySeparator(DateTimeOffset time) => new Container + { + Margin = new MarginPadding { Vertical = 5 }, + RelativeSizeAxes = Axes.X, + Height = 2, + Child = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + } + }; + private void newMessagesArrived(IEnumerable newMessages) { // Add up to last Channel.MAX_HISTORY messages var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MaxHistory)); - ChatLineFlow.AddRange(displayMessages.Select(CreateChatLine)); + var existingChatLines = getChatLines(); - if (scroll.IsScrolledToEnd(10) || !ChatLineFlow.Children.Any() || newMessages.Any(m => m is LocalMessage)) + Message lastMessage = existingChatLines.Any() ? existingChatLines.First().Message : null; + + displayMessages.ForEach(m => + { + if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != m.Timestamp.ToLocalTime().Date) + ChatLineFlow.Add(CreateDaySeparator(m.Timestamp)); + + ChatLineFlow.Add(CreateChatLine(m)); + lastMessage = m; + }); + + if (scroll.IsScrolledToEnd(10) || !existingChatLines.Any() || newMessages.Any(m => m is LocalMessage)) scrollToEnd(); - var staleMessages = ChatLineFlow.Children.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); + var staleMessages = existingChatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); int count = staleMessages.Length - Channel.MaxHistory; for (int i = 0; i < count; i++) @@ -98,7 +123,7 @@ namespace osu.Game.Overlays.Chat private void pendingMessageResolved(Message existing, Message updated) { - var found = ChatLineFlow.Children.LastOrDefault(c => c.Message == existing); + var found = getChatLines().LastOrDefault(c => c.Message == existing); if (found != null) { @@ -112,19 +137,25 @@ namespace osu.Game.Overlays.Chat private void messageRemoved(Message removed) { - ChatLineFlow.Children.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); + getChatLines().FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); } + private IEnumerable getChatLines() => ChatLineFlow.Children.OfType(); + private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); - protected class ChatLineContainer : FillFlowContainer + protected class ChatLineContainer : FillFlowContainer { protected override int Compare(Drawable x, Drawable y) { - var xC = (ChatLine)x; - var yC = (ChatLine)y; + if (x is ChatLine && y is ChatLine) + { + var xC = (ChatLine)x; + var yC = (ChatLine)y; - return xC.Message.CompareTo(yC.Message); + return xC.Message.CompareTo(yC.Message); + } + return base.Compare(x, y); } } } From d19041fa5353d007b01f1610a46a244e820e60b6 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 01:30:37 +0300 Subject: [PATCH 02/12] Implement DaySeparator class --- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 8 ++ osu.Game/Overlays/Chat/DrawableChannel.cs | 84 ++++++++++++++++--- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index 8f39fb9006..a17b6ea170 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -124,6 +124,14 @@ namespace osu.Game.Online.Chat protected override ChatLine CreateChatLine(Message m) => CreateChatLineAction(m); + protected override DaySeparator CreateDaySeparator(DateTimeOffset time) => new DaySeparator(time) + { + Colour = Color4.White, + TextSize = 14, + LineHeight = 1, + Margin = new MarginPadding { Horizontal = 10 } + }; + public StandAloneDrawableChannel(Channel channel) : base(channel) { diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 34de149bc3..850c7146da 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -14,6 +14,9 @@ using osu.Game.Graphics.Cursor; using osu.Game.Online.Chat; using osu.Framework.Graphics.Shapes; using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Game.Graphics; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics.Sprites; namespace osu.Game.Overlays.Chat { @@ -23,6 +26,9 @@ namespace osu.Game.Overlays.Chat protected ChatLineContainer ChatLineFlow; private OsuScrollContainer scroll; + [Resolved] + private OsuColour colours { get; set; } + public DrawableChannel(Channel channel) { Channel = channel; @@ -76,16 +82,9 @@ namespace osu.Game.Overlays.Chat protected virtual ChatLine CreateChatLine(Message m) => new ChatLine(m); - protected virtual Drawable CreateDaySeparator(DateTimeOffset time) => new Container + protected virtual DaySeparator CreateDaySeparator(DateTimeOffset time) => new DaySeparator(time) { - Margin = new MarginPadding { Vertical = 5 }, - RelativeSizeAxes = Axes.X, - Height = 2, - Child = new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - } + Colour = colours.ChatBlue.Lighten(0.7f) }; private void newMessagesArrived(IEnumerable newMessages) @@ -95,11 +94,11 @@ namespace osu.Game.Overlays.Chat var existingChatLines = getChatLines(); - Message lastMessage = existingChatLines.Any() ? existingChatLines.First().Message : null; + Message lastMessage = existingChatLines.Any() ? existingChatLines.Last().Message : null; displayMessages.ForEach(m => { - if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != m.Timestamp.ToLocalTime().Date) + if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Day != m.Timestamp.ToLocalTime().Day) ChatLineFlow.Add(CreateDaySeparator(m.Timestamp)); ChatLineFlow.Add(CreateChatLine(m)); @@ -158,5 +157,68 @@ namespace osu.Game.Overlays.Chat return base.Compare(x, y); } } + + protected class DaySeparator : GridContainer + { + public float TextSize + { + get => text.Font.Size; + set => text.Font = text.Font.With(size: value); + } + + private float lineHeight = 2; + + public float LineHeight + { + get => LineHeight; + set { lineHeight = leftBox.Height = rightBox.Height = value; } + } + + private readonly SpriteText text; + private readonly Box leftBox; + private readonly Box rightBox; + + public DaySeparator(DateTimeOffset time) + { + Margin = new MarginPadding { Vertical = 10 }; + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + ColumnDimensions = new[] + { + new Dimension(), + new Dimension(GridSizeMode.AutoSize), + new Dimension(), + }; + RowDimensions = new[] + { + new Dimension(GridSizeMode.AutoSize), + }; + Content = new[] + { + new Drawable[] + { + leftBox = new Box + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Height = lineHeight, + }, + text = new SpriteText + { + Margin = new MarginPadding { Horizontal = 10 }, + Text = time.ToLocalTime().ToString("dd MMM yyyy"), + }, + rightBox = new Box + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Height = lineHeight, + }, + } + }; + } + } } } From a3ab6d33c14ad83cd44edd4f5eeb35ee097a580e Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 01:37:30 +0300 Subject: [PATCH 03/12] Add test --- .../Visual/Online/TestSceneStandAloneChatDisplay.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs b/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs index 3c5641fcd6..39c2fbfcc9 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics; using osu.Game.Online.Chat; using osu.Game.Users; using osuTK; +using System; namespace osu.Game.Tests.Visual.Online { @@ -111,6 +112,13 @@ namespace osu.Game.Tests.Visual.Online Sender = longUsernameUser, Content = "Hi guys, my new username is lit!" })); + + AddStep("message with new date", () => testChannel.AddNewMessages(new Message(sequence++) + { + Sender = longUsernameUser, + Content = "Message from the future!", + Timestamp = DateTimeOffset.Now + })); } } } From bb7af1e39cf88a7dd9120251237af29fff60bdab Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 01:45:04 +0300 Subject: [PATCH 04/12] Fix some margin/padding issues --- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 3 +- osu.Game/Overlays/Chat/DrawableChannel.cs | 71 ++++++++++--------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index a17b6ea170..5b1d25b0d9 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -129,7 +129,8 @@ namespace osu.Game.Online.Chat Colour = Color4.White, TextSize = 14, LineHeight = 1, - Margin = new MarginPadding { Horizontal = 10 } + Padding = new MarginPadding { Horizontal = 10 }, + Margin = new MarginPadding { Vertical = 5 }, }; public StandAloneDrawableChannel(Channel channel) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 850c7146da..b26f974ec9 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -84,7 +84,8 @@ namespace osu.Game.Overlays.Chat protected virtual DaySeparator CreateDaySeparator(DateTimeOffset time) => new DaySeparator(time) { - Colour = colours.ChatBlue.Lighten(0.7f) + Margin = new MarginPadding { Vertical = 10 }, + Colour = colours.ChatBlue.Lighten(0.7f), }; private void newMessagesArrived(IEnumerable newMessages) @@ -158,7 +159,7 @@ namespace osu.Game.Overlays.Chat } } - protected class DaySeparator : GridContainer + protected class DaySeparator : Container { public float TextSize { @@ -180,42 +181,46 @@ namespace osu.Game.Overlays.Chat public DaySeparator(DateTimeOffset time) { - Margin = new MarginPadding { Vertical = 10 }; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - ColumnDimensions = new[] + Child = new GridContainer { - new Dimension(), - new Dimension(GridSizeMode.AutoSize), - new Dimension(), - }; - RowDimensions = new[] - { - new Dimension(GridSizeMode.AutoSize), - }; - Content = new[] - { - new Drawable[] + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + ColumnDimensions = new[] { - leftBox = new Box + new Dimension(), + new Dimension(GridSizeMode.AutoSize), + new Dimension(), + }, + RowDimensions = new[] + { + new Dimension(GridSizeMode.AutoSize), + }, + Content = new[] + { + new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.X, - Height = lineHeight, - }, - text = new SpriteText - { - Margin = new MarginPadding { Horizontal = 10 }, - Text = time.ToLocalTime().ToString("dd MMM yyyy"), - }, - rightBox = new Box - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.X, - Height = lineHeight, - }, + leftBox = new Box + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Height = lineHeight, + }, + text = new SpriteText + { + Margin = new MarginPadding { Horizontal = 10 }, + Text = time.ToLocalTime().ToString("dd MMM yyyy"), + }, + rightBox = new Box + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Height = lineHeight, + }, + } } }; } From 2896ed90e24cf774a573301c86798b2e3ba881c2 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 01:55:26 +0300 Subject: [PATCH 05/12] Fix incorrect date comparison --- osu.Game/Overlays/Chat/DrawableChannel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index b26f974ec9..ece5beb7f8 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -99,7 +99,7 @@ namespace osu.Game.Overlays.Chat displayMessages.ForEach(m => { - if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Day != m.Timestamp.ToLocalTime().Day) + if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != m.Timestamp.ToLocalTime().Date) ChatLineFlow.Add(CreateDaySeparator(m.Timestamp)); ChatLineFlow.Add(CreateChatLine(m)); From e9ae838f465bbf719a07623818e26e5b7bf5329b Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 02:16:52 +0300 Subject: [PATCH 06/12] CI fixes --- osu.Game/Overlays/Chat/DrawableChannel.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index ece5beb7f8..3dd9f755d1 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -155,6 +155,7 @@ namespace osu.Game.Overlays.Chat return xC.Message.CompareTo(yC.Message); } + return base.Compare(x, y); } } @@ -171,7 +172,7 @@ namespace osu.Game.Overlays.Chat public float LineHeight { - get => LineHeight; + get => lineHeight; set { lineHeight = leftBox.Height = rightBox.Height = value; } } @@ -193,11 +194,8 @@ namespace osu.Game.Overlays.Chat new Dimension(GridSizeMode.AutoSize), new Dimension(), }, - RowDimensions = new[] - { - new Dimension(GridSizeMode.AutoSize), - }, - Content = new[] + RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize), }, + Content = new[] { new Drawable[] { From b1eac6b400dd5bfb5ad4948e588b616a46a23f46 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 03:11:19 +0300 Subject: [PATCH 07/12] Apply suggested changes --- osu.Game/Overlays/Chat/DrawableChannel.cs | 32 ++++++----------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 3dd9f755d1..cfa56b5136 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -23,7 +23,7 @@ namespace osu.Game.Overlays.Chat public class DrawableChannel : Container { public readonly Channel Channel; - protected ChatLineContainer ChatLineFlow; + protected FillFlowContainer ChatLineFlow; private OsuScrollContainer scroll; [Resolved] @@ -48,7 +48,7 @@ namespace osu.Game.Overlays.Chat // Some chat lines have effects that slightly protrude to the bottom, // which we do not want to mask away, hence the padding. Padding = new MarginPadding { Bottom = 5 }, - Child = ChatLineFlow = new ChatLineContainer + Child = ChatLineFlow = new FillFlowContainer { Padding = new MarginPadding { Left = 20, Right = 20 }, RelativeSizeAxes = Axes.X, @@ -93,9 +93,9 @@ namespace osu.Game.Overlays.Chat // Add up to last Channel.MAX_HISTORY messages var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MaxHistory)); - var existingChatLines = getChatLines(); + var existingChatLines = getChatLines; - Message lastMessage = existingChatLines.Any() ? existingChatLines.Last().Message : null; + Message lastMessage = existingChatLines.LastOrDefault()?.Message; displayMessages.ForEach(m => { @@ -123,7 +123,7 @@ namespace osu.Game.Overlays.Chat private void pendingMessageResolved(Message existing, Message updated) { - var found = getChatLines().LastOrDefault(c => c.Message == existing); + var found = getChatLines.LastOrDefault(c => c.Message == existing); if (found != null) { @@ -137,29 +137,13 @@ namespace osu.Game.Overlays.Chat private void messageRemoved(Message removed) { - getChatLines().FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); + getChatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); } - private IEnumerable getChatLines() => ChatLineFlow.Children.OfType(); + private IEnumerable getChatLines => ChatLineFlow.Children.OfType(); private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); - protected class ChatLineContainer : FillFlowContainer - { - protected override int Compare(Drawable x, Drawable y) - { - if (x is ChatLine && y is ChatLine) - { - var xC = (ChatLine)x; - var yC = (ChatLine)y; - - return xC.Message.CompareTo(yC.Message); - } - - return base.Compare(x, y); - } - } - protected class DaySeparator : Container { public float TextSize @@ -173,7 +157,7 @@ namespace osu.Game.Overlays.Chat public float LineHeight { get => lineHeight; - set { lineHeight = leftBox.Height = rightBox.Height = value; } + set => lineHeight = leftBox.Height = rightBox.Height = value; } private readonly SpriteText text; From 09b2f11bd5c4ee7fd6ebf2320e0d107c53ac6f82 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 22 Oct 2019 03:14:20 +0300 Subject: [PATCH 08/12] Remove unused variable --- osu.Game/Overlays/Chat/DrawableChannel.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index cfa56b5136..85de23caaa 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -93,9 +93,7 @@ namespace osu.Game.Overlays.Chat // Add up to last Channel.MAX_HISTORY messages var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MaxHistory)); - var existingChatLines = getChatLines; - - Message lastMessage = existingChatLines.LastOrDefault()?.Message; + Message lastMessage = getChatLines.LastOrDefault()?.Message; displayMessages.ForEach(m => { @@ -106,10 +104,10 @@ namespace osu.Game.Overlays.Chat lastMessage = m; }); - if (scroll.IsScrolledToEnd(10) || !existingChatLines.Any() || newMessages.Any(m => m is LocalMessage)) + if (scroll.IsScrolledToEnd(10) || !getChatLines.Any() || newMessages.Any(m => m is LocalMessage)) scrollToEnd(); - var staleMessages = existingChatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); + var staleMessages = getChatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); int count = staleMessages.Length - Channel.MaxHistory; for (int i = 0; i < count; i++) From 0ba287a7fd31bcb39256722bbc42585fbad77b6d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Oct 2019 00:14:22 +0900 Subject: [PATCH 09/12] Rename variable --- osu.Game/Overlays/Chat/DrawableChannel.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 85de23caaa..20e82cea95 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -93,7 +93,7 @@ namespace osu.Game.Overlays.Chat // Add up to last Channel.MAX_HISTORY messages var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MaxHistory)); - Message lastMessage = getChatLines.LastOrDefault()?.Message; + Message lastMessage = chatLines.LastOrDefault()?.Message; displayMessages.ForEach(m => { @@ -104,10 +104,10 @@ namespace osu.Game.Overlays.Chat lastMessage = m; }); - if (scroll.IsScrolledToEnd(10) || !getChatLines.Any() || newMessages.Any(m => m is LocalMessage)) + if (scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage)) scrollToEnd(); - var staleMessages = getChatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); + var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); int count = staleMessages.Length - Channel.MaxHistory; for (int i = 0; i < count; i++) @@ -121,7 +121,7 @@ namespace osu.Game.Overlays.Chat private void pendingMessageResolved(Message existing, Message updated) { - var found = getChatLines.LastOrDefault(c => c.Message == existing); + var found = chatLines.LastOrDefault(c => c.Message == existing); if (found != null) { @@ -135,10 +135,10 @@ namespace osu.Game.Overlays.Chat private void messageRemoved(Message removed) { - getChatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); + chatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); } - private IEnumerable getChatLines => ChatLineFlow.Children.OfType(); + private IEnumerable chatLines => ChatLineFlow.Children.OfType(); private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); From 3b4823abe7c687bbab7eba9a6af9675fdb9f2786 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Oct 2019 00:16:17 +0900 Subject: [PATCH 10/12] Use foreach --- osu.Game/Overlays/Chat/DrawableChannel.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 20e82cea95..f40f53852a 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -95,14 +95,14 @@ namespace osu.Game.Overlays.Chat Message lastMessage = chatLines.LastOrDefault()?.Message; - displayMessages.ForEach(m => + foreach (var message in displayMessages) { - if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != m.Timestamp.ToLocalTime().Date) - ChatLineFlow.Add(CreateDaySeparator(m.Timestamp)); + if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != message.Timestamp.ToLocalTime().Date) + ChatLineFlow.Add(CreateDaySeparator(message.Timestamp)); - ChatLineFlow.Add(CreateChatLine(m)); - lastMessage = m; - }); + ChatLineFlow.Add(CreateChatLine(message)); + lastMessage = message; + } if (scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage)) scrollToEnd(); From e9aa7f32186a806a549968d6920e7ea871d5f0d0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Oct 2019 00:24:08 +0900 Subject: [PATCH 11/12] Subclass and use yellow for stand-alone chat display --- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 27 +++++++++++++------ osu.Game/Overlays/Chat/DrawableChannel.cs | 1 - 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index 5b1d25b0d9..5ae453ceeb 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Chat; using osuTK.Graphics; @@ -124,14 +125,7 @@ namespace osu.Game.Online.Chat protected override ChatLine CreateChatLine(Message m) => CreateChatLineAction(m); - protected override DaySeparator CreateDaySeparator(DateTimeOffset time) => new DaySeparator(time) - { - Colour = Color4.White, - TextSize = 14, - LineHeight = 1, - Padding = new MarginPadding { Horizontal = 10 }, - Margin = new MarginPadding { Vertical = 5 }, - }; + protected override DaySeparator CreateDaySeparator(DateTimeOffset time) => new CustomDaySeparator(time); public StandAloneDrawableChannel(Channel channel) : base(channel) @@ -143,6 +137,23 @@ namespace osu.Game.Online.Chat { ChatLineFlow.Padding = new MarginPadding { Horizontal = 0 }; } + + private class CustomDaySeparator : DaySeparator + { + public CustomDaySeparator(DateTimeOffset time) : base(time) + { + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Colour = colours.Yellow; + TextSize = 14; + LineHeight = 1; + Padding = new MarginPadding { Horizontal = 10 }; + Margin = new MarginPadding { Vertical = 5 }; + } + } } protected class StandAloneMessage : ChatLine diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index f40f53852a..6cdbfabe0f 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -13,7 +13,6 @@ using osu.Game.Graphics.Containers; using osu.Game.Graphics.Cursor; using osu.Game.Online.Chat; using osu.Framework.Graphics.Shapes; -using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Graphics; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics.Sprites; From c3375071adbc1cbc9557789ca0ef6e1ae96b854c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Oct 2019 00:26:47 +0900 Subject: [PATCH 12/12] Fix formatting issue --- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index 5ae453ceeb..21d0bcc4bf 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -140,7 +140,8 @@ namespace osu.Game.Online.Chat private class CustomDaySeparator : DaySeparator { - public CustomDaySeparator(DateTimeOffset time) : base(time) + public CustomDaySeparator(DateTimeOffset time) + : base(time) { }