1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 22:27:25 +08:00
osu-lazer/osu.Game/Overlays/Chat/ChannelListItem.cs

147 lines
5.5 KiB
C#
Raw Normal View History

2017-05-21 05:06:25 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
2017-05-21 05:06:25 +08:00
namespace osu.Game.Overlays.Chat
{
public class ChannelListItem : ClickableContainer
{
private const float width_padding = 5;
2017-05-21 05:06:25 +08:00
private const float channel_width = 150;
private const float topic_width = 380;
private const float text_size = 15;
private const float transition_duration = 100;
private readonly OsuSpriteText topic;
2017-05-21 06:37:11 +08:00
private readonly OsuSpriteText name;
2017-05-21 05:06:25 +08:00
private readonly TextAwesome joinedCheckmark;
private Color4? joinedColour;
private Color4? topicColour;
2017-05-21 06:37:11 +08:00
private Channel channel;
public Channel Channel
2017-05-21 05:06:25 +08:00
{
2017-05-21 06:37:11 +08:00
get { return channel; }
2017-05-21 05:06:25 +08:00
set
{
2017-05-21 06:37:11 +08:00
if (value == channel) return;
channel = value;
2017-05-21 05:06:25 +08:00
2017-05-21 06:37:11 +08:00
name.Text = Channel.ToString();
topic.Text = Channel.Topic;
2017-05-21 05:06:25 +08:00
updateColour();
}
}
2017-05-21 06:37:11 +08:00
public ChannelListItem()
2017-05-21 05:06:25 +08:00
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
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,
Margin = new MarginPadding { Right = 10f },
Alpha = 0f,
},
},
},
new Container
{
Width = channel_width,
AutoSizeAxes = Axes.Y,
Children = new[]
{
2017-05-21 06:37:11 +08:00
name = new OsuSpriteText
2017-05-21 05:06:25 +08:00
{
TextSize = text_size,
Font = @"Exo2.0-Bold",
},
},
},
new Container
{
Width = topic_width,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Left = width_padding },
2017-05-21 05:06:25 +08:00
Children = new[]
{
topic = new OsuSpriteText
{
TextSize = text_size,
Font = @"Exo2.0-SemiBold",
Alpha = 0.8f,
},
},
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = width_padding },
2017-05-21 05:06:25 +08:00
Spacing = new Vector2(3f, 0f),
Children = new Drawable[]
{
new TextAwesome
{
Icon = FontAwesome.fa_user,
TextSize = text_size - 2,
Margin = new MarginPadding { Top = 1 },
},
new OsuSpriteText
{
Text = @"0",
2017-05-21 05:06:25 +08:00
TextSize = text_size,
Font = @"Exo2.0-SemiBold",
},
},
},
},
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
topicColour = colours.Gray9;
joinedColour = colours.Blue;
updateColour();
}
private void updateColour()
{
2017-05-21 06:37:11 +08:00
joinedCheckmark.FadeTo(Channel.Joined ? 1f : 0f, transition_duration);
topic.FadeTo(Channel.Joined ? 0.8f : 1f, transition_duration);
topic.FadeColour(Channel.Joined ? Color4.White : topicColour ?? Color4.White, transition_duration);
FadeColour(Channel.Joined ? joinedColour ?? Color4.White : Color4.White, transition_duration);
2017-05-21 05:06:25 +08:00
}
}
}