1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:47:26 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/MedalHeaderContainer.cs

95 lines
3.1 KiB
C#
Raw Normal View History

2019-01-28 06:45:00 +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.
using osu.Framework.Allocation;
2019-03-10 06:58:14 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
2019-04-26 12:49:44 +08:00
using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header
{
2019-03-10 06:58:14 +08:00
public class MedalHeaderContainer : CompositeDrawable
{
private FillFlowContainer badgeFlowContainer;
2019-03-10 06:58:14 +08:00
public readonly Bindable<User> User = new Bindable<User>();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Alpha = 0;
2019-03-10 06:58:14 +08:00
AutoSizeAxes = Axes.Y;
User.ValueChanged += e => updateDisplay(e.NewValue);
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2019-05-20 14:58:40 +08:00
Colour = colours.GreySeafoamDarker,
},
new Container //artificial shadow
{
RelativeSizeAxes = Axes.X,
Height = 3,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new ColourInfo
{
TopLeft = Color4.Black.Opacity(0.2f),
TopRight = Color4.Black.Opacity(0.2f),
BottomLeft = Color4.Black.Opacity(0),
BottomRight = Color4.Black.Opacity(0)
}
},
},
badgeFlowContainer = new FillFlowContainer
{
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 5 },
Spacing = new Vector2(10, 10),
Padding = new MarginPadding { Horizontal = UserProfileOverlay.CONTENT_X_MARGIN, Vertical = 10 },
}
};
}
2019-03-10 06:58:14 +08:00
private void updateDisplay(User user)
{
2019-03-10 06:58:14 +08:00
var badges = user.Badges;
badgeFlowContainer.Clear();
if (badges?.Length > 0)
{
Show();
for (var index = 0; index < badges.Length; index++)
{
int displayIndex = index;
LoadComponentAsync(new DrawableBadge(badges[index]), asyncBadge =>
{
badgeFlowContainer.Add(asyncBadge);
// load in stable order regardless of async load order.
badgeFlowContainer.SetLayoutPosition(asyncBadge, displayIndex);
});
}
}
else
{
Hide();
}
}
}
}