Merge pull request #18962 from peppy/slider-range-control

Move star difficulty filter to song select
This commit is contained in:
Dan Balasescu 2022-07-03 21:58:00 +09:00 committed by GitHub
commit 9bf91835b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 181 additions and 49 deletions

View File

@ -0,0 +1,28 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Screens.Select;
using osuTK;
namespace osu.Game.Tests.Visual.SongSelect
{
public class TestSceneDifficultyRangeFilterControl : OsuTestScene
{
[Test]
public void TestBasic()
{
AddStep("create control", () =>
{
Child = new DifficultyRangeFilterControl
{
Width = 200,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(3),
};
});
}
}
}

View File

@ -19,7 +19,7 @@
namespace osu.Game.Graphics.UserInterface
{
public class Nub : CompositeDrawable, IHasCurrentValue<bool>, IHasAccentColour
public class Nub : Container, IHasCurrentValue<bool>, IHasAccentColour
{
public const float HEIGHT = 15;

View File

@ -38,8 +38,8 @@ public class OsuSliderBar<T> : SliderBar<T>, IHasTooltip, IHasAccentColour
private T lastSampleValue;
protected readonly Nub Nub;
private readonly Box leftBox;
private readonly Box rightBox;
protected readonly Box LeftBox;
protected readonly Box RightBox;
private readonly Container nubContainer;
public virtual LocalisableString TooltipText { get; private set; }
@ -57,7 +57,7 @@ public Color4 AccentColour
set
{
accentColour = value;
leftBox.Colour = value;
LeftBox.Colour = value;
}
}
@ -69,7 +69,7 @@ public Color4 BackgroundColour
set
{
backgroundColour = value;
rightBox.Colour = value;
RightBox.Colour = value;
}
}
@ -96,7 +96,7 @@ public OsuSliderBar()
CornerRadius = 5f,
Children = new Drawable[]
{
leftBox = new Box
LeftBox = new Box
{
Height = 5,
EdgeSmoothness = new Vector2(0, 0.5f),
@ -104,14 +104,13 @@ public OsuSliderBar()
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
rightBox = new Box
RightBox = new Box
{
Height = 5,
EdgeSmoothness = new Vector2(0, 0.5f),
RelativeSizeAxes = Axes.None,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Alpha = 0.5f,
},
},
},
@ -137,7 +136,7 @@ private void load(AudioManager audio, [CanBeNull] OverlayColourProvider colourPr
{
sample = audio.Samples.Get(@"UI/notch-tick");
AccentColour = colourProvider?.Highlight1 ?? colours.Pink;
BackgroundColour = colourProvider?.Background5 ?? colours.Pink.Opacity(0.5f);
BackgroundColour = colourProvider?.Background5 ?? colours.PinkDarker.Darken(1);
}
protected override void Update()
@ -229,9 +228,9 @@ private LocalisableString getTooltipText(T value)
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
leftBox.Scale = new Vector2(Math.Clamp(
LeftBox.Scale = new Vector2(Math.Clamp(
RangePadding + Nub.DrawPosition.X - Nub.DrawWidth / 2, 0, DrawWidth), 1);
rightBox.Scale = new Vector2(Math.Clamp(
RightBox.Scale = new Vector2(Math.Clamp(
DrawWidth - Nub.DrawPosition.X - RangePadding - Nub.DrawWidth / 2, 0, DrawWidth), 1);
}

View File

@ -3,13 +3,10 @@
#nullable disable
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays.Mods.Input;
@ -17,20 +14,11 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
{
public class SongSelectSettings : SettingsSubsection
{
private Bindable<double> minStars;
private Bindable<double> maxStars;
protected override LocalisableString Header => UserInterfaceStrings.SongSelectHeader;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
minStars = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum);
maxStars = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum);
minStars.ValueChanged += min => maxStars.Value = Math.Max(min.NewValue, maxStars.Value);
maxStars.ValueChanged += max => minStars.Value = Math.Min(max.NewValue, minStars.Value);
Children = new Drawable[]
{
new SettingsCheckbox
@ -44,20 +32,6 @@ private void load(OsuConfigManager config)
LabelText = UserInterfaceStrings.ShowConvertedBeatmaps,
Current = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps),
},
new SettingsSlider<double, StarsSlider>
{
LabelText = UserInterfaceStrings.StarsMinimum,
Current = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum),
KeyboardStep = 0.1f,
Keywords = new[] { "minimum", "maximum", "star", "difficulty" }
},
new SettingsSlider<double, MaximumStarsSlider>
{
LabelText = UserInterfaceStrings.StarsMaximum,
Current = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum),
KeyboardStep = 0.1f,
Keywords = new[] { "minimum", "maximum", "star", "difficulty" }
},
new SettingsEnumDropdown<RandomSelectAlgorithm>
{
LabelText = UserInterfaceStrings.RandomSelectionAlgorithm,
@ -71,15 +45,5 @@ private void load(OsuConfigManager config)
}
};
}
private class MaximumStarsSlider : StarsSlider
{
public override LocalisableString TooltipText => Current.IsDefault ? UserInterfaceStrings.NoLimit : base.TooltipText;
}
private class StarsSlider : OsuSliderBar<double>
{
public override LocalisableString TooltipText => Current.Value.ToString(@"0.## stars");
}
}
}

