2022-03-08 22:30:58 +00: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;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
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.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-05-16 05:09:37 +00:00
|
|
|
using osu.Framework.Localisation;
|
2022-03-08 22:30:58 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osuTK;
|
|
|
|
|
2022-03-09 18:13:56 +00:00
|
|
|
namespace osu.Game.Overlays.Chat.Listing
|
2022-03-08 22:30:58 +00:00
|
|
|
{
|
|
|
|
public class ChannelListingItem : OsuClickableContainer, IFilterable
|
|
|
|
{
|
|
|
|
public event Action<Channel>? OnRequestJoin;
|
|
|
|
public event Action<Channel>? OnRequestLeave;
|
|
|
|
|
2022-04-29 20:33:32 +00:00
|
|
|
public readonly Channel Channel;
|
|
|
|
|
2022-03-08 22:30:58 +00:00
|
|
|
public bool FilteringActive { get; set; }
|
2022-05-16 05:09:37 +00:00
|
|
|
public IEnumerable<LocalisableString> FilterTerms => new LocalisableString[] { Channel.Name, Channel.Topic ?? string.Empty };
|
2022-03-09 00:12:44 +00:00
|
|
|
public bool MatchingFilter { set => this.FadeTo(value ? 1f : 0f, 100); }
|
2022-03-08 22:30:58 +00:00
|
|
|
|
|
|
|
private Box hoverBox = null!;
|
|
|
|
private SpriteIcon checkbox = null!;
|
|
|
|
private OsuSpriteText channelText = null!;
|
2022-03-09 00:33:46 +00:00
|
|
|
private OsuSpriteText topicText = null!;
|
2022-03-08 22:30:58 +00:00
|
|
|
private IBindable<bool> channelJoined = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
2022-03-09 00:12:44 +00:00
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
2022-03-08 22:30:58 +00:00
|
|
|
|
2022-03-09 00:33:46 +00:00
|
|
|
private const float text_size = 18;
|
|
|
|
private const float icon_size = 14;
|
|
|
|
|
2022-03-10 06:58:19 +00:00
|
|
|
private const float vertical_margin = 1.5f;
|
|
|
|
|
2022-03-08 22:30:58 +00:00
|
|
|
public ChannelListingItem(Channel channel)
|
|
|
|
{
|
2022-04-29 20:33:32 +00:00
|
|
|
Channel = channel;
|
2022-03-09 00:12:44 +00:00
|
|
|
}
|
2022-03-08 22:30:58 +00:00
|
|
|
|
2022-03-09 00:12:44 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-03-08 22:30:58 +00:00
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 5;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2022-03-10 06:58:19 +00:00
|
|
|
Height = 20 + (vertical_margin * 2);
|
2022-03-08 22:30:58 +00:00
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
hoverBox = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-03-09 00:12:44 +00:00
|
|
|
Colour = colourProvider.Background3,
|
2022-03-10 06:58:19 +00:00
|
|
|
Margin = new MarginPadding { Vertical = vertical_margin },
|
2022-03-08 22:30:58 +00:00
|
|
|
Alpha = 0f,
|
|
|
|
},
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-03-09 00:12:44 +00:00
|
|
|
ColumnDimensions = new[]
|
2022-03-08 22:30:58 +00:00
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 40),
|
|
|
|
new Dimension(GridSizeMode.Absolute, 200),
|
|
|
|
new Dimension(GridSizeMode.Absolute, 400),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
checkbox = new SpriteIcon
|
|
|
|
{
|
2022-03-10 06:49:18 +00:00
|
|
|
Alpha = 0,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2022-03-08 22:30:58 +00:00
|
|
|
Icon = FontAwesome.Solid.Check,
|
2022-03-09 00:33:46 +00:00
|
|
|
Size = new Vector2(icon_size),
|
2022-03-08 22:30:58 +00:00
|
|
|
},
|
|
|
|
channelText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-04-29 20:33:32 +00:00
|
|
|
Text = Channel.Name,
|
2022-03-09 00:33:46 +00:00
|
|
|
Font = OsuFont.Torus.With(size: text_size, weight: FontWeight.SemiBold),
|
2022-03-08 22:30:58 +00:00
|
|
|
Margin = new MarginPadding { Bottom = 2 },
|
|
|
|
},
|
2022-03-09 00:33:46 +00:00
|
|
|
topicText = new OsuSpriteText
|
2022-03-08 22:30:58 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-04-29 20:33:32 +00:00
|
|
|
Text = Channel.Topic,
|
2022-03-09 00:33:46 +00:00
|
|
|
Font = OsuFont.Torus.With(size: text_size),
|
2022-03-08 22:30:58 +00:00
|
|
|
Margin = new MarginPadding { Bottom = 2 },
|
|
|
|
},
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Icon = FontAwesome.Solid.User,
|
2022-03-09 00:33:46 +00:00
|
|
|
Size = new Vector2(icon_size),
|
2022-03-08 22:30:58 +00:00
|
|
|
Margin = new MarginPadding { Right = 5 },
|
2022-03-09 00:12:44 +00:00
|
|
|
Colour = colourProvider.Light3,
|
2022-03-08 22:30:58 +00:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Text = "0",
|
2022-03-09 00:33:46 +00:00
|
|
|
Font = OsuFont.Torus.With(size: text_size),
|
2022-03-08 22:30:58 +00:00
|
|
|
Margin = new MarginPadding { Bottom = 2 },
|
2022-03-09 00:12:44 +00:00
|
|
|
Colour = colourProvider.Light3,
|
2022-03-08 22:30:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-03-09 00:12:44 +00:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-04-29 20:33:32 +00:00
|
|
|
channelJoined = Channel.Joined.GetBoundCopy();
|
2022-03-09 00:12:44 +00:00
|
|
|
channelJoined.BindValueChanged(change =>
|
|
|
|
{
|
2022-03-10 06:49:18 +00:00
|
|
|
const double duration = 500;
|
|
|
|
|
2022-03-09 00:12:44 +00:00
|
|
|
if (change.NewValue)
|
|
|
|
{
|
2022-03-10 06:49:18 +00:00
|
|
|
checkbox.FadeIn(duration, Easing.OutQuint);
|
|
|
|
checkbox.ScaleTo(1f, duration, Easing.OutElastic);
|
2022-03-09 00:33:46 +00:00
|
|
|
channelText.Colour = Colour4.White;
|
|
|
|
topicText.Colour = Colour4.White;
|
2022-03-09 00:12:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-10 06:49:18 +00:00
|
|
|
checkbox.FadeOut(duration, Easing.OutQuint);
|
|
|
|
checkbox.ScaleTo(0.8f, duration, Easing.OutQuint);
|
2022-03-09 00:33:46 +00:00
|
|
|
channelText.Colour = colourProvider.Light3;
|
|
|
|
topicText.Colour = colourProvider.Content2;
|
2022-03-09 00:12:44 +00:00
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2022-04-29 20:33:32 +00:00
|
|
|
Action = () => (channelJoined.Value ? OnRequestLeave : OnRequestJoin)?.Invoke(Channel);
|
2022-03-09 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
hoverBox.Show();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
2022-03-10 06:49:18 +00:00
|
|
|
hoverBox.FadeOut(300, Easing.OutQuint);
|
2022-03-09 00:12:44 +00:00
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
2022-03-08 22:30:58 +00:00
|
|
|
}
|
|
|
|
}
|