1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 08:13:31 +08:00

Add basic hard-coded inefficient multi-channel support.

This commit is contained in:
Dean Herbert 2017-05-11 23:10:48 +09:00
parent f044b95ce8
commit a77049213d
3 changed files with 54 additions and 21 deletions

View File

@ -53,5 +53,7 @@ namespace osu.Game.Online.Chat
if (messageCount > MAX_HISTORY) if (messageCount > MAX_HISTORY)
Messages.RemoveRange(0, messageCount - MAX_HISTORY); Messages.RemoveRange(0, messageCount - MAX_HISTORY);
} }
public override string ToString() => Name;
} }
} }

View File

@ -25,14 +25,6 @@ namespace osu.Game.Online.Chat.Drawables
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuSpriteText
{
Text = channel.Name,
TextSize = 50,
Alpha = 0.3f,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
scroll = new ScrollContainer scroll = new ScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -93,4 +85,4 @@ namespace osu.Game.Online.Chat.Drawables
private void scrollToEnd() => Scheduler.AddDelayed(() => scroll.ScrollToEnd(), 50); private void scrollToEnd() => Scheduler.AddDelayed(() => scroll.ScrollToEnd(), 50);
} }
} }

View File

@ -30,9 +30,7 @@ namespace osu.Game.Overlays
private ScheduledDelegate messageRequest; private ScheduledDelegate messageRequest;
private readonly Container content; private readonly Container currentChannelContainer;
protected override Container<Drawable> Content => content;
private readonly FocusedTextBox inputTextBox; private readonly FocusedTextBox inputTextBox;
@ -42,6 +40,8 @@ namespace osu.Game.Overlays
private GetMessagesRequest fetchReq; private GetMessagesRequest fetchReq;
private readonly OsuTabControl<Channel> channelTabs;
public ChatOverlay() public ChatOverlay()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -49,8 +49,13 @@ namespace osu.Game.Overlays
Anchor = Anchor.BottomLeft; Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft; Origin = Anchor.BottomLeft;
AddInternal(new Drawable[] Children = new Drawable[]
{ {
channelTabs = new OsuTabControl<Channel>()
{
RelativeSizeAxes = Axes.X,
Height = 20,
},
new Box new Box
{ {
Depth = float.MaxValue, Depth = float.MaxValue,
@ -58,10 +63,10 @@ namespace osu.Game.Overlays
Colour = Color4.Black, Colour = Color4.Black,
Alpha = 0.9f, Alpha = 0.9f,
}, },
content = new Container currentChannelContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 5, Bottom = textbox_height + 5 }, Padding = new MarginPadding { Top = 25, Bottom = textbox_height + 5 },
}, },
new Container new Container
{ {
@ -83,7 +88,9 @@ namespace osu.Game.Overlays
} }
} }
} }
}); };
channelTabs.Current.ValueChanged += newChannel => CurrentChannel = newChannel;
} }
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(APIAccess api, APIState state)
@ -137,7 +144,7 @@ namespace osu.Game.Overlays
private void initializeChannels() private void initializeChannels()
{ {
Clear(); currentChannelContainer.Clear();
careChannels = new List<Channel>(); careChannels = new List<Channel>();
@ -161,24 +168,56 @@ namespace osu.Game.Overlays
{ {
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 == @"#lobby"));
}); });
messageRequest = Scheduler.AddDelayed(fetchNewMessages, 1000, true); messageRequest = Scheduler.AddDelayed(() => fetchNewMessages(), 1000, true);
}; };
api.Queue(req); 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) private void addChannel(Channel channel)
{ {
Add(new DrawableChannel(channel));
careChannels.Add(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; if (fetchReq != null) return;
fetchReq = new GetMessagesRequest(careChannels, lastMessageId); fetchReq = new GetMessagesRequest(specificChannel != null ? new List<Channel> { specificChannel } : careChannels, lastMessageId);
fetchReq.Success += delegate (List<Message> messages) fetchReq.Success += delegate (List<Message> messages)
{ {
var ids = messages.Where(m => m.TargetType == TargetType.Channel).Select(m => m.TargetId).Distinct(); var ids = messages.Where(m => m.TargetType == TargetType.Channel).Select(m => m.TargetId).Distinct();