1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00
osu-lazer/osu.Game/Users/UserPanel.cs

202 lines
8.3 KiB
C#
Raw Normal View History

2017-05-22 14:11:42 +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.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2017-05-22 14:11:42 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2017-06-16 16:23:20 +08:00
using osu.Game.Overlays;
2017-05-22 14:11:42 +08:00
namespace osu.Game.Users
{
public class UserPanel : Container
{
private const float height = 100;
private const float content_padding = 10;
private const float status_height = 30;
private OsuColour colours;
2017-06-16 16:23:20 +08:00
private UserProfileOverlay profile;
2017-05-22 14:11:42 +08:00
2017-05-24 11:45:56 +08:00
private readonly Container statusBar;
2017-05-22 14:11:42 +08:00
private readonly Box statusBg;
private readonly OsuSpriteText statusMessage;
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
public UserPanel(User user)
{
2017-05-24 11:45:56 +08:00
Height = height - status_height;
2017-05-22 14:11:42 +08:00
Masking = true;
CornerRadius = 5;
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
2017-05-22 14:11:42 +08:00
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
};
Children = new Drawable[]
{
new AsyncLoadWrapper(new UserCoverBackground(user)
2017-05-22 14:11:42 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-05-24 15:21:34 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(200),
}) { RelativeSizeAxes = Axes.Both },
2017-05-22 14:11:42 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.7f),
},
new Container
{
2017-05-24 11:45:56 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Top = content_padding, Left = content_padding, Right = content_padding },
2017-05-22 14:11:42 +08:00
Children = new Drawable[]
{
new UpdateableAvatar
{
Size = new Vector2(height - status_height - content_padding * 2),
User = user,
Masking = true,
CornerRadius = 5,
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
2017-05-22 14:11:42 +08:00
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
},
},
2017-06-16 16:23:20 +08:00
new ClickableContainer
2017-05-22 14:11:42 +08:00
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = height - status_height - content_padding },
2017-05-22 14:11:42 +08:00
Children = new Drawable[]
{
new OsuSpriteText
{
Text = user.Username,
TextSize = 18,
Font = @"Exo2.0-SemiBoldItalic",
},
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.X,
Height = 20f,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5f, 0f),
Children = new Drawable[]
{
new DrawableFlag(user.Country?.FlagName ?? @"__")
{
Width = 30f,
RelativeSizeAxes = Axes.Y,
},
new Container
{
Width = 40f,
RelativeSizeAxes = Axes.Y,
},
new CircularContainer
{
Width = 20f,
RelativeSizeAxes = Axes.Y,
},
},
},
},
2017-06-16 16:23:20 +08:00
Action = () => profile?.ShowUser(user)
2017-05-22 14:11:42 +08:00
},
},
},
2017-05-24 11:45:56 +08:00
statusBar = new Container
2017-05-22 14:11:42 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
2017-05-24 11:45:56 +08:00
Alpha = 0f,
2017-05-22 14:11:42 +08:00
Children = new Drawable[]
{
statusBg = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.5f,
},
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5f, 0f),
Children = new[]
{
new TextAwesome
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Icon = FontAwesome.fa_circle_o,
Shadow = true,
TextSize = 14,
},
statusMessage = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = @"Exo2.0-Semibold",
},
},
},
},
},
};
}
2017-06-21 16:03:47 +08:00
[BackgroundDependencyLoader(permitNulls: true)]
2017-06-16 16:23:20 +08:00
private void load(OsuColour colours, UserProfileOverlay profile)
2017-05-22 14:11:42 +08:00
{
this.colours = colours;
2017-06-16 16:23:20 +08:00
this.profile = profile;
2017-05-25 15:31:56 +08:00
Status.ValueChanged += displayStatus;
}
protected override void LoadComplete()
{
base.LoadComplete();
Status.TriggerChange();
2017-05-22 14:11:42 +08:00
}
private void displayStatus(UserStatus status)
{
2017-05-24 15:00:39 +08:00
const float transition_duration = 500;
2017-05-24 11:45:56 +08:00
2017-05-24 14:49:06 +08:00
if (status == null)
{
statusBar.ResizeHeightTo(0f, transition_duration, EasingTypes.OutQuint);
statusBar.FadeOut(transition_duration, EasingTypes.OutQuint);
ResizeHeightTo(height - status_height, transition_duration, EasingTypes.OutQuint);
}
else
{
statusBar.ResizeHeightTo(status_height, transition_duration, EasingTypes.OutQuint);
statusBar.FadeIn(transition_duration, EasingTypes.OutQuint);
ResizeHeightTo(height, transition_duration, EasingTypes.OutQuint);
statusBg.FadeColour(status.GetAppropriateColour(colours), 500, EasingTypes.OutQuint);
statusMessage.Text = status.Message;
}
2017-05-22 14:11:42 +08:00
}
}
}