1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 04:32:55 +08:00
osu-lazer/osu.Game/Overlays/Chat/ChannelList/ChannelListItem.cs
Jai Sharma ae5b6c3e10 Use dummy channel to show selector and remove ChannelListSelector
Add dummy channel `DummySelectorChannel` which should be set as the
current channel in the channel manager when the selector in the chat
overlay should be shown.

Refactors the `ChannelListItem` to not show mention pill and close
button when the channel is the dummy selector channel.

Ensure that the `ChannelList` selects the dummy channel on clicking the
selector item.

Removes `ChannelListSelector` as it is no longer needed.

Removes the `setCurrent` parameter from `ChannelManager.JoinChannel`
method as it is no longer needed.
2022-05-15 20:24:49 +01:00

201 lines
6.4 KiB
C#

// 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;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osu.Game.Users.Drawables;
using osuTK;
namespace osu.Game.Overlays.Chat.ChannelList
{
public class ChannelListItem : OsuClickableContainer
{
public event Action<Channel>? OnRequestSelect;
public event Action<Channel>? OnRequestLeave;
public readonly Channel Channel;
public readonly BindableInt Mentions = new BindableInt();
public readonly BindableBool Unread = new BindableBool();
private Box hoverBox = null!;
private Box selectBox = null!;
private OsuSpriteText text = null!;
private Drawable close = null!;
[Resolved]
private Bindable<Channel> selectedChannel { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
public ChannelListItem(Channel channel)
{
Channel = channel;
}
[BackgroundDependencyLoader]
private void load()
{
Height = 30;
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
hoverBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3,
Alpha = 0f,
},
selectBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
Alpha = 0f,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 18, Right = 10 },
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new[]
{
createIcon(),
text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = Channel.Name,
Font = OsuFont.Torus.With(size: 17, weight: FontWeight.SemiBold),
Colour = colourProvider.Light3,
Margin = new MarginPadding { Bottom = 2 },
RelativeSizeAxes = Axes.X,
Truncate = true,
},
createMentionPill(),
close = createCloseButton(),
}
},
},
},
};
Action = () => OnRequestSelect?.Invoke(Channel);
}
protected override void LoadComplete()
{
base.LoadComplete();
selectedChannel.BindValueChanged(_ => updateState(), true);
Unread.BindValueChanged(_ => updateState(), true);
}
protected override bool OnHover(HoverEvent e)
{
hoverBox.FadeIn(300, Easing.OutQuint);
if (!isSelector)
close.FadeIn(300, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hoverBox.FadeOut(200, Easing.OutQuint);
if (!isSelector)
close.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e);
}
private Drawable createIcon()
{
if (Channel.Type != ChannelType.PM)
return Drawable.Empty();
return new UpdateableAvatar(Channel.Users.First(), isInteractive: false)
{
Size = new Vector2(20),
Margin = new MarginPadding { Right = 5 },
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
CornerRadius = 10,
Masking = true,
};
}
private Drawable createMentionPill()
{
if (isSelector)
return Drawable.Empty();
return new ChannelListItemMentionPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Mentions = { BindTarget = Mentions },
};
}
private Drawable createCloseButton()
{
if (isSelector)
return Drawable.Empty();
return new ChannelListItemCloseButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Action = () => OnRequestLeave?.Invoke(Channel),
};
}
private void updateState()
{
bool selected = selectedChannel.Value == Channel || (isSelector && selectedChannel.Value == null);
if (selected)
selectBox.FadeIn(300, Easing.OutQuint);
else
selectBox.FadeOut(200, Easing.OutQuint);
if (Unread.Value || selected)
text.FadeColour(colourProvider.Content1, 300, Easing.OutQuint);
else
text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint);
}
private bool isSelector => Channel is DummySelectorChannel;
}
}