mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Merge pull request #18962 from peppy/slider-range-control
Move star difficulty filter to song select
This commit is contained in:
commit
9bf91835b6
@ -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),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@ using osu.Game.Overlays;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class Nub : CompositeDrawable, IHasCurrentValue<bool>, IHasAccentColour
|
public class Nub : Container, IHasCurrentValue<bool>, IHasAccentColour
|
||||||
{
|
{
|
||||||
public const float HEIGHT = 15;
|
public const float HEIGHT = 15;
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
private T lastSampleValue;
|
private T lastSampleValue;
|
||||||
|
|
||||||
protected readonly Nub Nub;
|
protected readonly Nub Nub;
|
||||||
private readonly Box leftBox;
|
protected readonly Box LeftBox;
|
||||||
private readonly Box rightBox;
|
protected readonly Box RightBox;
|
||||||
private readonly Container nubContainer;
|
private readonly Container nubContainer;
|
||||||
|
|
||||||
public virtual LocalisableString TooltipText { get; private set; }
|
public virtual LocalisableString TooltipText { get; private set; }
|
||||||
@ -57,7 +57,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
accentColour = value;
|
accentColour = value;
|
||||||
leftBox.Colour = value;
|
LeftBox.Colour = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
backgroundColour = value;
|
backgroundColour = value;
|
||||||
rightBox.Colour = value;
|
RightBox.Colour = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
CornerRadius = 5f,
|
CornerRadius = 5f,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
leftBox = new Box
|
LeftBox = new Box
|
||||||
{
|
{
|
||||||
Height = 5,
|
Height = 5,
|
||||||
EdgeSmoothness = new Vector2(0, 0.5f),
|
EdgeSmoothness = new Vector2(0, 0.5f),
|
||||||
@ -104,14 +104,13 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
},
|
},
|
||||||
rightBox = new Box
|
RightBox = new Box
|
||||||
{
|
{
|
||||||
Height = 5,
|
Height = 5,
|
||||||
EdgeSmoothness = new Vector2(0, 0.5f),
|
EdgeSmoothness = new Vector2(0, 0.5f),
|
||||||
RelativeSizeAxes = Axes.None,
|
RelativeSizeAxes = Axes.None,
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Alpha = 0.5f,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -137,7 +136,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
sample = audio.Samples.Get(@"UI/notch-tick");
|
sample = audio.Samples.Get(@"UI/notch-tick");
|
||||||
AccentColour = colourProvider?.Highlight1 ?? colours.Pink;
|
AccentColour = colourProvider?.Highlight1 ?? colours.Pink;
|
||||||
BackgroundColour = colourProvider?.Background5 ?? colours.Pink.Opacity(0.5f);
|
BackgroundColour = colourProvider?.Background5 ?? colours.PinkDarker.Darken(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -229,9 +228,9 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
{
|
{
|
||||||
base.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);
|
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);
|
DrawWidth - Nub.DrawPosition.X - RangePadding - Nub.DrawWidth / 2, 0, DrawWidth), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,10 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Overlays.Mods.Input;
|
using osu.Game.Overlays.Mods.Input;
|
||||||
|
|
||||||
@ -17,20 +14,11 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
|
|||||||
{
|
{
|
||||||
public class SongSelectSettings : SettingsSubsection
|
public class SongSelectSettings : SettingsSubsection
|
||||||
{
|
{
|
||||||
private Bindable<double> minStars;
|
|
||||||
private Bindable<double> maxStars;
|
|
||||||
|
|
||||||
protected override LocalisableString Header => UserInterfaceStrings.SongSelectHeader;
|
protected override LocalisableString Header => UserInterfaceStrings.SongSelectHeader;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
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[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new SettingsCheckbox
|
new SettingsCheckbox
|
||||||
@ -44,20 +32,6 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
|
|||||||
LabelText = UserInterfaceStrings.ShowConvertedBeatmaps,
|
LabelText = UserInterfaceStrings.ShowConvertedBeatmaps,
|
||||||
Current = config.GetBindable<bool>(OsuSetting.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>
|
new SettingsEnumDropdown<RandomSelectAlgorithm>
|
||||||
{
|
{
|
||||||
LabelText = UserInterfaceStrings.RandomSelectionAlgorithm,
|
LabelText = UserInterfaceStrings.RandomSelectionAlgorithm,
|
||||||
@ -71,15 +45,5 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
133
osu.Game/Screens/Select/DifficultyRangeFilterControl.cs
Normal file
133
osu.Game/Screens/Select/DifficultyRangeFilterControl.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -155,15 +155,23 @@ namespace osu.Game.Screens.Select
|
|||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = 20,
|
Height = 40,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
new DifficultyRangeFilterControl
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopLeft,
|
||||||
|
Origin = Anchor.TopLeft,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Width = 0.48f,
|
||||||
|
},
|
||||||
collectionDropdown = new CollectionFilterDropdown
|
collectionDropdown = new CollectionFilterDropdown
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Width = 0.4f,
|
Y = 4,
|
||||||
|
Width = 0.5f,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user