From aa264cd2a8c89f77c966471661e6b76d781e27bf Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Jan 2020 12:32:30 +0800 Subject: [PATCH 1/6] allow tooltip to show as percentage as needed --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 8 ++++++-- .../Settings/Sections/Audio/VolumeSettings.cs | 8 ++++---- .../Settings/Sections/Gameplay/GeneralSettings.cs | 6 ++++-- .../Settings/Sections/Graphics/LayoutSettings.cs | 12 ++++++++---- osu.Game/Overlays/Settings/SettingsSlider.cs | 6 ++++++ .../Screens/Play/PlayerSettings/VisualSettings.cs | 10 ++++++++-- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 2112aac6a3..1058595232 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -35,6 +35,7 @@ namespace osu.Game.Graphics.UserInterface private readonly Container nubContainer; public virtual string TooltipText { get; private set; } + public bool DisplayAsPercentage { get; set; } private Color4 accentColour; @@ -172,8 +173,11 @@ namespace osu.Game.Graphics.UserInterface double floatMinValue = CurrentNumber.MinValue.ToDouble(NumberFormatInfo.InvariantInfo); double floatMaxValue = CurrentNumber.MaxValue.ToDouble(NumberFormatInfo.InvariantInfo); - if (floatMaxValue == 1 && floatMinValue >= -1) - TooltipText = floatValue.ToString("P0"); + if (DisplayAsPercentage) + { + double percentage = floatValue / floatMaxValue; + TooltipText = percentage.ToString("P0"); + } else { var decimalPrecision = normalise(CurrentNumber.Precision.ToDecimal(NumberFormatInfo.InvariantInfo), max_decimal_digits); diff --git a/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs index 0124f7090e..fe7f4c4908 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs @@ -17,10 +17,10 @@ namespace osu.Game.Overlays.Settings.Sections.Audio { Children = new Drawable[] { - new SettingsSlider { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.01f }, - new SettingsSlider { LabelText = "Master (window inactive)", Bindable = config.GetBindable(OsuSetting.VolumeInactive), KeyboardStep = 0.01f }, - new SettingsSlider { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.01f }, - new SettingsSlider { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.01f }, + new SettingsSlider { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.01f, DisplayAsPercentage = true }, + new SettingsSlider { LabelText = "Master (window inactive)", Bindable = config.GetBindable(OsuSetting.VolumeInactive), KeyboardStep = 0.01f, DisplayAsPercentage = true }, + new SettingsSlider { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.01f, DisplayAsPercentage = true }, + new SettingsSlider { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.01f, DisplayAsPercentage = true }, }; } } diff --git a/osu.Game/Overlays/Settings/Sections/Gameplay/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Gameplay/GeneralSettings.cs index 08bc67e43e..2d2cd42213 100644 --- a/osu.Game/Overlays/Settings/Sections/Gameplay/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Gameplay/GeneralSettings.cs @@ -21,13 +21,15 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay { LabelText = "Background dim", Bindable = config.GetBindable(OsuSetting.DimLevel), - KeyboardStep = 0.01f + KeyboardStep = 0.01f, + DisplayAsPercentage = true }, new SettingsSlider { LabelText = "Background blur", Bindable = config.GetBindable(OsuSetting.BlurLevel), - KeyboardStep = 0.01f + KeyboardStep = 0.01f, + DisplayAsPercentage = true }, new SettingsCheckbox { diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index 02b9edd975..efbb08b7df 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -98,25 +98,29 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics { LabelText = "Horizontal position", Bindable = scalingPositionX, - KeyboardStep = 0.01f + KeyboardStep = 0.01f, + DisplayAsPercentage = true }, new SettingsSlider { LabelText = "Vertical position", Bindable = scalingPositionY, - KeyboardStep = 0.01f + KeyboardStep = 0.01f, + DisplayAsPercentage = true }, new SettingsSlider { LabelText = "Horizontal scale", Bindable = scalingSizeX, - KeyboardStep = 0.01f + KeyboardStep = 0.01f, + DisplayAsPercentage = true }, new SettingsSlider { LabelText = "Vertical scale", Bindable = scalingSizeY, - KeyboardStep = 0.01f + KeyboardStep = 0.01f, + DisplayAsPercentage = true }, } }, diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index 96c0279a7b..a7485f77cd 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -33,5 +33,11 @@ namespace osu.Game.Overlays.Settings get => ((TSlider)Control).KeyboardStep; set => ((TSlider)Control).KeyboardStep = value; } + + public bool DisplayAsPercentage + { + get => ((TSlider)Control).DisplayAsPercentage; + set => ((TSlider)Control).DisplayAsPercentage = value; + } } } diff --git a/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs b/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs index ff64f35a18..9db3a587fa 100644 --- a/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs +++ b/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs @@ -27,12 +27,18 @@ namespace osu.Game.Screens.Play.PlayerSettings { Text = "Background dim:" }, - dimSliderBar = new PlayerSliderBar(), + dimSliderBar = new PlayerSliderBar + { + DisplayAsPercentage = true + }, new OsuSpriteText { Text = "Background blur:" }, - blurSliderBar = new PlayerSliderBar(), + blurSliderBar = new PlayerSliderBar + { + DisplayAsPercentage = true + }, new OsuSpriteText { Text = "Toggles:" From a3cfeb08d41d3b4b8235b6422fc35c8d5cf16b0d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Jan 2020 12:34:17 +0800 Subject: [PATCH 2/6] remove unused assignment --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 1058595232..d908f046bd 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -170,7 +170,6 @@ namespace osu.Game.Graphics.UserInterface else { double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo); - double floatMinValue = CurrentNumber.MinValue.ToDouble(NumberFormatInfo.InvariantInfo); double floatMaxValue = CurrentNumber.MaxValue.ToDouble(NumberFormatInfo.InvariantInfo); if (DisplayAsPercentage) From 894642d5883d75dcd9c1b294c6edde806994a06c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Jan 2020 18:04:00 +0800 Subject: [PATCH 3/6] add xmldoc and formatting --- .../Graphics/UserInterface/OsuSliderBar.cs | 4 +++ .../Settings/Sections/Audio/VolumeSettings.cs | 32 ++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index d908f046bd..2db1c881c0 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -35,6 +35,10 @@ namespace osu.Game.Graphics.UserInterface private readonly Container nubContainer; public virtual string TooltipText { get; private set; } + + /// + /// Whether to format the tooltip as a percentage or the actual value. + /// public bool DisplayAsPercentage { get; set; } private Color4 accentColour; diff --git a/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs index fe7f4c4908..bda677ecd6 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs @@ -17,10 +17,34 @@ namespace osu.Game.Overlays.Settings.Sections.Audio { Children = new Drawable[] { - new SettingsSlider { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.01f, DisplayAsPercentage = true }, - new SettingsSlider { LabelText = "Master (window inactive)", Bindable = config.GetBindable(OsuSetting.VolumeInactive), KeyboardStep = 0.01f, DisplayAsPercentage = true }, - new SettingsSlider { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.01f, DisplayAsPercentage = true }, - new SettingsSlider { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.01f, DisplayAsPercentage = true }, + new SettingsSlider + { + LabelText = "Master", + Bindable = audio.Volume, + KeyboardStep = 0.01f, + DisplayAsPercentage = true + }, + new SettingsSlider + { + LabelText = "Master (window inactive)", + Bindable = config.GetBindable(OsuSetting.VolumeInactive), + KeyboardStep = 0.01f, + DisplayAsPercentage = true + }, + new SettingsSlider + { + LabelText = "Effect", + Bindable = audio.VolumeSample, + KeyboardStep = 0.01f, + DisplayAsPercentage = true + }, + new SettingsSlider + { + LabelText = "Music", + Bindable = audio.VolumeTrack, + KeyboardStep = 0.01f, + DisplayAsPercentage = true + }, }; } } From cfc4eaff59c72c41e41f2b16485429b581dfa134 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Jan 2020 12:50:21 +0900 Subject: [PATCH 4/6] Fix display being incorrect when MaxValue is not 1 --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 2db1c881c0..5c6c7aeafd 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -174,12 +174,10 @@ namespace osu.Game.Graphics.UserInterface else { double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo); - double floatMaxValue = CurrentNumber.MaxValue.ToDouble(NumberFormatInfo.InvariantInfo); if (DisplayAsPercentage) { - double percentage = floatValue / floatMaxValue; - TooltipText = percentage.ToString("P0"); + TooltipText = floatValue.ToString("P0"); } else { From aa597c193468b5b2f4c798412b41f003ad5e1e2d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Jan 2020 12:55:07 +0900 Subject: [PATCH 5/6] Copy documentation across to SettingsSlider --- osu.Game/Overlays/Settings/SettingsSlider.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index a7485f77cd..9fc3379b94 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -3,6 +3,7 @@ using System; using osu.Framework.Graphics; +using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Settings @@ -22,18 +23,28 @@ namespace osu.Game.Overlays.Settings RelativeSizeAxes = Axes.X }; + /// + /// When set, value changes based on user input are only transferred to any bound control's Current on commit. + /// This is useful if the UI interaction could be adversely affected by the value changing, such as the position of the on the screen. + /// public bool TransferValueOnCommit { get => ((TSlider)Control).TransferValueOnCommit; set => ((TSlider)Control).TransferValueOnCommit = value; } + /// + /// A custom step value for each key press which actuates a change on this control. + /// public float KeyboardStep { get => ((TSlider)Control).KeyboardStep; set => ((TSlider)Control).KeyboardStep = value; } + /// + /// Whether to format the tooltip as a percentage or the actual value. + /// public bool DisplayAsPercentage { get => ((TSlider)Control).DisplayAsPercentage; From f457ecaf83968ce794e42bb6f8198c842b738aac Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 29 Jan 2020 13:54:12 +0900 Subject: [PATCH 6/6] Fix random test failures --- osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs index 98b8e3c5d6..fc06780431 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs @@ -118,6 +118,7 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.ReleaseKey(Key.Enter); }); + AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddAssert("ensure selection changed", () => selected != Beatmap.Value); AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen()); @@ -145,6 +146,7 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.ReleaseKey(Key.Down); }); + AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddAssert("ensure selection didn't change", () => selected == Beatmap.Value); AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen()); @@ -176,6 +178,7 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.ReleaseKey(Key.Enter); }); + AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddAssert("ensure selection changed", () => selected != Beatmap.Value); AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen()); @@ -208,6 +211,7 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.ReleaseButton(MouseButton.Left); }); + AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddAssert("ensure selection didn't change", () => selected == Beatmap.Value); AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen());