1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-30 05:47:25 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/BadgeHeaderContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 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 System.Threading;
using osu.Framework.Allocation;
2019-03-10 06:58:14 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Online.API.Requests.Responses;
2019-04-26 12:49:44 +08:00
using osu.Game.Overlays.Profile.Header.Components;
using osuTK;
namespace osu.Game.Overlays.Profile.Header
{
public partial class BadgeHeaderContainer : CompositeDrawable
{
2022-12-30 20:17:59 +08:00
private FillFlowContainer badgeFlowContainer = null!;
2023-01-11 02:24:54 +08:00
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
[BackgroundDependencyLoader]
2020-01-30 05:10:48 +08:00
private void load(OverlayColourProvider colourProvider)
{
Alpha = 0;
2019-03-10 06:58:14 +08:00
AutoSizeAxes = Axes.Y;
2023-01-11 02:24:54 +08:00
User.ValueChanged += e => updateDisplay(e.NewValue?.User);
2019-03-10 06:58:14 +08:00
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2020-01-30 05:10:48 +08:00
Colour = colourProvider.Background5,
},
2020-05-05 09:31:11 +08:00
new Container // artificial shadow
{
RelativeSizeAxes = Axes.X,
Height = 3,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Colour4.Black.Opacity(0.2f), Colour4.Black.Opacity(0))
}
},
badgeFlowContainer = new FillFlowContainer
{
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(10, 10),
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.HORIZONTAL_PADDING, Top = 10 },
}
};
}
2022-12-30 20:17:59 +08:00
private CancellationTokenSource? cancellationTokenSource;
2022-12-30 20:17:59 +08:00
private void updateDisplay(APIUser? user)
{
cancellationTokenSource?.Cancel();
cancellationTokenSource = new CancellationTokenSource();
badgeFlowContainer.Clear();
2022-12-30 20:17:59 +08:00
var badges = user?.Badges;
if (badges?.Length > 0)
{
Show();
for (int index = 0; index < badges.Length; index++)
{
int displayIndex = index;
LoadComponentAsync(new DrawableBadge(badges[index]), asyncBadge =>
{
// load in stable order regardless of async load order.
2019-07-01 23:41:08 +08:00
badgeFlowContainer.Insert(displayIndex, asyncBadge);
}, cancellationTokenSource.Token);
}
}
else
{
Hide();
}
}
protected override void Dispose(bool isDisposing)
{
cancellationTokenSource?.Cancel();
base.Dispose(isDisposing);
}
}
}