diff --git a/osu.Game/Graphics/UserInterface/NormalSliderBar.cs b/osu.Game/Graphics/UserInterface/NormalSliderBar.cs index 1a894046d9..902609d7a6 100644 --- a/osu.Game/Graphics/UserInterface/NormalSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/NormalSliderBar.cs @@ -4,37 +4,27 @@ #nullable disable using System; -using System.Globalization; using JetBrains.Annotations; using osuTK; using osuTK.Graphics; using osu.Framework.Allocation; -using osu.Framework.Audio; -using osu.Framework.Audio.Sample; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; -using osu.Framework.Utils; using osu.Game.Overlays; namespace osu.Game.Graphics.UserInterface { - public partial class NormalSliderBar : OsuSliderBar, IHasAccentColour + public partial class NormalSliderBar : OsuSliderBar where T : struct, IEquatable, IComparable, IConvertible { - private Sample sample; - private double lastSampleTime; - private T lastSampleValue; - protected readonly Nub Nub; protected readonly Box LeftBox; protected readonly Box RightBox; private readonly Container nubContainer; - public bool PlaySamplesOnAdjust { get; set; } = true; - private readonly HoverClickSounds hoverClickSounds; private Color4 accentColour; @@ -118,9 +108,8 @@ namespace osu.Game.Graphics.UserInterface } [BackgroundDependencyLoader(true)] - private void load(AudioManager audio, [CanBeNull] OverlayColourProvider colourProvider, OsuColour colours) + private void load([CanBeNull] OverlayColourProvider colourProvider, OsuColour colours) { - sample = audio.Samples.Get(@"UI/notch-tick"); AccentColour = colourProvider?.Highlight1 ?? colours.Pink; BackgroundColour = colourProvider?.Background5 ?? colours.PinkDarker.Darken(1); } @@ -169,37 +158,6 @@ namespace osu.Game.Graphics.UserInterface Nub.Glowing = !Current.Disabled && (IsHovered || IsDragged); } - protected override void OnUserChange(T value) - { - base.OnUserChange(value); - playSample(value); - } - - private void playSample(T value) - { - if (!PlaySamplesOnAdjust) - return; - - if (Clock == null || Clock.CurrentTime - lastSampleTime <= 30) - return; - - if (value.Equals(lastSampleValue)) - return; - - lastSampleValue = value; - lastSampleTime = Clock.CurrentTime; - - var channel = sample.GetChannel(); - - channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + NormalizedValue * 0.2f; - - // intentionally pitched down, even when hitting max. - if (NormalizedValue == 0 || NormalizedValue == 1) - channel.Frequency.Value -= 0.5f; - - channel.Play(); - } - protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); @@ -211,14 +169,5 @@ namespace osu.Game.Graphics.UserInterface { Nub.MoveToX(value, 250, Easing.OutQuint); } - - /// - /// Removes all non-significant digits, keeping at most a requested number of decimal digits. - /// - /// The decimal to normalize. - /// The maximum number of decimal digits to keep. The final result may have fewer decimal digits than this value. - /// The normalised decimal. - private decimal normalise(decimal d, int sd) - => decimal.Parse(Math.Round(d, sd).ToString(string.Concat("0.", new string('#', sd)), CultureInfo.InvariantCulture), CultureInfo.InvariantCulture); } } diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 6a8f81a4b6..ee1f75c419 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -3,9 +3,13 @@ using System; using System.Globalization; +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; +using osu.Framework.Utils; using osu.Game.Utils; namespace osu.Game.Graphics.UserInterface @@ -13,6 +17,19 @@ namespace osu.Game.Graphics.UserInterface public abstract partial class OsuSliderBar : SliderBar, IHasTooltip where T : struct, IEquatable, IComparable, IConvertible { + private Sample sample = null!; + + private double lastSampleTime; + private T lastSampleValue; + + public bool PlaySamplesOnAdjust { get; set; } = true; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + sample = audio.Samples.Get(@"UI/notch-tick"); + } + public virtual LocalisableString TooltipText { get; private set; } /// @@ -34,9 +51,37 @@ namespace osu.Game.Graphics.UserInterface protected override void OnUserChange(T value) { base.OnUserChange(value); + + playSample(value); + TooltipText = getTooltipText(value); } + private void playSample(T value) + { + if (!PlaySamplesOnAdjust) + return; + + if (Clock == null || Clock.CurrentTime - lastSampleTime <= 30) + return; + + if (value.Equals(lastSampleValue)) + return; + + lastSampleValue = value; + lastSampleTime = Clock.CurrentTime; + + var channel = sample.GetChannel(); + + channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + NormalizedValue * 0.2f; + + // intentionally pitched down, even when hitting max. + if (NormalizedValue == 0 || NormalizedValue == 1) + channel.Frequency.Value -= 0.5f; + + channel.Play(); + } + private LocalisableString getTooltipText(T value) { if (CurrentNumber.IsInteger)