1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 11:22:57 +08:00

Restructure OsuSliderBar to allow for custom tooltips

This commit is contained in:
Dean Herbert 2022-03-03 16:59:10 +09:00
parent 8115a4bb8f
commit 657f2ebb9d

View File

@ -40,7 +40,7 @@ namespace osu.Game.Graphics.UserInterface
private readonly Box rightBox;
private readonly Container nubContainer;
public virtual LocalisableString TooltipText { get; private set; }
public virtual LocalisableString TooltipText { get; protected set; }
/// <summary>
/// Whether to format the tooltip as a percentage or the actual value.
@ -148,7 +148,7 @@ namespace osu.Game.Graphics.UserInterface
protected override void LoadComplete()
{
base.LoadComplete();
CurrentNumber.BindValueChanged(current => updateTooltipText(current.NewValue), true);
CurrentNumber.BindValueChanged(current => TooltipText = GetTooltipText(current.NewValue), true);
}
protected override bool OnHover(HoverEvent e)
@ -178,7 +178,7 @@ namespace osu.Game.Graphics.UserInterface
{
base.OnUserChange(value);
playSample(value);
updateTooltipText(value);
TooltipText = GetTooltipText(value);
}
private void playSample(T value)
@ -203,28 +203,22 @@ namespace osu.Game.Graphics.UserInterface
channel.Play();
}
private void updateTooltipText(T value)
protected virtual LocalisableString GetTooltipText(T value)
{
if (CurrentNumber.IsInteger)
TooltipText = value.ToInt32(NumberFormatInfo.InvariantInfo).ToString("N0");
else
{
return value.ToInt32(NumberFormatInfo.InvariantInfo).ToString("N0");
double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo);
if (DisplayAsPercentage)
{
TooltipText = floatValue.ToString("0%");
}
else
{
return floatValue.ToString("0%");
decimal decimalPrecision = normalise(CurrentNumber.Precision.ToDecimal(NumberFormatInfo.InvariantInfo), max_decimal_digits);
// Find the number of significant digits (we could have less than 5 after normalize())
int significantDigits = FormatUtils.FindPrecision(decimalPrecision);
TooltipText = floatValue.ToString($"N{significantDigits}");
}
}
return floatValue.ToString($"N{significantDigits}");
}
protected override void UpdateAfterChildren()