mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 15:53:19 +08:00
Display tournament banner on user profile
This commit is contained in:
parent
2873905cc6
commit
3b5d573db1
@ -121,6 +121,12 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray()
|
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
TournamentBanner = new TournamentBanner
|
||||||
|
{
|
||||||
|
Id = 13926,
|
||||||
|
TournamentId = 35,
|
||||||
|
ImageLowRes = "https://assets.ppy.sh/tournament-banners/official/owc2022/profile/winner_US.jpg",
|
||||||
|
},
|
||||||
Badges = new[]
|
Badges = new[]
|
||||||
{
|
{
|
||||||
new Badge
|
new Badge
|
||||||
|
@ -234,6 +234,10 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
set => Statistics.RankHistory = value;
|
set => Statistics.RankHistory = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonProperty(@"active_tournament_banner")]
|
||||||
|
[CanBeNull]
|
||||||
|
public TournamentBanner TournamentBanner;
|
||||||
|
|
||||||
[JsonProperty("badges")]
|
[JsonProperty("badges")]
|
||||||
public Badge[] Badges;
|
public Badge[] Badges;
|
||||||
|
|
||||||
|
63
osu.Game/Overlays/Profile/Header/BannerHeaderContainer.cs
Normal file
63
osu.Game/Overlays/Profile/Header/BannerHeaderContainer.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Overlays.Profile.Header.Components;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Header
|
||||||
|
{
|
||||||
|
public partial class BannerHeaderContainer : CompositeDrawable
|
||||||
|
{
|
||||||
|
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Alpha = 0;
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
FillMode = FillMode.Fit;
|
||||||
|
FillAspectRatio = 1000 / 60f;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
User.BindValueChanged(u => updateDisplay(u.NewValue?.User), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CancellationTokenSource? cancellationTokenSource;
|
||||||
|
|
||||||
|
private void updateDisplay(APIUser? user)
|
||||||
|
{
|
||||||
|
cancellationTokenSource?.Cancel();
|
||||||
|
cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
ClearInternal();
|
||||||
|
|
||||||
|
var banner = user?.TournamentBanner;
|
||||||
|
|
||||||
|
if (banner != null)
|
||||||
|
{
|
||||||
|
Show();
|
||||||
|
|
||||||
|
LoadComponentAsync(new DrawableTournamentBanner(banner), AddInternal, cancellationTokenSource.Token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
cancellationTokenSource?.Cancel();
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Header.Components
|
||||||
|
{
|
||||||
|
[LongRunningLoad]
|
||||||
|
public partial class DrawableTournamentBanner : OsuClickableContainer
|
||||||
|
{
|
||||||
|
private readonly TournamentBanner banner;
|
||||||
|
|
||||||
|
public DrawableTournamentBanner(TournamentBanner banner)
|
||||||
|
{
|
||||||
|
this.banner = banner;
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(LargeTextureStore textures, OsuGame? game, IAPIProvider api)
|
||||||
|
{
|
||||||
|
Child = new Sprite
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Texture = textures.Get(banner.Image),
|
||||||
|
};
|
||||||
|
|
||||||
|
Action = () => game?.OpenUrlExternally($@"{api.WebsiteRootUrl}/community/tournaments/{banner.TournamentId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
this.FadeInFromZero(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override LocalisableString TooltipText => "view in browser";
|
||||||
|
}
|
||||||
|
}
|
@ -47,6 +47,10 @@ namespace osu.Game.Overlays.Profile
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
User = { BindTarget = User },
|
User = { BindTarget = User },
|
||||||
},
|
},
|
||||||
|
new BannerHeaderContainer
|
||||||
|
{
|
||||||
|
User = { BindTarget = User },
|
||||||
|
},
|
||||||
new BadgeHeaderContainer
|
new BadgeHeaderContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
23
osu.Game/Users/TournamentBanner.cs
Normal file
23
osu.Game/Users/TournamentBanner.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace osu.Game.Users
|
||||||
|
{
|
||||||
|
public class TournamentBanner
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int Id;
|
||||||
|
|
||||||
|
[JsonProperty("tournament_id")]
|
||||||
|
public int TournamentId;
|
||||||
|
|
||||||
|
[JsonProperty("image")]
|
||||||
|
public string ImageLowRes = null!;
|
||||||
|
|
||||||
|
// TODO: remove when api returns @2x image link: https://github.com/ppy/osu-web/issues/9816
|
||||||
|
public string Image => $@"{Path.ChangeExtension(ImageLowRes, null)}@2x{Path.GetExtension(ImageLowRes)}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user