1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 03:33:05 +08:00
osu-lazer/osu.Game/Overlays/Chat/Selection/ChannelListItem.cs

190 lines
7.0 KiB
C#
Raw Normal View History

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