View File

@ -0,0 +1,133 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Select
{
internal class DifficultyRangeFilterControl : CompositeDrawable
{
private Bindable<double> lowerStars = null!;
private Bindable<double> upperStars = null!;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
const float vertical_offset = 13;
InternalChildren = new Drawable[]
{
new OsuSpriteText
{
Text = "Difficulty range",
Font = OsuFont.GetFont(size: 14),
},
new MaximumStarsSlider
{
Current = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum),
KeyboardStep = 0.1f,
RelativeSizeAxes = Axes.X,
Y = vertical_offset,
},
new MinimumStarsSlider
{
Current = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum),
KeyboardStep = 0.1f,
RelativeSizeAxes = Axes.X,
Y = vertical_offset,
}
};
lowerStars = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum);
upperStars = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum);
}
protected override void LoadComplete()
{
base.LoadComplete();
lowerStars.ValueChanged += min => upperStars.Value = Math.Max(min.NewValue + 0.1, upperStars.Value);
upperStars.ValueChanged += max => lowerStars.Value = Math.Min(max.NewValue - 0.1, lowerStars.Value);
}
private class MinimumStarsSlider : StarsSlider
{
protected override void LoadComplete()
{
base.LoadComplete();
LeftBox.Height = 6; // hide any colour bleeding from overlap
AccentColour = BackgroundColour;
BackgroundColour = Color4.Transparent;
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
base.ReceivePositionalInputAt(screenSpacePos)
&& screenSpacePos.X <= Nub.ScreenSpaceDrawQuad.TopRight.X;
}
private class MaximumStarsSlider : StarsSlider
{
protected override void LoadComplete()
{
base.LoadComplete();
RightBox.Height = 6; // just to match the left bar height really
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
base.ReceivePositionalInputAt(screenSpacePos)
&& screenSpacePos.X >= Nub.ScreenSpaceDrawQuad.TopLeft.X;
}
private class StarsSlider : OsuSliderBar<double>
{
public override LocalisableString TooltipText => Current.IsDefault
? UserInterfaceStrings.NoLimit
: Current.Value.ToString(@"0.## stars");
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
return true; // Make sure only one nub shows hover effect at once.
}
protected override void LoadComplete()
{
base.LoadComplete();
Nub.Width = Nub.HEIGHT;
RangePadding = Nub.Width / 2;
OsuSpriteText currentDisplay;
Nub.Add(currentDisplay = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = -0.5f,
Colour = Color4.White,
Font = OsuFont.Torus.With(size: 10),
});
Current.BindValueChanged(current =>
{
currentDisplay.Text = current.NewValue != Current.Default ? current.NewValue.ToString("N1") : "∞";
}, true);
}
}
}
}

View File

@ -155,15 +155,23 @@ private void load(OsuColour colours, IBindable<RulesetInfo> parentRuleset, OsuCo
new Container
{
RelativeSizeAxes = Axes.X,
Height = 20,
Height = 40,
Children = new Drawable[]
{
new DifficultyRangeFilterControl
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Width = 0.48f,
},
collectionDropdown = new CollectionFilterDropdown
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
Width = 0.4f,
Y = 4,
Width = 0.5f,
}
}
},