1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-22 12:13:05 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/Components/LevelBadge.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.9 KiB
C#
Raw Normal View History

// 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
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;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
2021-07-17 21:21:30 +08:00
using osu.Game.Resources.Localisation.Web;
2019-04-26 12:49:44 +08:00
namespace osu.Game.Overlays.Profile.Header.Components
{
public class LevelBadge : CompositeDrawable, IHasTooltip
{
public readonly Bindable<APIUser> User = new Bindable<APIUser>();
2021-07-17 21:21:30 +08:00
public LocalisableString TooltipText { get; private set; }
private OsuSpriteText levelText;
public LevelBadge()
{
2021-07-17 21:21:30 +08:00
TooltipText = UsersStrings.ShowStatsLevel("0");
}
[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)
}
};
User.BindValueChanged(user => updateLevel(user.NewValue));
}
private void updateLevel(APIUser user)
{
levelText.Text = user?.Statistics?.Level.Current.ToString() ?? "0";
2021-07-17 21:21:30 +08:00
TooltipText = UsersStrings.ShowStatsLevel(user?.Statistics?.Level.Current.ToString());
}
}
}