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.
|
|
|
|
|
|
|
|
using System;
|
2024-10-22 17:36:00 +08:00
|
|
|
using System.Collections.Generic;
|
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;
|
2024-10-22 17:36:00 +08:00
|
|
|
using osu.Framework.Localisation;
|
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-05-19 18:26:14 +08:00
|
|
|
using osu.Game.Overlays.Chat.Listing;
|
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
|
|
|
{
|
2024-10-22 17:36:00 +08:00
|
|
|
public partial class ChannelListItem : OsuClickableContainer, IFilterable
|
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 02:12:43 +08:00
|
|
|
private Box hoverBox = null!;
|
|
|
|
private Box selectBox = null!;
|
|
|
|
private OsuSpriteText text = null!;
|
2022-05-18 08:35:39 +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
|
|
|
{
|
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
|
|
|
{
|
2024-05-03 12:31:19 +08:00
|
|
|
Height = 25;
|
2022-03-15 02:31:13 +08:00
|
|
|
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,
|
|
|
|
},
|
2024-02-21 04:18:37 +08:00
|
|
|
new GridContainer
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-03-15 05:39:57 +08:00
|
|
|
Padding = new MarginPadding { Left = 18, Right = 10 },
|
2024-02-21 04:18:37 +08:00
|
|
|
ColumnDimensions = new[]
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable?[]
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
createIcon(),
|
|
|
|
text = new TruncatingSpriteText
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Text = Channel.Name,
|
2024-05-03 12:31:19 +08:00
|
|
|
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
|
2024-02-21 04:18:37 +08:00
|
|
|
Colour = colourProvider.Light3,
|
|
|
|
Margin = new MarginPadding { Bottom = 2 },
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
},
|
|
|
|
createMentionPill(),
|
|
|
|
close = createCloseButton(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
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);
|
2022-05-18 01:52:19 +08:00
|
|
|
close?.FadeIn(300, Easing.OutQuint);
|
2022-05-16 02:38:37 +08:00
|
|
|
|
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);
|
2022-05-18 01:52:19 +08:00
|
|
|
close?.FadeOut(200, Easing.OutQuint);
|
2022-05-16 02:38:37 +08:00
|
|
|
|
2022-03-15 02:31:13 +08:00
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
2022-05-18 01:52:19 +08:00
|
|
|
private UpdateableAvatar? createIcon()
|
2022-03-15 02:31:13 +08:00
|
|
|
{
|
2022-04-30 04:33:32 +08:00
|
|
|
if (Channel.Type != ChannelType.PM)
|
2022-05-18 01:52:19 +08:00
|
|
|
return null;
|
2022-03-15 02:31:13 +08:00
|
|
|
|
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-18 01:52:19 +08:00
|
|
|
private ChannelListItemMentionPill? createMentionPill()
|
2022-05-16 02:38:37 +08:00
|
|
|
{
|
|
|
|
if (isSelector)
|
2022-05-18 01:52:19 +08:00
|
|
|
return null;
|
2022-05-16 02:38:37 +08:00
|
|
|
|
|
|
|
return new ChannelListItemMentionPill
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Margin = new MarginPadding { Right = 3 },
|
|
|
|
Mentions = { BindTarget = Mentions },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-18 01:52:19 +08:00
|
|
|
private ChannelListItemCloseButton? createCloseButton()
|
2022-05-16 02:38:37 +08:00
|
|
|
{
|
|
|
|
if (isSelector)
|
2022-05-18 01:52:19 +08:00
|
|
|
return null;
|
2022-05-16 02:38:37 +08:00
|
|
|
|
|
|
|
return new ChannelListItemCloseButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Margin = new MarginPadding { Right = 3 },
|
|
|
|
Action = () => OnRequestLeave?.Invoke(Channel),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-03 05:32:25 +08:00
|
|
|
private void updateState()
|
2022-04-21 02:12:43 +08:00
|
|
|
{
|
2022-05-19 18:45:39 +08:00
|
|
|
bool selected = selectedChannel.Value == Channel;
|
2022-05-04 20:00:11 +08:00
|
|
|
|
|
|
|
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-05-16 02:38:37 +08:00
|
|
|
|
2022-05-19 18:26:14 +08:00
|
|
|
private bool isSelector => Channel is ChannelListing.ChannelListingChannel;
|
2024-10-22 17:36:00 +08:00
|
|
|
|
|
|
|
#region Filtering support
|
|
|
|
|
|
|
|
public IEnumerable<LocalisableString> FilterTerms => isSelector ? Enumerable.Empty<LocalisableString>() : [Channel.Name];
|
|
|
|
|
|
|
|
private bool matchingFilter = true;
|
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
{
|
|
|
|
get => matchingFilter;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (matchingFilter == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
matchingFilter = value;
|
|
|
|
Alpha = matchingFilter ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool FilteringActive { get; set; }
|
|
|
|
|
|
|
|
#endregion
|
2022-03-15 02:31:13 +08:00
|
|
|
}
|
|
|
|
}
|