2019-04-25 19:30:16 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-04-25 19:30:16 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-06-26 01:10:04 +08:00
|
|
|
using osu.Framework.Localisation;
|
2019-04-25 19:30:16 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-07-17 21:21:30 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2019-04-25 19:30:16 +08:00
|
|
|
|
2019-04-26 12:49:44 +08:00
|
|
|
namespace osu.Game.Overlays.Profile.Header.Components
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
|
|
|
public class LevelBadge : CompositeDrawable, IHasTooltip
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
public readonly Bindable<APIUser> User = new Bindable<APIUser>();
|
2019-04-25 19:30:16 +08:00
|
|
|
|
2021-07-17 21:21:30 +08:00
|
|
|
public LocalisableString TooltipText { get; private set; }
|
2019-04-25 19:30:16 +08:00
|
|
|
|
|
|
|
private OsuSpriteText levelText;
|
|
|
|
|
|
|
|
public LevelBadge()
|
|
|
|
{
|
2021-07-17 21:21:30 +08:00
|
|
|
TooltipText = UsersStrings.ShowStatsLevel("0");
|
2019-04-25 19:30:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, TextureStore textures)
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Sprite
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Texture = textures.Get("Profile/levelbadge"),
|
|
|
|
Colour = colours.Yellow,
|
|
|
|
},
|
|
|
|
levelText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 20)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-26 11:32:15 +08:00
|
|
|
User.BindValueChanged(user => updateLevel(user.NewValue));
|
2019-04-25 19:30:16 +08:00
|
|
|
}
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
private void updateLevel(APIUser user)
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
2019-04-26 11:32:15 +08:00
|
|
|
levelText.Text = user?.Statistics?.Level.Current.ToString() ?? "0";
|
2021-07-17 21:21:30 +08:00
|
|
|
TooltipText = UsersStrings.ShowStatsLevel(user?.Statistics?.Level.Current.ToString());
|
2019-04-25 19:30:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|