1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:20:04 +08:00

Allow use of skin username/flag/avatar components outside of gameplay

This commit is contained in:
Dean Herbert 2023-11-23 17:15:03 +09:00
parent 9a6857bfad
commit 5239fee947
No known key found for this signature in database
3 changed files with 57 additions and 6 deletions

View File

@ -7,6 +7,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Settings;
using osu.Game.Skinning;
using osu.Game.Users.Drawables;
@ -29,6 +31,14 @@ namespace osu.Game.Screens.Play.HUD
private const float default_size = 80f;
[Resolved]
private GameplayState? gameplayState { get; set; }
[Resolved]
private IAPIProvider api { get; set; } = null!;
private IBindable<APIUser>? apiUser;
public PlayerAvatar()
{
Size = new Vector2(default_size);
@ -41,9 +51,15 @@ namespace osu.Game.Screens.Play.HUD
}
[BackgroundDependencyLoader]
private void load(GameplayState gameplayState)
private void load()
{
avatar.User = gameplayState.Score.ScoreInfo.User;
if (gameplayState != null)
avatar.User = gameplayState.Score.ScoreInfo.User;
else
{
apiUser = api.LocalUser.GetBoundCopy();
apiUser.BindValueChanged(u => avatar.User = u.NewValue, true);
}
}
protected override void LoadComplete()

View File

@ -2,8 +2,11 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Skinning;
using osu.Game.Users.Drawables;
using osuTK;
@ -18,9 +21,18 @@ namespace osu.Game.Screens.Play.HUD
private const float default_size = 40f;
[Resolved]
private GameplayState? gameplayState { get; set; }
[Resolved]
private IAPIProvider api { get; set; } = null!;
private IBindable<APIUser>? apiUser;
public PlayerFlag()
{
Size = new Vector2(default_size, default_size / 1.4f);
InternalChild = flag = new UpdateableFlag
{
RelativeSizeAxes = Axes.Both,
@ -28,9 +40,15 @@ namespace osu.Game.Screens.Play.HUD
}
[BackgroundDependencyLoader]
private void load(GameplayState gameplayState)
private void load()
{
flag.CountryCode = gameplayState.Score.ScoreInfo.User.CountryCode;
if (gameplayState != null)
flag.CountryCode = gameplayState.Score.ScoreInfo.User.CountryCode;
else
{
apiUser = api.LocalUser.GetBoundCopy();
apiUser.BindValueChanged(u => flag.CountryCode = u.NewValue.CountryCode, true);
}
}
public bool UsesFixedAnchor { get; set; }

View File

@ -3,9 +3,12 @@
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
@ -15,6 +18,14 @@ namespace osu.Game.Skinning.Components
{
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;
@ -30,9 +41,15 @@ namespace osu.Game.Skinning.Components
}
[BackgroundDependencyLoader]
private void load(GameplayState gameplayState)
private void load()
{
text.Text = gameplayState.Score.ScoreInfo.User.Username;
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);