From 49ab031e75f0398ed321b0664d68acee9aba5b31 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 25 May 2022 18:42:49 +0900 Subject: [PATCH] Allow traversing in both directions using ctrl-tab shortcuts --- osu.Game/Overlays/ChatOverlayV2.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/osu.Game/Overlays/ChatOverlayV2.cs b/osu.Game/Overlays/ChatOverlayV2.cs index a23595e1c0..d0355e0165 100644 --- a/osu.Game/Overlays/ChatOverlayV2.cs +++ b/osu.Game/Overlays/ChatOverlayV2.cs @@ -215,8 +215,12 @@ namespace osu.Game.Overlays channelManager.JoinLastClosedChannel(); return true; + case PlatformAction.DocumentPrevious: + cycleChannel(-1); + return true; + case PlatformAction.DocumentNext: - cycleChannel(); + cycleChannel(1); return true; default: @@ -372,7 +376,6 @@ namespace osu.Game.Overlays private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs args) => channelListing.UpdateAvailableChannels(channelManager.AvailableChannels); - private void handleChatMessage(string message) { if (string.IsNullOrWhiteSpace(message)) @@ -384,21 +387,16 @@ namespace osu.Game.Overlays channelManager.PostMessage(message); } - private void cycleChannel() + private void cycleChannel(int direction) { - List overlayChannels = filterChannels(channelManager.JoinedChannels).ToList(); + List overlayChannels = filterToChatChannels(channelManager.JoinedChannels).ToList(); if (overlayChannels.Count < 2) return; - int currentIdx = overlayChannels.IndexOf(currentChannel.Value); - int nextIdx = currentIdx + 1; + int currentIndex = overlayChannels.IndexOf(currentChannel.Value); - // Cycle the list when reaching the end - if (nextIdx > overlayChannels.Count - 1) - nextIdx = 0; - - currentChannel.Value = overlayChannels[nextIdx]; + currentChannel.Value = overlayChannels[(currentIndex + direction + overlayChannels.Count) % overlayChannels.Count]; } private IEnumerable filterToChatChannels(IEnumerable channels) => channels.Cast().Where(c => c.Type != ChannelType.System);