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-04-30 04:33:32 +08:00
|
|
|
public readonly Channel Channel;
|
|
|
|
|
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-04-21 04:05:33 +08:00
|
|
|
public readonly BindableBool SelectorActive = new BindableBool();
|
|
|
|
|
2022-04-21 02:12:43 +08:00
|
|
|
private Box hoverBox = null!;
|
|
|
|
private Box selectBox = null!;
|
|
|
|
private OsuSpriteText text = null!;
|
|
|
|
private ChannelListItemCloseButton close = null!;
|
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
|
|
|
{
|
2022-04-30 04:33:32 +08:00
|
|
|
Channel = channel;
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[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-04-30 04:33:32 +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-04-30 04:33:32 +08:00
|
|
|
Action = () => OnRequestLeave?.Invoke(Channel),
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-03-16 06:19:58 +08:00
|
|
|
|
2022-04-30 04:33:32 +08:00
|
|
|
Action = () => OnRequestSelect?.Invoke(Channel);
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-05-03 05:32:25 +08:00
|
|
|
selectedChannel.BindValueChanged(_ => updateState(), true);
|
|
|
|
SelectorActive.BindValueChanged(_ => updateState(), true);
|
|
|
|
Unread.BindValueChanged(_ => updateState(), true);
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2022-04-21 02:12:43 +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-04-21 02:12:43 +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
|
|
|
{
|
2022-04-30 04:33:32 +08:00
|
|
|
if (Channel.Type != ChannelType.PM)
|
2022-03-15 02:31:13 +08:00
|
|
|
return Drawable.Empty();
|
|
|
|
|
2022-04-30 04:33:32 +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
|
|
|
};
|
|
|
|
}
|
2022-04-21 02:12:43 +08:00
|
|
|
|
2022-05-03 05:32:25 +08:00
|
|
|
private void updateState()
|
2022-04-21 02:12:43 +08:00
|
|
|
{
|
2022-05-04 20:00:11 +08:00
|
|
|
bool selected = selectedChannel.Value == Channel && !SelectorActive.Value;
|
|
|
|
|
|
|
|
if (selected)
|
2022-04-21 02:12:43 +08:00
|
|
|
selectBox.FadeIn(300, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
selectBox.FadeOut(200, Easing.OutQuint);
|
2022-05-03 05:32:25 +08:00
|
|
|
|
2022-05-04 20:00:11 +08:00
|
|
|
if (Unread.Value || selected)
|
2022-05-03 05:32:25 +08:00
|
|
|
text.FadeColour(colourProvider.Content1, 300, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint);
|
2022-04-21 02:12:43 +08:00
|
|
|
}
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
}
|