From f044b95ce81d9822ae6e08e70939794b21c8e20d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 23:10:19 +0900 Subject: [PATCH 1/5] Allow OsuTabControl to handle non-enum types. --- osu.Game/Graphics/UserInterface/OsuTabControl.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 242a9a8f6a..8b72eedbfd 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -25,15 +25,15 @@ namespace osu.Game.Graphics.UserInterface protected override bool InternalContains(Vector2 screenSpacePos) => base.InternalContains(screenSpacePos) || Dropdown.Contains(screenSpacePos); + private bool isEnumType => typeof(T).IsEnum; + public OsuTabControl() { TabContainer.Spacing = new Vector2(10f, 0f); - if (!typeof(T).IsEnum) - throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument"); - - foreach (var val in (T[])Enum.GetValues(typeof(T))) - AddItem(val); + if (isEnumType) + foreach (var val in (T[])Enum.GetValues(typeof(T))) + AddItem(val); } [BackgroundDependencyLoader] @@ -136,7 +136,7 @@ namespace osu.Game.Graphics.UserInterface Margin = new MarginPadding { Top = 5, Bottom = 5 }, Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, - Text = (value as Enum)?.GetDescription(), + Text = (value as Enum)?.GetDescription() ?? value.ToString(), TextSize = 14, Font = @"Exo2.0-Bold", // Font should only turn bold when active? }, From a77049213dc51b98c793af5765a5a14da21d7b2f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 23:10:48 +0900 Subject: [PATCH 2/5] Add basic hard-coded inefficient multi-channel support. --- osu.Game/Online/Chat/Channel.cs | 2 + .../Online/Chat/Drawables/DrawableChannel.cs | 10 +-- osu.Game/Overlays/ChatOverlay.cs | 63 +++++++++++++++---- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index d3bd57a1c9..6b43010776 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -53,5 +53,7 @@ namespace osu.Game.Online.Chat if (messageCount > MAX_HISTORY) Messages.RemoveRange(0, messageCount - MAX_HISTORY); } + + public override string ToString() => Name; } } diff --git a/osu.Game/Online/Chat/Drawables/DrawableChannel.cs b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs index e3101e8fd7..8268ab41c5 100644 --- a/osu.Game/Online/Chat/Drawables/DrawableChannel.cs +++ b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs @@ -25,14 +25,6 @@ namespace osu.Game.Online.Chat.Drawables Children = new Drawable[] { - new OsuSpriteText - { - Text = channel.Name, - TextSize = 50, - Alpha = 0.3f, - Anchor = Anchor.Centre, - Origin = Anchor.Centre - }, scroll = new ScrollContainer { RelativeSizeAxes = Axes.Both, @@ -93,4 +85,4 @@ namespace osu.Game.Online.Chat.Drawables private void scrollToEnd() => Scheduler.AddDelayed(() => scroll.ScrollToEnd(), 50); } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index dc586bd363..77c9f36af5 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -30,9 +30,7 @@ namespace osu.Game.Overlays private ScheduledDelegate messageRequest; - private readonly Container content; - - protected override Container Content => content; + private readonly Container currentChannelContainer; private readonly FocusedTextBox inputTextBox; @@ -42,6 +40,8 @@ namespace osu.Game.Overlays private GetMessagesRequest fetchReq; + private readonly OsuTabControl channelTabs; + public ChatOverlay() { RelativeSizeAxes = Axes.X; @@ -49,8 +49,13 @@ namespace osu.Game.Overlays Anchor = Anchor.BottomLeft; Origin = Anchor.BottomLeft; - AddInternal(new Drawable[] + Children = new Drawable[] { + channelTabs = new OsuTabControl() + { + RelativeSizeAxes = Axes.X, + Height = 20, + }, new Box { Depth = float.MaxValue, @@ -58,10 +63,10 @@ namespace osu.Game.Overlays Colour = Color4.Black, Alpha = 0.9f, }, - content = new Container + currentChannelContainer = new Container { RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Top = 5, Bottom = textbox_height + 5 }, + Padding = new MarginPadding { Top = 25, Bottom = textbox_height + 5 }, }, new Container { @@ -83,7 +88,9 @@ namespace osu.Game.Overlays } } } - }); + }; + + channelTabs.Current.ValueChanged += newChannel => CurrentChannel = newChannel; } public void APIStateChanged(APIAccess api, APIState state) @@ -137,7 +144,7 @@ namespace osu.Game.Overlays private void initializeChannels() { - Clear(); + currentChannelContainer.Clear(); careChannels = new List(); @@ -161,24 +168,56 @@ namespace osu.Game.Overlays { loading.FadeOut(100); addChannel(channels.Find(c => c.Name == @"#lazer")); + addChannel(channels.Find(c => c.Name == @"#osu")); + addChannel(channels.Find(c => c.Name == @"#lobby")); }); - messageRequest = Scheduler.AddDelayed(fetchNewMessages, 1000, true); + messageRequest = Scheduler.AddDelayed(() => fetchNewMessages(), 1000, true); }; + api.Queue(req); } + private Channel currentChannel; + + protected Channel CurrentChannel + { + get + { + return currentChannel; + } + + set + { + if (currentChannel == value) return; + + if (currentChannel != null) + currentChannelContainer.Clear(); + + currentChannel = value; + currentChannelContainer.Add(new DrawableChannel(currentChannel)); + + channelTabs.Current.Value = value; + } + } + private void addChannel(Channel channel) { - Add(new DrawableChannel(channel)); careChannels.Add(channel); + channelTabs.AddItem(channel); + + // we need to get a good number of messages initially for each channel we care about. + fetchNewMessages(channel); + + if (CurrentChannel == null) + CurrentChannel = channel; } - private void fetchNewMessages() + private void fetchNewMessages(Channel specificChannel = null) { if (fetchReq != null) return; - fetchReq = new GetMessagesRequest(careChannels, lastMessageId); + fetchReq = new GetMessagesRequest(specificChannel != null ? new List { specificChannel } : careChannels, lastMessageId); fetchReq.Success += delegate (List messages) { var ids = messages.Where(m => m.TargetType == TargetType.Channel).Select(m => m.TargetId).Distinct(); From ffa59c6cb3a0cd7fa9036e008cfbb78ee24fb3ee Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 23:51:26 +0900 Subject: [PATCH 3/5] Support read-only channels, post to correct channel. Also cache drawable channels better. --- osu.Game/Online/Chat/Channel.cs | 2 ++ .../Online/Chat/Drawables/DrawableChannel.cs | 8 ++++---- osu.Game/Overlays/ChatOverlay.cs | 20 +++++++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index 6b43010776..d159f482a9 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -27,6 +27,8 @@ namespace osu.Game.Online.Chat //internal bool Joined; + public bool ReadOnly => Name != "#lazer"; + public const int MAX_HISTORY = 300; [JsonConstructor] diff --git a/osu.Game/Online/Chat/Drawables/DrawableChannel.cs b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs index 8268ab41c5..870f67a01e 100644 --- a/osu.Game/Online/Chat/Drawables/DrawableChannel.cs +++ b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs @@ -13,13 +13,13 @@ namespace osu.Game.Online.Chat.Drawables { public class DrawableChannel : Container { - private readonly Channel channel; + public readonly Channel Channel; private readonly FillFlowContainer flow; private readonly ScrollContainer scroll; public DrawableChannel(Channel channel) { - this.channel = channel; + Channel = channel; RelativeSizeAxes = Axes.Both; @@ -48,14 +48,14 @@ namespace osu.Game.Online.Chat.Drawables { base.LoadComplete(); - newMessagesArrived(channel.Messages); + newMessagesArrived(Channel.Messages); scrollToEnd(); } protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - channel.NewMessagesArrived -= newMessagesArrived; + Channel.NewMessagesArrived -= newMessagesArrived; } private void newMessagesArrived(IEnumerable newMessages) diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 77c9f36af5..05239082ef 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -142,10 +142,14 @@ namespace osu.Game.Overlays private List careChannels; + private List loadedChannels = new List(); + private void initializeChannels() { currentChannelContainer.Clear(); + loadedChannels.Clear(); + careChannels = new List(); SpriteText loading; @@ -167,6 +171,7 @@ namespace osu.Game.Overlays Scheduler.Add(delegate { loading.FadeOut(100); + addChannel(channels.Find(c => c.Name == @"#lazer")); addChannel(channels.Find(c => c.Name == @"#osu")); addChannel(channels.Find(c => c.Name == @"#lobby")); @@ -192,10 +197,17 @@ namespace osu.Game.Overlays if (currentChannel == value) return; if (currentChannel != null) - currentChannelContainer.Clear(); + currentChannelContainer.Clear(false); currentChannel = value; - currentChannelContainer.Add(new DrawableChannel(currentChannel)); + + var loaded = loadedChannels.Find(d => d.Channel == value); + if (loaded == null) + loadedChannels.Add(loaded = new DrawableChannel(currentChannel)); + + inputTextBox.Current.Disabled = currentChannel.ReadOnly; + + currentChannelContainer.Add(loaded); channelTabs.Current.Value = value; } @@ -203,6 +215,8 @@ namespace osu.Game.Overlays private void addChannel(Channel channel) { + if (channel == null) return; + careChannels.Add(channel); channelTabs.AddItem(channel); @@ -246,8 +260,6 @@ namespace osu.Game.Overlays if (!string.IsNullOrEmpty(postText) && api.LocalUser.Value != null) { - var currentChannel = careChannels.FirstOrDefault(); - if (currentChannel == null) return; var message = new Message From f248efb01f5cdc8b6a1747bd1a179fb981fbe7d9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 May 2017 13:25:50 +0900 Subject: [PATCH 4/5] CI Fixes --- osu.Game/Online/Chat/Drawables/DrawableChannel.cs | 1 - osu.Game/Overlays/ChatOverlay.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/Chat/Drawables/DrawableChannel.cs b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs index 870f67a01e..d179f851b2 100644 --- a/osu.Game/Online/Chat/Drawables/DrawableChannel.cs +++ b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs @@ -7,7 +7,6 @@ using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; -using osu.Game.Graphics.Sprites; namespace osu.Game.Online.Chat.Drawables { diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 05239082ef..75ddcd89b6 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -51,7 +51,7 @@ namespace osu.Game.Overlays Children = new Drawable[] { - channelTabs = new OsuTabControl() + channelTabs = new OsuTabControl { RelativeSizeAxes = Axes.X, Height = 20, @@ -142,7 +142,7 @@ namespace osu.Game.Overlays private List careChannels; - private List loadedChannels = new List(); + private readonly List loadedChannels = new List(); private void initializeChannels() { From 1420aa406c8d12ba8d4b8ee0c3fa4adb3fb1f181 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 May 2017 14:24:32 +0900 Subject: [PATCH 5/5] Add framework fix. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 682f078b2e..fcf36739bc 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 682f078b2efc82fa19342f499f14c4a8458843d5 +Subproject commit fcf36739bc8a97b43a08ce0b29bd7c67ce1a3547