From ffa59c6cb3a0cd7fa9036e008cfbb78ee24fb3ee Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 23:51:26 +0900 Subject: [PATCH] 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