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.
|
2019-01-11 08:12:19 +08:00
|
|
|
|
|
2022-03-04 11:00:02 +08:00
|
|
|
|
using System.Threading;
|
2019-01-11 08:12:19 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-10 06:58:14 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-01-11 08:12:19 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-04-26 12:49:44 +08:00
|
|
|
|
using osu.Game.Overlays.Profile.Header.Components;
|
2019-01-11 08:12:19 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Header
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class MedalHeaderContainer : CompositeDrawable
|
2019-01-11 08:12:19 +08:00
|
|
|
|
{
|
2022-12-30 20:17:59 +08:00
|
|
|
|
private FillFlowContainer badgeFlowContainer = null!;
|
2019-01-11 08:12:19 +08:00
|
|
|
|
|
2023-01-10 00:37:28 +08:00
|
|
|
|
public readonly Bindable<UserProfileData?> UserProfile = new Bindable<UserProfileData?>();
|
2019-01-11 08:12:19 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-01-30 05:10:48 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2019-01-11 08:12:19 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0;
|
2019-03-10 06:58:14 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2022-12-30 21:56:19 +08:00
|
|
|
|
UserProfile.ValueChanged += e => updateDisplay(e.NewValue?.User);
|
2019-03-10 06:58:14 +08:00
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
2019-01-11 08:12:19 +08:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-01-30 05:10:48 +08:00
|
|
|
|
Colour = colourProvider.Background5,
|
2019-01-11 08:12:19 +08:00
|
|
|
|
},
|
2020-05-05 09:31:11 +08:00
|
|
|
|
new Container // artificial shadow
|
2019-01-11 08:12:19 +08:00
|
|
|
|
{
|
|
|
|
|
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 },
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 20:17:59 +08:00
|
|
|
|
private CancellationTokenSource? cancellationTokenSource;
|
2022-03-04 11:00:02 +08:00
|
|
|
|
|
2022-12-30 20:17:59 +08:00
|
|
|
|
private void updateDisplay(APIUser? user)
|
2019-01-11 08:12:19 +08:00
|
|
|
|
{
|
2022-03-04 15:00:56 +08:00
|
|
|
|
cancellationTokenSource?.Cancel();
|
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
|
2019-01-11 08:12:19 +08:00
|
|
|
|
badgeFlowContainer.Clear();
|
2019-05-07 12:23:09 +08:00
|
|
|
|
|
2022-12-30 20:17:59 +08:00
|
|
|
|
var badges = user?.Badges;
|
2022-03-04 11:00:02 +08:00
|
|
|
|
|
2019-01-11 08:12:19 +08:00
|
|
|
|
if (badges?.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
Show();
|
2019-05-07 12:23:09 +08:00
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
for (int index = 0; index < badges.Length; index++)
|
2019-01-11 08:12:19 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
2022-03-04 15:00:56 +08:00
|
|
|
|
}, cancellationTokenSource.Token);
|
2019-01-11 08:12:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-04 15:01:07 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
cancellationTokenSource?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
2019-01-11 08:12:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|