diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs deleted file mode 100644 index 8a64f7c9a4..0000000000 --- a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using osu.Framework.Graphics; -using osu.Framework.Configuration; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using OpenTK; - -namespace osu.Game.Tests.Visual -{ - public class TestCaseSliderBarPercentage : OsuTestCase - { - public override IReadOnlyList RequiredTypes => new[] { typeof(OsuSliderBar<>) }; - - private readonly BindableFloat floatValue; - private readonly BindableDouble doubleValue; - - private readonly TestSliderBar floatSliderBar; - private readonly TestSliderBar doubleSliderBar; - - public TestCaseSliderBarPercentage() - { - floatValue = new BindableFloat - { - MinValue = -1, - MaxValue = 1, - }; - - doubleValue = new BindableDouble - { - MinValue = -1, - MaxValue = 1 - }; - - Child = new FillFlowContainer - { - AutoSizeAxes = Axes.Y, - Width = 300, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 20), - Children = new Drawable[] - { - floatSliderBar = new TestSliderBar { RelativeSizeAxes = Axes.X }, - doubleSliderBar = new TestSliderBar { RelativeSizeAxes = Axes.X } - } - }; - - floatSliderBar.Current.BindTo(floatValue); - doubleSliderBar.Current.BindTo(doubleValue); - - floatValue.ValueChanged += setValue; - doubleValue.ValueChanged += setValue; - - AddStep("Digits = 0", () => setPercentageDigits(0)); - AddStep("Value = 0", () => setValue(0)); - AddAssert("Check 0%", () => checkExact(0)); - - AddStep("Value = 0.5", () => setValue(0.5)); - AddAssert("Check 50%", () => checkExact(0.5m)); - - AddStep("Value = 0.54", () => setValue(0.54)); - AddAssert("Check 54%", () => checkExact(0.54m)); - - AddStep("Value = 0.544", () => setValue(0.544)); - AddAssert("Check 54%", () => checkExact(0.54m)); - - AddStep("Value = 0.548", () => setValue(0.548)); - AddAssert("Check 55%", () => checkExact(0.55m)); - - AddStep("Digits = 1", () => setPercentageDigits(1)); - AddAssert("Check 54.8%", () => checkExact(0.548m)); - - AddSliderStep("Percentage", -1.0, 1.0, 0.0, setValue); - AddSliderStep("Digits", 0, 7, 1, setPercentageDigits); - } - - private bool checkExact(decimal percentage) - { - string expectedValue = percentage.ToString("P", floatSliderBar.Format); - return floatSliderBar.TooltipText == expectedValue && doubleSliderBar.TooltipText == expectedValue; - } - - private void setValue(T value) - { - floatValue.Value = Convert.ToSingle(value); - doubleValue.Value = Convert.ToDouble(value); - } - - private void setPercentageDigits(int digits) - { - floatSliderBar.Format.PercentDecimalDigits = digits; - doubleSliderBar.Format.PercentDecimalDigits = digits; - - // Make sure that the text referenced in TestSliderBar is updated - // This doesn't break any assertions if missing, but breaks the visual display - floatSliderBar.Current.TriggerChange(); - doubleSliderBar.Current.TriggerChange(); - } - - private class TestSliderBar : OsuSliderBar - where T : struct, IEquatable, IComparable, IConvertible - { - public TestSliderBar() - { - SpriteText valueText; - AddInternal(valueText = new OsuSpriteText - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreLeft, - X = 5, - Text = TooltipText - }); - - Current.ValueChanged += v => valueText.Text = TooltipText; - } - } - } -} diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs deleted file mode 100644 index af2b9be351..0000000000 --- a/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using OpenTK; - -namespace osu.Game.Tests.Visual -{ - public class TestCaseSliderBarPrecision : OsuTestCase - { - public override IReadOnlyList RequiredTypes => new[] { typeof(OsuSliderBar<>) }; - - private readonly BindableInt intValue; - private readonly BindableFloat floatValue; - private readonly BindableDouble doubleValue; - - private readonly TestSliderBar intSliderBar; - private readonly TestSliderBar floatSliderBar; - private readonly TestSliderBar doubleSliderBar; - - public TestCaseSliderBarPrecision() - { - intValue = new BindableInt - { - MinValue = -1000, - MaxValue = 1000, - }; - - floatValue = new BindableFloat - { - MinValue = -1000, - MaxValue = 1000, - }; - - doubleValue = new BindableDouble - { - MinValue = -1000, - MaxValue = 1000 - }; - - Child = new FillFlowContainer - { - AutoSizeAxes = Axes.Y, - Width = 300, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 20), - Children = new Drawable[] - { - intSliderBar = new TestSliderBar { RelativeSizeAxes = Axes.X }, - floatSliderBar = new TestSliderBar { RelativeSizeAxes = Axes.X }, - doubleSliderBar = new TestSliderBar { RelativeSizeAxes = Axes.X } - } - }; - - intSliderBar.Current.BindTo(intValue); - floatSliderBar.Current.BindTo(floatValue); - doubleSliderBar.Current.BindTo(doubleValue); - - intValue.ValueChanged += setValue; - floatValue.ValueChanged += setValue; - doubleValue.ValueChanged += setValue; - - AddStep("Value = 0", () => setValue(0)); - AddStep("Digits = 0", () => setDecimalDigits(0)); - AddAssert("Check all 0", () => checkExact("0")); - - AddStep("Digits = 3", () => setDecimalDigits(3)); - AddAssert("Check 0.000", () => checkExact(0.000m)); - - AddStep("Value = 0.5", () => setValue(0.5)); - AddAssert("Check 0.500", () => checkExact(0.500m)); - - AddStep("Value = 123.4567", () => setValue(123.4567)); - AddAssert("Check 123.457", () => checkExact(123.457m)); - - AddStep("Value = 765.4312", () => setValue(765.4312)); - AddAssert("Check 765.431", () => checkExact(765.431m)); - - AddStep("Value = -12.3456", () => setValue(-12.3456)); - AddAssert("Check -12.346", () => checkExact(-12.346m)); - AddStep("Digits = 1", () => setDecimalDigits(1)); - AddAssert("Check -12.3", () => checkExact(-12.3m)); - AddStep("Digits = 0", () => setDecimalDigits(0)); - AddAssert("Check -12", () => checkExact(-12m)); - - AddStep("Value = -12.8", () => setValue(-12.8)); - AddAssert("Check -13", () => checkExact(-13m)); - AddStep("Digits = 1", () => setDecimalDigits(1)); - AddAssert("Check -12.8", () => checkExact(-12.8m)); - - AddSliderStep("Digits", 0, 7, 1, setDecimalDigits); - } - - /// - /// Checks whether all sliderbar tooltips display an exact value. - /// - /// The expected value that should be displayed. - private bool checkExact(string value) - => intSliderBar.TooltipText == value - && floatSliderBar.TooltipText == value - && doubleSliderBar.TooltipText == value; - - /// - /// Checks whether all sliderbar tooltips display an exact value. - /// - /// The expected value that should be displayed. - private bool checkExact(decimal value) - { - var expectedDecimal = value.ToString(intSliderBar.Format); - - return intSliderBar.TooltipText == Convert.ToInt32(value).ToString("N0") - && floatSliderBar.TooltipText == expectedDecimal - && doubleSliderBar.TooltipText == expectedDecimal; - } - - /// - /// Checks whether all floating-point sliderbar tooltips have a certain number of decimal digits. - /// - /// The expected number of decimal digits. - private bool checkDecimalDigits(int decimals) - => checkDecimalDigits(decimals, floatSliderBar.TooltipText) - && checkDecimalDigits(decimals, doubleSliderBar.TooltipText); - - private bool checkDecimalDigits(int decimals, string value) - => value.Length - value.IndexOf(intSliderBar.Format.NumberDecimalSeparator, StringComparison.InvariantCulture) - 1 == decimals; - - private void setValue(T value) - { - intValue.Value = Convert.ToInt32(value); - floatValue.Value = Convert.ToSingle(value); - doubleValue.Value = Convert.ToDouble(value); - } - - private void setDecimalDigits(int digits) - { - intSliderBar.Format.NumberDecimalDigits = digits; - floatSliderBar.Format.NumberDecimalDigits = digits; - doubleSliderBar.Format.NumberDecimalDigits = digits; - - // Make sure that the text referenced in TestSliderBar is updated - // This doesn't break any assertions if missing, but breaks the visual display - intSliderBar.Current.TriggerChange(); - floatSliderBar.Current.TriggerChange(); - doubleSliderBar.Current.TriggerChange(); - } - - private class TestSliderBar : OsuSliderBar - where T : struct, IEquatable, IComparable, IConvertible - { - public TestSliderBar() - { - SpriteText valueText; - AddInternal(valueText = new OsuSpriteText - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreLeft, - X = 5, - Text = TooltipText - }); - - Current.ValueChanged += v => valueText.Text = TooltipText; - } - } - } -} diff --git a/osu.Game.Tests/osu.Game.Tests.csproj b/osu.Game.Tests/osu.Game.Tests.csproj index 53d971a0b3..8c04874e75 100644 --- a/osu.Game.Tests/osu.Game.Tests.csproj +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -132,8 +132,6 @@ - - diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index d42efe6678..f574ac13f7 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -28,24 +28,6 @@ namespace osu.Game.Graphics.UserInterface private readonly Box leftBox; private readonly Box rightBox; - private NumberFormatInfo format; - public NumberFormatInfo Format - { - get => format ?? (format = createDefaultFormat()); - set - { - if (format == value) - return; - format = value; - - if (IsLoaded) - { - // Some users may want to see the updated ToolTipText - Current.TriggerChange(); - } - } - } - public virtual string TooltipText { get @@ -60,9 +42,9 @@ namespace osu.Game.Graphics.UserInterface var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat.MaxValue; if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1)) - return floatValue.Value.ToString("P", Format); + return floatValue.Value.ToString("P0"); - return floatValue.Value.ToString("F", Format); + return floatValue.Value.ToString("N1"); } var bindableInt = CurrentNumber as BindableNumber; diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index 56aa77a24f..708d9437a5 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Globalization; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; @@ -24,15 +23,6 @@ namespace osu.Game.Overlays.Settings RelativeSizeAxes = Axes.X }; - /// - /// The format that will be used for the tooltip when the sliderbar is hovered. - /// - public NumberFormatInfo Format - { - get => ((U)Control).Format; - set => ((U)Control).Format = value; - } - public float KeyboardStep; [BackgroundDependencyLoader] diff --git a/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs b/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs index 65d83480a0..a63a3415e3 100644 --- a/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs +++ b/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs @@ -59,7 +59,6 @@ namespace osu.Game.Screens.Play.ReplaySettings } }; - sliderbar.Format.NumberDecimalDigits = 2; sliderbar.Bindable.ValueChanged += rateMultiplier => multiplierText.Text = $"{rateMultiplier}x"; } @@ -73,5 +72,6 @@ namespace osu.Game.Screens.Play.ReplaySettings var clockRate = AdjustableClock.Rate; sliderbar.Bindable.ValueChanged += rateMultiplier => AdjustableClock.Rate = clockRate * rateMultiplier; } + } } diff --git a/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs b/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs index 724f28dadf..e755e6bfd9 100644 --- a/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs +++ b/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs @@ -21,6 +21,8 @@ namespace osu.Game.Screens.Play.ReplaySettings private class Sliderbar : OsuSliderBar { + public override string TooltipText => $"{CurrentNumber.Value}"; + [BackgroundDependencyLoader] private void load(OsuColour colours) {