From ddc9edab5423899579c1f50ff0909e1a34e7ac2f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 14:33:28 +0900 Subject: [PATCH 01/13] Make OsuSliderBar support both float and double values --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index fd75269610..4ff65dea93 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -32,11 +32,18 @@ namespace osu.Game.Graphics.UserInterface get { var bindableDouble = CurrentNumber as BindableNumber; - if (bindableDouble != null) + var bindableFloat = CurrentNumber as BindableNumber; + var floatValue = bindableDouble?.Value ?? bindableFloat?.Value ?? null; + + if (floatValue != null) { - if (bindableDouble.MaxValue == 1 && (bindableDouble.MinValue == 0 || bindableDouble.MinValue == -1)) - return bindableDouble.Value.ToString(@"P0"); - return bindableDouble.Value.ToString(@"n1"); + var floatMinValue = bindableDouble?.MinValue ?? bindableFloat?.MinValue ?? null; + var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat?.MaxValue ?? null; + + if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1)) + return floatValue.Value.ToString(@"P0"); + + return floatValue.Value.ToString(@"n1"); } var bindableInt = CurrentNumber as BindableNumber; From 08af3e6303e3e95064c8b5d6e6717aa1f377fd2f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 14:34:50 +0900 Subject: [PATCH 02/13] Make OsuSliderBar formatting support variable number of digits --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 4ff65dea93..bbbe710313 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Globalization; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; @@ -27,6 +28,11 @@ namespace osu.Game.Graphics.UserInterface private readonly Box leftBox; private readonly Box rightBox; + /// + /// The amount of decimal digits to display for s with floating point values. + /// + public int TooltipDecimalDigits = 1; + public virtual string TooltipText { get @@ -43,7 +49,10 @@ namespace osu.Game.Graphics.UserInterface if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1)) return floatValue.Value.ToString(@"P0"); - return floatValue.Value.ToString(@"n1"); + var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); + nfi.NumberDecimalDigits = TooltipDecimalDigits; + + return string.Format(nfi, "{0:F}", floatValue.Value); } var bindableInt = CurrentNumber as BindableNumber; From eaa2a007e779e8003698a8037409a1ab90f0f64d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 16:12:15 +0900 Subject: [PATCH 03/13] Cleanup --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index bbbe710313..c282ed96d6 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -39,12 +39,12 @@ namespace osu.Game.Graphics.UserInterface { var bindableDouble = CurrentNumber as BindableNumber; var bindableFloat = CurrentNumber as BindableNumber; - var floatValue = bindableDouble?.Value ?? bindableFloat?.Value ?? null; + var floatValue = bindableDouble?.Value ?? bindableFloat?.Value; if (floatValue != null) { - var floatMinValue = bindableDouble?.MinValue ?? bindableFloat?.MinValue ?? null; - var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat?.MaxValue ?? null; + var floatMinValue = bindableDouble?.MinValue ?? bindableFloat.MinValue; + var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat.MaxValue; if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1)) return floatValue.Value.ToString(@"P0"); From b84f83cf165cc746308fbb44f94e3c53e6e436f8 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 16:12:48 +0900 Subject: [PATCH 04/13] Trigger a value changed event when the number of digits changes --- .../Graphics/UserInterface/OsuSliderBar.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index c282ed96d6..a5fb2de395 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -28,10 +28,26 @@ namespace osu.Game.Graphics.UserInterface private readonly Box leftBox; private readonly Box rightBox; + private int tooltipDecimalDigits = 1; /// /// The amount of decimal digits to display for s with floating point values. /// - public int TooltipDecimalDigits = 1; + public int TooltipDecimalDigits + { + get => tooltipDecimalDigits; + set + { + if (tooltipDecimalDigits == value) + return; + tooltipDecimalDigits = value; + + if (IsLoaded) + { + // Some users may want to see the updated ToolTipText + Current.TriggerChange(); + } + } + } public virtual string TooltipText { From cbf48524385b9c920f1736880ce01175b49a1c79 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 17:00:38 +0900 Subject: [PATCH 05/13] Expose a NumberFormatInfo for more extensibility --- .../Graphics/UserInterface/OsuSliderBar.cs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index a5fb2de395..701a9d4460 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -28,18 +28,15 @@ namespace osu.Game.Graphics.UserInterface private readonly Box leftBox; private readonly Box rightBox; - private int tooltipDecimalDigits = 1; - /// - /// The amount of decimal digits to display for s with floating point values. - /// - public int TooltipDecimalDigits + private NumberFormatInfo format; + public NumberFormatInfo Format { - get => tooltipDecimalDigits; + get => format ?? (format = createDefaultFormat()); set { - if (tooltipDecimalDigits == value) + if (format == value) return; - tooltipDecimalDigits = value; + format = value; if (IsLoaded) { @@ -63,17 +60,14 @@ namespace osu.Game.Graphics.UserInterface var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat.MaxValue; if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1)) - return floatValue.Value.ToString(@"P0"); + return floatValue.Value.ToString("P", Format); - var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); - nfi.NumberDecimalDigits = TooltipDecimalDigits; - - return string.Format(nfi, "{0:F}", floatValue.Value); + return floatValue.Value.ToString("F", Format); } var bindableInt = CurrentNumber as BindableNumber; if (bindableInt != null) - return bindableInt.Value.ToString(@"n0"); + return bindableInt.Value.ToString("N0"); return Current.Value.ToString(); } @@ -137,6 +131,15 @@ namespace osu.Game.Graphics.UserInterface AccentColour = colours.Pink; } + private NumberFormatInfo createDefaultFormat() + { + var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); + nfi.PercentDecimalDigits = 0; + nfi.NumberDecimalDigits = 1; + + return nfi; + } + protected override bool OnHover(InputState state) { Nub.Glowing = true; From 76f4bb1ca08d9257f1dbac24493f4a83d4d15dbf Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 17:00:51 +0900 Subject: [PATCH 06/13] Add automated test cases --- .../Visual/TestCaseSliderBarPercentage.cs | 123 +++++++++++++ .../Visual/TestCaseSliderBarPrecision.cs | 172 ++++++++++++++++++ osu.Game.Tests/osu.Game.Tests.csproj | 2 + 3 files changed, 297 insertions(+) create mode 100644 osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs create mode 100644 osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs new file mode 100644 index 0000000000..5c4d545348 --- /dev/null +++ b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs @@ -0,0 +1,123 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/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 + { + 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 new file mode 100644 index 0000000000..928ba0d825 --- /dev/null +++ b/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs @@ -0,0 +1,172 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/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 + { + 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 8c04874e75..53d971a0b3 100644 --- a/osu.Game.Tests/osu.Game.Tests.csproj +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -132,6 +132,8 @@ + + From b84da31174403e3790d39d2afa92a742b8686742 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 2 Jan 2018 23:20:58 +0900 Subject: [PATCH 07/13] Change in-line with framework --- osu.Game/Overlays/OnScreenDisplay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index ce0feeb4c6..9a35551645 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -139,7 +139,7 @@ namespace osu.Game.Overlays private readonly List references = new List(); - private void trackSetting(Bindable bindable, Bindable.BindableValueChanged action) + private void trackSetting(Bindable bindable, Action action) { // we need to keep references as we bind references.Add(bindable); From 1571c10c4255213282df82ef686b77ea34900a85 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 5 Jan 2018 14:37:32 +0900 Subject: [PATCH 08/13] Fix up replay settings sliderbar formatting --- osu.Game/Overlays/Settings/SettingsSlider.cs | 13 +++++++++++-- .../Screens/Play/ReplaySettings/PlaybackSettings.cs | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index 49d73f77ec..db6e5e3f2e 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -2,9 +2,9 @@ // 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.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Settings @@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Settings public class SettingsSlider : SettingsItem where T : struct, IEquatable - where U : SliderBar, new() + where U : OsuSliderBar, new() { protected override Drawable CreateControl() => new U { @@ -24,6 +24,15 @@ 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 3109552532..a7b03c3742 100644 --- a/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs +++ b/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs @@ -59,6 +59,7 @@ namespace osu.Game.Screens.Play.ReplaySettings } }; + sliderbar.Format.NumberDecimalDigits = 2; sliderbar.Bindable.ValueChanged += rateMultiplier => multiplierText.Text = $"{rateMultiplier}x"; } From c9692a44f9b044a2100d7a86b250b2aa7f9c0bfe Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Jan 2018 21:04:21 +0900 Subject: [PATCH 09/13] Fix framework licence headers in osu project --- osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs | 2 +- osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs index 5c4d545348..ce32dbe889 100644 --- a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs +++ b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs @@ -1,5 +1,5 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs index 928ba0d825..c4b3a63bf2 100644 --- a/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs +++ b/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs @@ -1,5 +1,5 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; From 17e7f75aca98dc5dc826b35bd29202c9bba841dc Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 10 Jan 2018 15:41:13 +0900 Subject: [PATCH 10/13] More osu!-side bindable fixes --- osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs | 2 +- osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs | 2 +- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 4 ++-- osu.Game/Overlays/Settings/SettingsSlider.cs | 4 ++-- osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs index ce32dbe889..8a64f7c9a4 100644 --- a/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs +++ b/osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs @@ -103,7 +103,7 @@ namespace osu.Game.Tests.Visual } private class TestSliderBar : OsuSliderBar - where T : struct, IEquatable + where T : struct, IEquatable, IComparable, IConvertible { public TestSliderBar() { diff --git a/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs b/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs index c4b3a63bf2..af2b9be351 100644 --- a/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs +++ b/osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs @@ -152,7 +152,7 @@ namespace osu.Game.Tests.Visual } private class TestSliderBar : OsuSliderBar - where T : struct, IEquatable + where T : struct, IEquatable, IComparable, IConvertible { public TestSliderBar() { diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index e3d9a89bf7..d42efe6678 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -18,7 +18,7 @@ using osu.Framework.Graphics.Shapes; namespace osu.Game.Graphics.UserInterface { public class OsuSliderBar : SliderBar, IHasTooltip, IHasAccentColour - where T : struct, IEquatable + where T : struct, IEquatable, IComparable, IConvertible { private SampleChannel sample; private double lastSampleTime; @@ -69,7 +69,7 @@ namespace osu.Game.Graphics.UserInterface if (bindableInt != null) return bindableInt.Value.ToString("N0"); - return Current.Value.ToString(); + return Current.Value.ToString(CultureInfo.InvariantCulture); } } diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index 43f1fa6a02..56aa77a24f 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -10,12 +10,12 @@ using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Settings { public class SettingsSlider : SettingsSlider> - where T : struct, IEquatable + where T : struct, IEquatable, IComparable, IConvertible { } public class SettingsSlider : SettingsItem - where T : struct, IEquatable + where T : struct, IEquatable, IComparable, IConvertible where U : OsuSliderBar, new() { protected override Drawable CreateControl() => new U diff --git a/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs b/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs index e6e909183d..724f28dadf 100644 --- a/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs +++ b/osu.Game/Screens/Play/ReplaySettings/ReplaySliderBar.cs @@ -11,7 +11,7 @@ using osu.Game.Overlays.Settings; namespace osu.Game.Screens.Play.ReplaySettings { public class ReplaySliderBar : SettingsSlider - where T : struct, IEquatable + where T : struct, IEquatable, IComparable, IConvertible { protected override Drawable CreateControl() => new Sliderbar { From c010b48b2984e1c625505a778d904a2c3b0b79c7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 10 Jan 2018 17:29:16 +0900 Subject: [PATCH 11/13] Remove number format specified from OsuSliderBar, override ToolTipText Better/cleaner solution. --- .../Visual/TestCaseSliderBarPercentage.cs | 123 ------------- .../Visual/TestCaseSliderBarPrecision.cs | 172 ------------------ osu.Game.Tests/osu.Game.Tests.csproj | 2 - .../Graphics/UserInterface/OsuSliderBar.cs | 22 +-- osu.Game/Overlays/Settings/SettingsSlider.cs | 10 - .../Play/ReplaySettings/PlaybackSettings.cs | 2 +- .../Play/ReplaySettings/ReplaySliderBar.cs | 2 + 7 files changed, 5 insertions(+), 328 deletions(-) delete mode 100644 osu.Game.Tests/Visual/TestCaseSliderBarPercentage.cs delete mode 100644 osu.Game.Tests/Visual/TestCaseSliderBarPrecision.cs 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) { From d1476833619261ed5ff136d6faf33069cf9ad2dc Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 10 Jan 2018 17:39:15 +0900 Subject: [PATCH 12/13] Cleanup --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 9 --------- osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs | 1 - 2 files changed, 10 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index f574ac13f7..3c3939586e 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -113,15 +113,6 @@ namespace osu.Game.Graphics.UserInterface AccentColour = colours.Pink; } - private NumberFormatInfo createDefaultFormat() - { - var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); - nfi.PercentDecimalDigits = 0; - nfi.NumberDecimalDigits = 1; - - return nfi; - } - protected override bool OnHover(InputState state) { Nub.Glowing = true; diff --git a/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs b/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs index a63a3415e3..f8ac653f69 100644 --- a/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs +++ b/osu.Game/Screens/Play/ReplaySettings/PlaybackSettings.cs @@ -72,6 +72,5 @@ namespace osu.Game.Screens.Play.ReplaySettings var clockRate = AdjustableClock.Rate; sliderbar.Bindable.ValueChanged += rateMultiplier => AdjustableClock.Rate = clockRate * rateMultiplier; } - } } From 98894f010fada7224403248726d90825ccf64844 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Jan 2018 18:57:53 +0900 Subject: [PATCH 13/13] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 80bcb82ef8..49b563e2cf 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 80bcb82ef8d2e1af1ce077f4a037b6d279ad9e74 +Subproject commit 49b563e2cf170eb19006b98dd5b69c2398362d9e