2022-04-15 22:38:47 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
using System;
|
2022-05-25 19:29:04 +08:00
|
|
|
using System.Linq;
|
2022-04-15 22:38:47 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
2022-05-27 13:23:03 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2022-04-15 22:38:47 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-05-27 13:23:03 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-04-15 22:38:47 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.Chat;
|
2022-05-19 18:26:14 +08:00
|
|
|
using osu.Game.Overlays.Chat.Listing;
|
2022-05-27 13:23:03 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-04-15 22:38:47 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Chat.ChannelList
|
|
|
|
{
|
|
|
|
public class ChannelList : Container
|
|
|
|
{
|
2022-05-16 02:38:37 +08:00
|
|
|
public Action<Channel>? OnRequestSelect;
|
2022-04-15 22:38:47 +08:00
|
|
|
public Action<Channel>? OnRequestLeave;
|
|
|
|
|
2022-05-30 00:58:27 +08:00
|
|
|
public IEnumerable<Channel> Channels => groupFlow.Children
|
|
|
|
.OfType<ChannelGroup>()
|
2022-05-30 00:56:37 +08:00
|
|
|
.SelectMany(channelGroup => channelGroup.ItemFlow)
|
|
|
|
.Select(item => item.Channel);
|
2022-05-25 19:29:04 +08:00
|
|
|
|
2022-05-19 18:45:39 +08:00
|
|
|
public readonly ChannelListing.ChannelListingChannel ChannelListingChannel = new ChannelListing.ChannelListingChannel();
|
2022-04-15 22:38:47 +08:00
|
|
|
|
2022-05-19 18:45:39 +08:00
|
|
|
private readonly Dictionary<Channel, ChannelListItem> channelMap = new Dictionary<Channel, ChannelListItem>();
|
2022-05-16 02:38:37 +08:00
|
|
|
|
2022-05-25 19:37:28 +08:00
|
|
|
private OsuScrollContainer scroll = null!;
|
2022-05-28 02:46:53 +08:00
|
|
|
private FillFlowContainer groupFlow = null!;
|
|
|
|
private ChannelGroup announceChannelGroup = null!;
|
|
|
|
private ChannelGroup publicChannelGroup = null!;
|
|
|
|
private ChannelGroup privateChannelGroup = null!;
|
2022-05-16 02:38:37 +08:00
|
|
|
private ChannelListItem selector = null!;
|
2022-04-15 22:38:47 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = colourProvider.Background6,
|
|
|
|
},
|
2022-05-25 19:37:28 +08:00
|
|
|
scroll = new OsuScrollContainer
|
2022-04-15 22:38:47 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-04-17 02:19:18 +08:00
|
|
|
ScrollbarAnchor = Anchor.TopRight,
|
2022-04-15 22:38:47 +08:00
|
|
|
ScrollDistance = 35f,
|
2022-05-28 02:46:53 +08:00
|
|
|
Child = groupFlow = new FillFlowContainer
|
2022-04-15 22:38:47 +08:00
|
|
|
{
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-05-28 02:46:53 +08:00
|
|
|
announceChannelGroup = new ChannelGroup(ChatStrings.ChannelsListTitleANNOUNCE.ToUpper()),
|
|
|
|
publicChannelGroup = new ChannelGroup(ChatStrings.ChannelsListTitlePUBLIC.ToUpper()),
|
2022-05-27 23:06:23 +08:00
|
|
|
selector = new ChannelListItem(ChannelListingChannel),
|
2022-05-28 02:46:53 +08:00
|
|
|
privateChannelGroup = new ChannelGroup(ChatStrings.ChannelsListTitlePM.ToUpper()),
|
2022-04-15 22:38:47 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-05-16 02:38:37 +08:00
|
|
|
|
|
|
|
selector.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan);
|
2022-04-15 22:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddChannel(Channel channel)
|
|
|
|
{
|
|
|
|
if (channelMap.ContainsKey(channel))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ChannelListItem item = new ChannelListItem(channel);
|
2022-04-16 05:05:20 +08:00
|
|
|
item.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan);
|
|
|
|
item.OnRequestLeave += chan => OnRequestLeave?.Invoke(chan);
|
2022-04-15 22:38:47 +08:00
|
|
|
|
2022-05-28 02:46:53 +08:00
|
|
|
FillFlowContainer<ChannelListItem> flow = getFlowForChannel(channel);
|
2022-04-15 22:38:47 +08:00
|
|
|
channelMap.Add(channel, item);
|
|
|
|
flow.Add(item);
|
2022-05-27 23:06:23 +08:00
|
|
|
|
|
|
|
updateVisibility();
|
2022-04-15 22:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveChannel(Channel channel)
|
|
|
|
{
|
|
|
|
if (!channelMap.ContainsKey(channel))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ChannelListItem item = channelMap[channel];
|
2022-05-28 02:46:53 +08:00
|
|
|
FillFlowContainer<ChannelListItem> flow = getFlowForChannel(channel);
|
2022-04-15 22:38:47 +08:00
|
|
|
|
|
|
|
channelMap.Remove(channel);
|
|
|
|
flow.Remove(item);
|
2022-05-27 23:06:23 +08:00
|
|
|
|
|
|
|
updateVisibility();
|
2022-04-15 22:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public ChannelListItem GetItem(Channel channel)
|
|
|
|
{
|
|
|
|
if (!channelMap.ContainsKey(channel))
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
|
|
return channelMap[channel];
|
|
|
|
}
|
|
|
|
|
2022-05-25 22:15:46 +08:00
|
|
|
public void ScrollChannelIntoView(Channel channel) => scroll.ScrollIntoView(GetItem(channel));
|
2022-05-25 19:37:28 +08:00
|
|
|
|
2022-05-28 02:46:53 +08:00
|
|
|
private FillFlowContainer<ChannelListItem> getFlowForChannel(Channel channel)
|
2022-04-15 22:38:47 +08:00
|
|
|
{
|
|
|
|
switch (channel.Type)
|
|
|
|
{
|
|
|
|
case ChannelType.Public:
|
2022-05-28 02:46:53 +08:00
|
|
|
return publicChannelGroup.ItemFlow;
|
2022-04-15 22:38:47 +08:00
|
|
|
|
|
|
|
case ChannelType.PM:
|
2022-05-28 02:46:53 +08:00
|
|
|
return privateChannelGroup.ItemFlow;
|
2022-04-15 22:38:47 +08:00
|
|
|
|
2022-05-27 23:06:23 +08:00
|
|
|
case ChannelType.Announce:
|
2022-05-28 02:46:53 +08:00
|
|
|
return announceChannelGroup.ItemFlow;
|
2022-05-27 23:06:23 +08:00
|
|
|
|
2022-04-15 22:38:47 +08:00
|
|
|
default:
|
2022-05-28 02:46:53 +08:00
|
|
|
return publicChannelGroup.ItemFlow;
|
2022-05-25 22:15:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:06:23 +08:00
|
|
|
private void updateVisibility()
|
|
|
|
{
|
2022-05-28 02:46:53 +08:00
|
|
|
if (announceChannelGroup.ItemFlow.Children.Count == 0)
|
|
|
|
announceChannelGroup.Hide();
|
2022-05-27 23:06:23 +08:00
|
|
|
else
|
2022-05-28 02:46:53 +08:00
|
|
|
announceChannelGroup.Show();
|
2022-05-27 23:06:23 +08:00
|
|
|
}
|
|
|
|
|
2022-05-28 02:46:53 +08:00
|
|
|
private class ChannelGroup : FillFlowContainer
|
2022-05-25 22:15:46 +08:00
|
|
|
{
|
2022-05-28 03:12:00 +08:00
|
|
|
public readonly FillFlowContainer<ChannelListItem> ItemFlow;
|
2022-05-25 19:29:04 +08:00
|
|
|
|
2022-05-28 02:46:53 +08:00
|
|
|
public ChannelGroup(LocalisableString label)
|
2022-04-15 22:38:47 +08:00
|
|
|
{
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2022-05-28 02:46:53 +08:00
|
|
|
Padding = new MarginPadding { Top = 8 };
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = label,
|
|
|
|
Margin = new MarginPadding { Left = 18, Bottom = 5 },
|
|
|
|
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold),
|
|
|
|
},
|
2022-05-28 03:12:00 +08:00
|
|
|
ItemFlow = new FillFlowContainer<ChannelListItem>
|
2022-05-28 02:46:53 +08:00
|
|
|
{
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
},
|
|
|
|
};
|
2022-04-15 22:38:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|