1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 22:32:55 +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.

98 lines
2.8 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
2023-01-18 21:25:11 +08:00
using osu.Framework.Graphics.Colour;
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;
2021-07-17 21:21:30 +08:00
using osu.Game.Resources.Localisation.Web;
2023-01-18 21:25:11 +08:00
using osu.Game.Scoring;
using osu.Game.Users;
2019-04-26 12:49:44 +08:00
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class LevelBadge : CompositeDrawable, IHasTooltip
{
public readonly Bindable<UserStatistics.LevelInfo?> LevelInfo = new Bindable<UserStatistics.LevelInfo?>();
2021-07-17 21:21:30 +08:00
public LocalisableString TooltipText { get; private set; }
2022-12-30 20:17:59 +08:00
private OsuSpriteText levelText = null!;
2023-01-18 21:25:11 +08:00
private Sprite sprite = null!;
[Resolved]
private OsuColour osuColour { get; set; } = null!;
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[]
{
2023-01-18 21:25:11 +08:00
sprite = 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)
}
};
2023-01-17 04:42:07 +08:00
}
2023-01-17 04:42:07 +08:00
protected override void LoadComplete()
{
2023-01-17 04:47:31 +08:00
base.LoadComplete();
2023-01-17 04:42:07 +08:00
LevelInfo.BindValueChanged(level => updateLevel(level.NewValue), true);
}
private void updateLevel(UserStatistics.LevelInfo? levelInfo)
{
2023-01-18 21:25:11 +08:00
int level = levelInfo?.Current ?? 0;
levelText.Text = level.ToString();
TooltipText = UsersStrings.ShowStatsLevel(level.ToString());
sprite.Colour = mapLevelToTierColour(level);
}
private ColourInfo mapLevelToTierColour(int level)
{
var tier = RankingTier.Iron;
if (level > 0)
{
tier = (RankingTier)(level / 20);
}
if (level >= 105)
{
tier = RankingTier.Radiant;
}
if (level >= 110)
{
tier = RankingTier.Lustrous;
}
return osuColour.ForRankingTier(tier);
}
}
}