1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00
osu-lazer/osu.Game/Overlays/Mods/VerticalAttributeDisplay.cs
Givikap120 507f9642cc Better counter formatization
Now CS and HP have 1 decimal point precision, while AR and OD is kept with 2 because of future support of rate-changed AR/OD
2023-09-08 22:15:30 +03:00

79 lines
2.8 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.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Overlays.Mods
{
public partial class VerticalAttributeDisplay : Container, IHasCurrentValue<double>
{
public Bindable<double> Current
{
get => current.Current;
set => current.Current = value;
}
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
/// <summary>
/// Text to display in the top area of the display.
/// </summary>
public LocalisableString Label { get; protected set; }
public VerticalAttributeDisplay(LocalisableString label, string format = "0.#")
{
Label = label;
AutoSizeAxes = Axes.X;
Origin = Anchor = Anchor.CentreLeft;
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0);
InternalChild = new FillFlowContainer
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = Label,
Margin = new MarginPadding { Horizontal = 15 }, // to reserve space for 0.XX value
Font = OsuFont.Default.With(size: 20, weight: FontWeight.Bold)
},
new EffectCounter()
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Current = { BindTarget = Current },
Format = format
}
}
};
}
private partial class EffectCounter : RollingCounter<double>
{
protected override double RollingDuration => 500;
public string Format = "0.#";
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString(Format);
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
{
Font = OsuFont.Default.With(size: 18, weight: FontWeight.SemiBold)
};
}
}
}