osu/osu.Game/Overlays/Chat/ChannelListItem.cs

194 lines
7.2 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
2017-05-20 21:06:25 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-05-20 21:06:25 +00:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-05-30 01:04:53 +00:00
using osu.Framework.Input;
2017-05-20 21:06:25 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
2017-05-20 21:06:25 +00:00
namespace osu.Game.Overlays.Chat
{
2017-05-20 23:22:55 +00:00
public class ChannelListItem : ClickableContainer, IFilterable
2017-05-20 21:06:25 +00:00
{
private const float width_padding = 5;
2017-05-20 21:06:25 +00:00
private const float channel_width = 150;
private const float text_size = 15;
private const float transition_duration = 100;
2017-05-27 20:49:57 +00:00
private readonly Channel channel;
2017-05-30 01:04:53 +00:00
private readonly OsuSpriteText name;
2017-05-20 21:06:25 +00:00
private readonly OsuSpriteText topic;
private readonly TextAwesome joinedCheckmark;
private Color4? joinedColour;
private Color4? topicColour;
2017-05-30 01:04:53 +00:00
private Color4 hoverColour;
2017-05-20 21:06:25 +00:00
public string[] FilterTerms => new[] { channel.Name };
2017-06-01 01:39:03 +00:00
public bool MatchingFilter
2017-05-26 06:38:52 +00:00
{
2017-05-26 07:02:04 +00:00
set
2017-05-26 06:38:52 +00:00
{
2017-05-20 23:22:55 +00:00
FadeTo(value ? 1f : 0f, 100);
}
}
public Action<Channel> OnRequestJoin;
2017-05-26 06:56:10 +00:00
public Action<Channel> OnRequestLeave;
public ChannelListItem(Channel channel)
2017-05-20 21:06:25 +00:00
{
this.channel = channel;
2017-05-20 21:06:25 +00:00
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Action = () => { (channel.Joined ? OnRequestLeave : OnRequestJoin)?.Invoke(channel); };
2017-05-20 21:06:25 +00:00
Children = new Drawable[]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new Container
{
Children = new[]
{
joinedCheckmark = new TextAwesome
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Icon = FontAwesome.fa_check_circle,
TextSize = text_size,
Shadow = false,
2017-05-20 21:06:25 +00:00
Margin = new MarginPadding { Right = 10f },
Alpha = 0f,
},
},
},
new Container
{
Width = channel_width,
AutoSizeAxes = Axes.Y,
Children = new[]
{
2017-05-30 01:04:53 +00:00
name = new OsuSpriteText
2017-05-20 21:06:25 +00:00
{
Text = channel.ToString(),
2017-05-20 21:06:25 +00:00
TextSize = text_size,
Font = @"Exo2.0-Bold",
Shadow = false,
2017-05-20 21:06:25 +00:00
},
},
},
new Container
{
2017-05-26 06:51:09 +00:00
RelativeSizeAxes = Axes.X,
Width = 0.7f,
2017-05-20 21:06:25 +00:00
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Left = width_padding },
2017-05-20 21:06:25 +00:00
Children = new[]
{
topic = new OsuSpriteText
{
Text = channel.Topic,
2017-05-20 21:06:25 +00:00
TextSize = text_size,
Font = @"Exo2.0-SemiBold",
Shadow = false,
2017-05-20 21:06:25 +00:00
Alpha = 0.8f,
},
},
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = width_padding },
2017-05-20 21:06:25 +00:00
Spacing = new Vector2(3f, 0f),
Children = new Drawable[]
{
new TextAwesome
{
Icon = FontAwesome.fa_user,
TextSize = text_size - 2,
Shadow = false,
2017-05-20 21:06:25 +00:00
Margin = new MarginPadding { Top = 1 },
},
new OsuSpriteText
{
Text = @"0",
2017-05-20 21:06:25 +00:00
TextSize = text_size,
Font = @"Exo2.0-SemiBold",
Shadow = false,
2017-05-20 21:06:25 +00:00
},
},
},
},
},
};
channel.Joined.ValueChanged += updateColour;
2017-05-20 21:06:25 +00:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
topicColour = colours.Gray9;
joinedColour = colours.Blue;
2017-05-30 01:04:53 +00:00
hoverColour = colours.Yellow;
2017-05-20 21:06:25 +00:00
updateColour(channel.Joined);
}
2017-05-30 01:04:53 +00:00
protected override bool OnHover(InputState state)
{
if (!channel.Joined.Value)
2017-06-01 09:10:26 +00:00
name.FadeColour(hoverColour, 50, EasingTypes.OutQuint);
2017-05-30 01:04:53 +00:00
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
if (!channel.Joined.Value)
name.FadeColour(Color4.White, transition_duration);
}
protected override void Dispose(bool isDisposing)
{
if(channel != null) channel.Joined.ValueChanged -= updateColour;
base.Dispose(isDisposing);
2017-05-20 21:06:25 +00:00
}
private void updateColour(bool joined)
{
2017-05-26 06:46:50 +00:00
if (joined)
{
2017-05-30 01:04:53 +00:00
name.FadeColour(Color4.White, transition_duration);
2017-05-26 06:46:50 +00:00
joinedCheckmark.FadeTo(1f, transition_duration);
topic.FadeTo(0.8f, transition_duration);
topic.FadeColour(Color4.White, transition_duration);
FadeColour(joinedColour ?? Color4.White, transition_duration);
}
else
{
joinedCheckmark.FadeTo(0f, transition_duration);
topic.FadeTo(1f, transition_duration);
topic.FadeColour(topicColour ?? Color4.White, transition_duration);
FadeColour(Color4.White, transition_duration);
}
2017-05-20 21:06:25 +00:00
}
}
}