2022-09-18 03:09:34 +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 osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Configuration;
|
2023-03-06 07:10:42 +08:00
|
|
|
using osu.Game.Localisation.SkinComponents;
|
2023-11-23 16:15:03 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2023-03-08 02:43:52 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
2022-09-18 03:09:34 +08:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
2023-03-06 07:09:02 +08:00
|
|
|
public partial class PlayerAvatar : CompositeDrawable, ISerialisableDrawable
|
2022-09-18 03:09:34 +08:00
|
|
|
{
|
2023-03-08 02:43:52 +08:00
|
|
|
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.CornerRadius), nameof(SkinnableComponentStrings.CornerRadiusDescription),
|
|
|
|
SettingControlType = typeof(SettingsPercentageSlider<float>))]
|
2023-10-06 15:51:24 +08:00
|
|
|
public new BindableFloat CornerRadius { get; } = new BindableFloat(0.25f)
|
2022-09-18 03:09:34 +08:00
|
|
|
{
|
|
|
|
MinValue = 0,
|
2023-03-07 04:11:52 +08:00
|
|
|
MaxValue = 0.5f,
|
2022-09-18 03:09:34 +08:00
|
|
|
Precision = 0.01f
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly UpdateableAvatar avatar;
|
|
|
|
|
2023-03-07 16:00:10 +08:00
|
|
|
private const float default_size = 80f;
|
|
|
|
|
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;
|
|
|
|
|
2024-09-19 15:54:00 +08:00
|
|
|
private readonly Container cornerContainer;
|
|
|
|
|
2023-03-06 07:09:02 +08:00
|
|
|
public PlayerAvatar()
|
2022-09-18 03:09:34 +08:00
|
|
|
{
|
2023-03-07 16:00:10 +08:00
|
|
|
Size = new Vector2(default_size);
|
|
|
|
|
2024-09-19 15:54:00 +08:00
|
|
|
InternalChild = cornerContainer = new Container
|
2022-09-18 03:09:34 +08:00
|
|
|
{
|
2024-09-19 15:54:00 +08:00
|
|
|
Masking = true,
|
2022-09-18 03:09:34 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-09-19 15:54:00 +08:00
|
|
|
Child = avatar = new UpdateableAvatar(isInteractive: false)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
}
|
2022-09-18 03:09:34 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-07 16:39:21 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-11-23 16:15:03 +08:00
|
|
|
private void load()
|
2023-03-07 16:39:21 +08:00
|
|
|
{
|
2023-11-23 16:15:03 +08:00
|
|
|
if (gameplayState != null)
|
|
|
|
avatar.User = gameplayState.Score.ScoreInfo.User;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
apiUser = api.LocalUser.GetBoundCopy();
|
|
|
|
apiUser.BindValueChanged(u => avatar.User = u.NewValue, true);
|
|
|
|
}
|
2023-03-07 16:39:21 +08:00
|
|
|
}
|
|
|
|
|
2022-09-18 03:09:34 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-09-19 15:54:00 +08:00
|
|
|
CornerRadius.BindValueChanged(e => cornerContainer.CornerRadius = e.NewValue * default_size, true);
|
2022-09-18 03:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
}
|
|
|
|
}
|