2023-11-06 14:24:12 +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 JetBrains.Annotations;
|
|
|
|
using osu.Framework.Allocation;
|
2023-11-23 16:15:03 +08:00
|
|
|
using osu.Framework.Bindables;
|
2023-11-06 14:24:12 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2023-11-23 16:15:03 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2023-11-06 14:24:12 +08:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Components
|
|
|
|
{
|
|
|
|
[UsedImplicitly]
|
|
|
|
public partial class PlayerName : FontAdjustableSkinComponent
|
|
|
|
{
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
2023-11-23 16:15:03 +08:00
|
|
|
[Resolved]
|
|
|
|
private GameplayState? gameplayState { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
|
|
|
|
|
|
|
private IBindable<APIUser>? apiUser;
|
|
|
|
|
2023-11-06 14:24:12 +08:00
|
|
|
public PlayerName()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-11-23 16:15:03 +08:00
|
|
|
private void load()
|
2023-11-06 14:24:12 +08:00
|
|
|
{
|
2023-11-23 16:15:03 +08:00
|
|
|
if (gameplayState != null)
|
|
|
|
text.Text = gameplayState.Score.ScoreInfo.User.Username;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
apiUser = api.LocalUser.GetBoundCopy();
|
|
|
|
apiUser.BindValueChanged(u => text.Text = u.NewValue.Username, true);
|
|
|
|
}
|
2023-11-06 14:24:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
|
|
|
|
}
|
|
|
|
}
|