2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-05-21 08:26:39 +08:00
|
|
|
using System;
|
2017-09-13 22:18:02 +08:00
|
|
|
using System.Collections.Generic;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2017-05-21 05:06:25 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2017-05-21 05:06:25 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-03-27 18:29:27 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2017-05-21 05:06:25 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-21 05:29:57 +08:00
|
|
|
using osu.Game.Online.Chat;
|
2017-06-29 01:19:04 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-07-10 01:42:57 +08:00
|
|
|
namespace osu.Game.Overlays.Chat.Selection
|
2017-05-21 05:06:25 +08:00
|
|
|
{
|
2017-06-29 01:19:04 +08:00
|
|
|
public class ChannelListItem : OsuClickableContainer, IFilterable
|
2017-05-21 05:06:25 +08:00
|
|
|
{
|
2017-05-21 05:29:57 +08:00
|
|
|
private const float width_padding = 5;
|
2017-05-21 05:06:25 +08:00
|
|
|
private const float channel_width = 150;
|
|
|
|
private const float text_size = 15;
|
|
|
|
private const float transition_duration = 100;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-01-30 13:35:03 +08:00
|
|
|
public readonly Channel Channel;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-06-01 18:55:01 +08:00
|
|
|
private readonly Bindable<bool> joinedBind = new Bindable<bool>();
|
2017-05-30 09:04:53 +08:00
|
|
|
private readonly OsuSpriteText name;
|
2017-05-21 05:06:25 +08:00
|
|
|
private readonly OsuSpriteText topic;
|
2017-08-03 13:36:21 +08:00
|
|
|
private readonly SpriteIcon joinedCheckmark;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-06-01 18:55:01 +08:00
|
|
|
private Color4 joinedColour;
|
|
|
|
private Color4 topicColour;
|
2017-05-30 09:04:53 +08:00
|
|
|
private Color4 hoverColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-01-30 13:35:03 +08:00
|
|
|
public IEnumerable<string> FilterTerms => new[] { Channel.Name, Channel.Topic ?? string.Empty };
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2017-06-01 09:39:03 +08:00
|
|
|
public bool MatchingFilter
|
2017-05-26 14:38:52 +08:00
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
set => this.FadeTo(value ? 1f : 0f, 100);
|
2017-05-21 07:22:55 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-03-28 23:29:07 +08:00
|
|
|
public bool FilteringActive { get; set; }
|
|
|
|
|
2017-05-21 08:26:39 +08:00
|
|
|
public Action<Channel> OnRequestJoin;
|
2017-05-26 14:56:10 +08:00
|
|
|
public Action<Channel> OnRequestLeave;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-05-28 04:35:42 +08:00
|
|
|
public ChannelListItem(Channel channel)
|
2017-05-21 05:06:25 +08:00
|
|
|
{
|
2020-01-30 14:00:39 +08:00
|
|
|
Channel = channel;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-05-21 05:06:25 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
Action = () => { (channel.Joined.Value ? OnRequestLeave : OnRequestJoin)?.Invoke(channel); };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-05-21 05:06:25 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Children = new[]
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
joinedCheckmark = new SpriteIcon
|
2017-05-21 05:06:25 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
2019-04-02 18:55:24 +08:00
|
|
|
Icon = FontAwesome.Solid.CheckCircle,
|
2017-08-03 13:36:21 +08:00
|
|
|
Size = new Vector2(text_size),
|
2017-05-21 08:38:36 +08:00
|
|
|
Shadow = false,
|
2017-05-21 05:06:25 +08:00
|
|
|
Margin = new MarginPadding { Right = 10f },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Width = channel_width,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2017-05-30 09:04:53 +08:00
|
|
|
name = new OsuSpriteText
|
2017-05-21 05:06:25 +08:00
|
|
|
{
|
2017-05-28 04:35:42 +08:00
|
|
|
Text = channel.ToString(),
|
2019-02-12 12:04:46 +08:00
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
2017-05-21 08:38:36 +08:00
|
|
|
Shadow = false,
|
2017-05-21 05:06:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
2017-05-26 14:51:09 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Width = 0.7f,
|
2017-05-21 05:06:25 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-05-21 05:29:57 +08:00
|
|
|
Margin = new MarginPadding { Left = width_padding },
|
2017-05-21 05:06:25 +08:00
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
topic = new OsuSpriteText
|
|
|
|
{
|
2017-05-28 04:35:42 +08:00
|
|
|
Text = channel.Topic,
|
2019-02-12 12:04:46 +08:00
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.SemiBold),
|
2017-05-21 08:38:36 +08:00
|
|
|
Shadow = false,
|
2017-05-21 05:06:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-05-21 05:29:57 +08:00
|
|
|
Margin = new MarginPadding { Left = width_padding },
|
2017-05-21 05:06:25 +08:00
|
|
|
Spacing = new Vector2(3f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
new SpriteIcon
|
2017-05-21 05:06:25 +08:00
|
|
|
{
|
2019-09-03 01:42:21 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2019-04-02 18:55:24 +08:00
|
|
|
Icon = FontAwesome.Solid.User,
|
2017-08-03 13:36:21 +08:00
|
|
|
Size = new Vector2(text_size - 2),
|
2017-05-21 08:38:36 +08:00
|
|
|
Shadow = false,
|
2017-05-21 05:06:25 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2017-05-21 06:30:40 +08:00
|
|
|
Text = @"0",
|
2019-02-12 12:04:46 +08:00
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.SemiBold),
|
2017-05-21 08:38:36 +08:00
|
|
|
Shadow = false,
|
2017-05-21 05:06:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-05-21 05:06:25 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
topicColour = colours.Gray9;
|
|
|
|
joinedColour = colours.Blue;
|
2017-05-30 09:04:53 +08:00
|
|
|
hoverColour = colours.Yellow;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
joinedBind.ValueChanged += joined => updateColour(joined.NewValue);
|
2020-01-30 13:35:03 +08:00
|
|
|
joinedBind.BindTo(Channel.Joined);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-09-08 23:47:23 +08:00
|
|
|
joinedBind.TriggerChange();
|
|
|
|
FinishTransforms(true);
|
2017-05-21 08:26:39 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-05-30 09:04:53 +08:00
|
|
|
{
|
2020-01-30 13:35:03 +08:00
|
|
|
if (!Channel.Joined.Value)
|
2017-07-23 02:50:25 +08:00
|
|
|
name.FadeColour(hoverColour, 50, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
return base.OnHover(e);
|
2017-05-30 09:04:53 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-05-30 09:04:53 +08:00
|
|
|
{
|
2020-01-30 13:35:03 +08:00
|
|
|
if (!Channel.Joined.Value)
|
2017-05-30 09:04:53 +08:00
|
|
|
name.FadeColour(Color4.White, transition_duration);
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-05-21 08:26:39 +08:00
|
|
|
private void updateColour(bool joined)
|
2017-05-21 05:29:57 +08:00
|
|
|
{
|
2017-05-26 14:46:50 +08:00
|
|
|
if (joined)
|
|
|
|
{
|
2017-05-30 09:04:53 +08:00
|
|
|
name.FadeColour(Color4.White, transition_duration);
|
2017-05-26 14:46:50 +08:00
|
|
|
joinedCheckmark.FadeTo(1f, transition_duration);
|
|
|
|
topic.FadeTo(0.8f, transition_duration);
|
|
|
|
topic.FadeColour(Color4.White, transition_duration);
|
2017-07-15 00:18:12 +08:00
|
|
|
this.FadeColour(joinedColour, transition_duration);
|
2017-05-26 14:46:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
joinedCheckmark.FadeTo(0f, transition_duration);
|
|
|
|
topic.FadeTo(1f, transition_duration);
|
2017-06-01 18:55:01 +08:00
|
|
|
topic.FadeColour(topicColour, transition_duration);
|
2017-07-15 00:18:12 +08:00
|
|
|
this.FadeColour(Color4.White, transition_duration);
|
2017-05-26 14:46:50 +08:00
|
|
|
}
|
2017-05-21 05:06:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|