From 70ee7e4afdea9a442e4f197577f2de82f1a46af4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 2 Aug 2018 07:59:48 +0900 Subject: [PATCH 1/3] Scroll chat to end of buffer when posting a new message --- osu.Game/Overlays/Chat/DrawableChannel.cs | 6 +++--- osu.Game/Overlays/ChatOverlay.cs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index bcc8879902..acc145af68 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -64,7 +64,7 @@ private void load() protected override void LoadComplete() { base.LoadComplete(); - scrollToEnd(); + ScrollToEnd(); } protected override void Dispose(bool isDisposing) @@ -86,7 +86,7 @@ private void newMessagesArrived(IEnumerable newMessages) if (!IsLoaded) return; if (scroll.IsScrolledToEnd(10) || !flow.Children.Any()) - scrollToEnd(); + ScrollToEnd(); var staleMessages = flow.Children.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); int count = staleMessages.Length - Channel.MAX_HISTORY; @@ -118,7 +118,7 @@ private void messageRemoved(Message removed) flow.Children.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); } - private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); + public void ScrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); private class ChatLineContainer : FillFlowContainer { diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 8e20d76914..f86c5204bb 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -475,6 +475,8 @@ private void postMessage(TextBox textbox, bool newText) if (target == null) return; + currentChannelContainer.Child.ScrollToEnd(); + if (!api.IsLoggedIn) { target.AddNewMessages(new ErrorMessage("Please sign in to participate in chat!")); From 4c57e629ffe0905e90cb524d59fc3e714b7eb556 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 3 Aug 2018 19:32:34 +0900 Subject: [PATCH 2/3] Use private implementation --- osu.Game/Overlays/Chat/DrawableChannel.cs | 8 ++++---- osu.Game/Overlays/ChatOverlay.cs | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index acc145af68..4586d4d87c 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -64,7 +64,7 @@ private void load() protected override void LoadComplete() { base.LoadComplete(); - ScrollToEnd(); + scrollToEnd(); } protected override void Dispose(bool isDisposing) @@ -85,8 +85,8 @@ private void newMessagesArrived(IEnumerable newMessages) if (!IsLoaded) return; - if (scroll.IsScrolledToEnd(10) || !flow.Children.Any()) - ScrollToEnd(); + if (scroll.IsScrolledToEnd(10) || !flow.Children.Any() || newMessages.Any(m => m.GetType() == typeof(LocalEchoMessage))) + scrollToEnd(); var staleMessages = flow.Children.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); int count = staleMessages.Length - Channel.MAX_HISTORY; @@ -118,7 +118,7 @@ private void messageRemoved(Message removed) flow.Children.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); } - public void ScrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); + private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd()); private class ChatLineContainer : FillFlowContainer { diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index f86c5204bb..8e20d76914 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -475,8 +475,6 @@ private void postMessage(TextBox textbox, bool newText) if (target == null) return; - currentChannelContainer.Child.ScrollToEnd(); - if (!api.IsLoggedIn) { target.AddNewMessages(new ErrorMessage("Please sign in to participate in chat!")); From b4ef3dd4dd970e55a7c29c02d6903751762d1507 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 3 Aug 2018 20:02:12 +0900 Subject: [PATCH 3/3] Add LocalMessage --- osu.Game/Online/Chat/InfoMessage.cs | 2 +- osu.Game/Online/Chat/LocalEchoMessage.cs | 2 +- osu.Game/Online/Chat/LocalMessage.cs | 16 ++++++++++++++++ osu.Game/Overlays/Chat/DrawableChannel.cs | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Online/Chat/LocalMessage.cs diff --git a/osu.Game/Online/Chat/InfoMessage.cs b/osu.Game/Online/Chat/InfoMessage.cs index 2be025e403..2ff901deb1 100644 --- a/osu.Game/Online/Chat/InfoMessage.cs +++ b/osu.Game/Online/Chat/InfoMessage.cs @@ -6,7 +6,7 @@ namespace osu.Game.Online.Chat { - public class InfoMessage : Message + public class InfoMessage : LocalMessage { private static int infoID = -1; diff --git a/osu.Game/Online/Chat/LocalEchoMessage.cs b/osu.Game/Online/Chat/LocalEchoMessage.cs index 2e90b9d3fd..7d678029aa 100644 --- a/osu.Game/Online/Chat/LocalEchoMessage.cs +++ b/osu.Game/Online/Chat/LocalEchoMessage.cs @@ -3,7 +3,7 @@ namespace osu.Game.Online.Chat { - public class LocalEchoMessage : Message + public class LocalEchoMessage : LocalMessage { public LocalEchoMessage() : base(null) { diff --git a/osu.Game/Online/Chat/LocalMessage.cs b/osu.Game/Online/Chat/LocalMessage.cs new file mode 100644 index 0000000000..93f1e7f9ea --- /dev/null +++ b/osu.Game/Online/Chat/LocalMessage.cs @@ -0,0 +1,16 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Online.Chat +{ + /// + /// A message which is generated and displayed locally. + /// + public class LocalMessage : Message + { + protected LocalMessage(long? id) + : base(id) + { + } + } +} diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 4586d4d87c..c57e71b5ad 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -85,7 +85,7 @@ private void newMessagesArrived(IEnumerable newMessages) if (!IsLoaded) return; - if (scroll.IsScrolledToEnd(10) || !flow.Children.Any() || newMessages.Any(m => m.GetType() == typeof(LocalEchoMessage))) + if (scroll.IsScrolledToEnd(10) || !flow.Children.Any() || newMessages.Any(m => m is LocalMessage)) scrollToEnd(); var staleMessages = flow.Children.Where(c => c.LifetimeEnd == double.MaxValue).ToArray();