mirror of
https://github.com/ppy/osu.git
synced 2024-11-14 15:17:27 +08:00
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
// 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;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osu.Game.Online.API;
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
using osu.Game.Screens.Play;
|
|
|
|
namespace osu.Game.Skinning.Components
|
|
{
|
|
[UsedImplicitly]
|
|
public partial class PlayerName : FontAdjustableSkinComponent
|
|
{
|
|
private readonly OsuSpriteText text;
|
|
|
|
[Resolved]
|
|
private GameplayState? gameplayState { get; set; }
|
|
|
|
[Resolved]
|
|
private IAPIProvider api { get; set; } = null!;
|
|
|
|
private IBindable<APIUser>? apiUser;
|
|
|
|
public PlayerName()
|
|
{
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
InternalChildren = new Drawable[]
|
|
{
|
|
text = new OsuSpriteText
|
|
{
|
|
Anchor = Anchor.CentreLeft,
|
|
Origin = Anchor.CentreLeft,
|
|
}
|
|
};
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
if (gameplayState != null)
|
|
text.Text = gameplayState.Score.ScoreInfo.User.Username;
|
|
else
|
|
{
|
|
apiUser = api.LocalUser.GetBoundCopy();
|
|
apiUser.BindValueChanged(u => text.Text = u.NewValue.Username, true);
|
|
}
|
|
}
|
|
|
|
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
|
|
}
|
|
}
|