1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 02:22:57 +08:00

Support read-only channels, post to correct channel.

Also cache drawable channels better.
This commit is contained in:
Dean Herbert 2017-05-11 23:51:26 +09:00
parent a77049213d
commit ffa59c6cb3
3 changed files with 22 additions and 8 deletions

View File

@ -27,6 +27,8 @@ namespace osu.Game.Online.Chat
//internal bool Joined; //internal bool Joined;
public bool ReadOnly => Name != "#lazer";
public const int MAX_HISTORY = 300; public const int MAX_HISTORY = 300;
[JsonConstructor] [JsonConstructor]

View File

@ -13,13 +13,13 @@ namespace osu.Game.Online.Chat.Drawables
{ {
public class DrawableChannel : Container public class DrawableChannel : Container
{ {
private readonly Channel channel; public readonly Channel Channel;
private readonly FillFlowContainer flow; private readonly FillFlowContainer flow;
private readonly ScrollContainer scroll; private readonly ScrollContainer scroll;
public DrawableChannel(Channel channel) public DrawableChannel(Channel channel)
{ {
this.channel = channel; Channel = channel;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -48,14 +48,14 @@ namespace osu.Game.Online.Chat.Drawables
{ {
base.LoadComplete(); base.LoadComplete();
newMessagesArrived(channel.Messages); newMessagesArrived(Channel.Messages);
scrollToEnd(); scrollToEnd();
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
channel.NewMessagesArrived -= newMessagesArrived; Channel.NewMessagesArrived -= newMessagesArrived;
} }
private void newMessagesArrived(IEnumerable<Message> newMessages) private void newMessagesArrived(IEnumerable<Message> newMessages)

View File

@ -142,10 +142,14 @@ namespace osu.Game.Overlays
private List<Channel> careChannels; private List<Channel> careChannels;
private List<DrawableChannel> loadedChannels = new List<DrawableChannel>();
private void initializeChannels() private void initializeChannels()
{ {
currentChannelContainer.Clear(); currentChannelContainer.Clear();
loadedChannels.Clear();
careChannels = new List<Channel>(); careChannels = new List<Channel>();
SpriteText loading; SpriteText loading;
@ -167,6 +171,7 @@ namespace osu.Game.Overlays
Scheduler.Add(delegate Scheduler.Add(delegate
{ {
loading.FadeOut(100); loading.FadeOut(100);
addChannel(channels.Find(c => c.Name == @"#lazer")); addChannel(channels.Find(c => c.Name == @"#lazer"));
addChannel(channels.Find(c => c.Name == @"#osu")); addChannel(channels.Find(c => c.Name == @"#osu"));
addChannel(channels.Find(c => c.Name == @"#lobby")); addChannel(channels.Find(c => c.Name == @"#lobby"));
@ -192,10 +197,17 @@ namespace osu.Game.Overlays
if (currentChannel == value) return; if (currentChannel == value) return;
if (currentChannel != null) if (currentChannel != null)
currentChannelContainer.Clear(); currentChannelContainer.Clear(false);
currentChannel = value; 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; channelTabs.Current.Value = value;
} }
@ -203,6 +215,8 @@ namespace osu.Game.Overlays
private void addChannel(Channel channel) private void addChannel(Channel channel)
{ {
if (channel == null) return;
careChannels.Add(channel); careChannels.Add(channel);
channelTabs.AddItem(channel); channelTabs.AddItem(channel);
@ -246,8 +260,6 @@ namespace osu.Game.Overlays
if (!string.IsNullOrEmpty(postText) && api.LocalUser.Value != null) if (!string.IsNullOrEmpty(postText) && api.LocalUser.Value != null)
{ {
var currentChannel = careChannels.FirstOrDefault();
if (currentChannel == null) return; if (currentChannel == null) return;
var message = new Message var message = new Message