mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:07:52 +08:00
Merge pull request #25553 from peppy/skin-player-elements
Allow use of skin username/flag/avatar components outside of gameplay
This commit is contained in:
commit
9541d3d452
@ -7,6 +7,8 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Localisation.SkinComponents;
|
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.Overlays.Settings;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
@ -29,6 +31,14 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private const float default_size = 80f;
|
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()
|
public PlayerAvatar()
|
||||||
{
|
{
|
||||||
Size = new Vector2(default_size);
|
Size = new Vector2(default_size);
|
||||||
@ -41,9 +51,15 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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()
|
protected override void LoadComplete()
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -18,9 +21,18 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private const float default_size = 40f;
|
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()
|
public PlayerFlag()
|
||||||
{
|
{
|
||||||
Size = new Vector2(default_size, default_size / 1.4f);
|
Size = new Vector2(default_size, default_size / 1.4f);
|
||||||
|
|
||||||
InternalChild = flag = new UpdateableFlag
|
InternalChild = flag = new UpdateableFlag
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -28,9 +40,15 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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; }
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
@ -3,9 +3,12 @@
|
|||||||
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
namespace osu.Game.Skinning.Components
|
namespace osu.Game.Skinning.Components
|
||||||
@ -15,6 +18,14 @@ namespace osu.Game.Skinning.Components
|
|||||||
{
|
{
|
||||||
private readonly OsuSpriteText text;
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private GameplayState? gameplayState { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
|
private IBindable<APIUser>? apiUser;
|
||||||
|
|
||||||
public PlayerName()
|
public PlayerName()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
@ -30,9 +41,15 @@ namespace osu.Game.Skinning.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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);
|
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
|
||||||
|
Loading…
Reference in New Issue
Block a user