1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 01:57:48 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/Components/LevelProgressBar.cs
Salman Ahmed be2d616e34 Fix localisation use cases not falling back to default(LocalisableString)
Previously such use cases have been returning `null` values just fine since `GetLocalisableString` was returning `LocalisableFormattableString`, and these null values were wrapped in `LocalisableString`s implicitly, therefore not requiring an explicit fallback string and `null` doesn't break anything.
2022-04-28 11:21:00 +03:00

69 lines
2.4 KiB
C#

// 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.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header.Components
{
public class LevelProgressBar : CompositeDrawable, IHasTooltip
{
public readonly Bindable<APIUser> User = new Bindable<APIUser>();
public LocalisableString TooltipText { get; }
private Bar levelProgressBar;
private OsuSpriteText levelProgressText;
public LevelProgressBar()
{
TooltipText = UsersStrings.ShowStatsLevelProgress;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
InternalChildren = new Drawable[]
{
new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Child = levelProgressBar = new Bar
{
RelativeSizeAxes = Axes.Both,
BackgroundColour = Color4.Black,
Direction = BarDirection.LeftToRight,
AccentColour = colourProvider.Highlight1
}
},
levelProgressText = new OsuSpriteText
{
Anchor = Anchor.BottomRight,
Origin = Anchor.TopRight,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold)
}
};
User.BindValueChanged(user => updateProgress(user.NewValue));
}
private void updateProgress(APIUser user)
{
levelProgressBar.Length = user?.Statistics?.Level.Progress / 100f ?? 0;
levelProgressText.Text = user?.Statistics?.Level.Progress.ToLocalisableString("0'%'") ?? default(LocalisableString);
}
}
}