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-20 05:49:14 +08:00
|
|
|
private ChannelListItemClose? 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-20 00:44:58 +08:00
|
|
|
Text = channel.Type == ChannelType.Public ? $"# {channel.Name.Substring(1)}" : channel.Name,
|
|
|
|
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-20 05:49:14 +08:00
|
|
|
new ChannelListItemMention
|
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-20 05:49:14 +08:00
|
|
|
close = new ChannelListItemClose
|
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)
|
|
|
|
selectBox?.Show();
|
|
|
|
else
|
|
|
|
selectBox?.Hide();
|
|
|
|
}, true);
|
2022-03-20 00:44:58 +08:00
|
|
|
|
|
|
|
Unread.BindValueChanged(change =>
|
|
|
|
{
|
|
|
|
text!.Colour = change.NewValue ? colourProvider.Content1 : colourProvider.Light3;
|
|
|
|
}, true);
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
hoverBox?.Show();
|
|
|
|
close?.Show();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
hoverBox?.Hide();
|
|
|
|
close?.Hide();
|
|
|
|
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 05:36:11 +08:00
|
|
|
return new UpdateableAvatar(channel.Users.First(), false, false, true)
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|