2022-03-15 02:31:13 +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-03-20 05:36:11 +08:00
|
|
|
using System.Linq;
|
2022-03-15 02:31:13 +08:00
|
|
|
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;
|
2022-03-20 00:44:58 +08:00
|
|
|
using osu.Game.Graphics;
|
2022-03-15 02:31:13 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-03-20 00:44:58 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-03-15 02:31:13 +08:00
|
|
|
using osu.Game.Online.Chat;
|
2022-03-20 05:36:11 +08:00
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
using osuTK;
|
2022-03-15 02:31:13 +08:00
|
|
|
|
2022-03-20 05:49:14 +08:00
|
|
|
namespace osu.Game.Overlays.Chat.ChannelList
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2022-03-20 05:49:14 +08:00
|
|
|
public class ChannelListItem : OsuClickableContainer
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
public event Action<Channel>? OnRequestSelect;
|
|
|
|
public event Action<Channel>? OnRequestLeave;
|
|
|
|
|
2022-03-15 05:26:33 +08:00
|
|
|
public readonly BindableInt Mentions = new BindableInt();
|
2022-03-15 02:31:13 +08:00
|
|
|
|
2022-03-15 05:32:30 +08:00
|
|
|
public readonly BindableBool Unread = new BindableBool();
|
2022-03-15 02:31:13 +08:00
|
|
|
|
2022-03-15 04:14:04 +08:00
|
|
|
private readonly Channel channel;
|
|
|
|
|
2022-03-15 02:31:13 +08:00
|
|
|
private Box? hoverBox;
|
|
|
|
private Box? selectBox;
|
2022-03-20 00:44:58 +08:00
|
|
|
private OsuSpriteText? text;
|
2022-03-21 13:15:22 +08:00
|
|
|
private ChannelListItemCloseButton? close;
|
2022-03-15 02:31:13 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-03-15 04:14:04 +08:00
|
|
|
private Bindable<Channel> selectedChannel { get; set; } = null!;
|
2022-03-15 02:31:13 +08:00
|
|
|
|
2022-03-20 00:44:58 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
2022-03-20 05:49:14 +08:00
|
|
|
public ChannelListItem(Channel channel)
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
this.channel = channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-03-20 00:44:58 +08:00
|
|
|
private void load()
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
Height = 30;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
hoverBox = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-03-15 04:14:04 +08:00
|
|
|
Colour = colourProvider.Background3,
|
2022-03-15 02:31:13 +08:00
|
|
|
Alpha = 0f,
|
|
|
|
},
|
|
|
|
selectBox = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-03-15 04:14:04 +08:00
|
|
|
Colour = colourProvider.Background4,
|
2022-03-15 02:31:13 +08:00
|
|
|
Alpha = 0f,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-03-15 05:39:57 +08:00
|
|
|
Padding = new MarginPadding { Left = 18, Right = 10 },
|
2022-03-15 02:31:13 +08:00
|
|
|
Child = new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
2022-03-15 03:42:55 +08:00
|
|
|
new[]
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2022-03-18 13:03:52 +08:00
|
|
|
createIcon(),
|
2022-03-20 00:44:58 +08:00
|
|
|
text = new OsuSpriteText
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-03-21 13:36:55 +08:00
|
|
|
Text = channel.Name,
|
2022-03-20 00:44:58 +08:00
|
|
|
Font = OsuFont.Torus.With(size: 17, weight: FontWeight.SemiBold),
|
|
|
|
Colour = colourProvider.Light3,
|
|
|
|
Margin = new MarginPadding { Bottom = 2 },
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Truncate = true,
|
2022-03-15 02:31:13 +08:00
|
|
|
},
|
2022-03-21 13:15:22 +08:00
|
|
|
new ChannelListItemMentionPill
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Margin = new MarginPadding { Right = 3 },
|
2022-03-16 06:33:36 +08:00
|
|
|
Mentions = { BindTarget = Mentions },
|
2022-03-15 02:31:13 +08:00
|
|
|
},
|
2022-03-21 13:15:22 +08:00
|
|
|
close = new ChannelListItemCloseButton
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Margin = new MarginPadding { Right = 3 },
|
2022-03-16 06:19:58 +08:00
|
|
|
Action = () => OnRequestLeave?.Invoke(channel),
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-03-16 06:19:58 +08:00
|
|
|
|
|
|
|
Action = () => OnRequestSelect?.Invoke(channel);
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-03-15 04:14:04 +08:00
|
|
|
selectedChannel.BindValueChanged(change =>
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
if (change.NewValue == channel)
|
2022-03-21 13:41:42 +08:00
|
|
|
selectBox?.FadeIn(300, Easing.OutQuint);
|
2022-03-15 02:31:13 +08:00
|
|
|
else
|
2022-03-21 13:41:42 +08:00
|
|
|
selectBox?.FadeOut(200, Easing.OutQuint);
|
2022-03-15 02:31:13 +08:00
|
|
|
}, true);
|
2022-03-20 00:44:58 +08:00
|
|
|
|
|
|
|
Unread.BindValueChanged(change =>
|
|
|
|
{
|
2022-03-21 13:34:54 +08:00
|
|
|
text!.FadeColour(change.NewValue ? colourProvider.Content1 : colourProvider.Light3, 300, Easing.OutQuint);
|
2022-03-20 00:44:58 +08:00
|
|
|
}, true);
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2022-03-21 13:28:12 +08:00
|
|
|
hoverBox?.FadeIn(300, Easing.OutQuint);
|
|
|
|
close?.FadeIn(300, Easing.OutQuint);
|
2022-03-15 02:31:13 +08:00
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
2022-03-21 13:28:12 +08:00
|
|
|
hoverBox?.FadeOut(200, Easing.OutQuint);
|
|
|
|
close?.FadeOut(200, Easing.OutQuint);
|
2022-03-15 02:31:13 +08:00
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
2022-03-18 13:03:52 +08:00
|
|
|
private Drawable createIcon()
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
if (channel.Type != ChannelType.PM)
|
|
|
|
return Drawable.Empty();
|
|
|
|
|
2022-03-20 06:20:17 +08:00
|
|
|
return new UpdateableAvatar(channel.Users.First(), isInteractive: false)
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2022-03-20 05:36:11 +08:00
|
|
|
Size = new Vector2(20),
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
2022-03-15 02:31:13 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-03-20 05:36:11 +08:00
|
|
|
CornerRadius = 10,
|
|
|
|
Masking = true,
|
2022-03-15 02:31:13 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|