mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 07:42:58 +08:00
Tidy up implementation and add basic visual test
This commit is contained in:
parent
d54f7fc728
commit
32139ac13f
@ -0,0 +1,26 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Child = new DifficultyRangeFilterControl
|
||||||
|
{
|
||||||
|
Width = 200,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(3),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -15,13 +14,14 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select
|
namespace osu.Game.Screens.Select
|
||||||
{
|
{
|
||||||
internal class DifficultyRangeFilterControl : CompositeDrawable
|
internal class DifficultyRangeFilterControl : CompositeDrawable
|
||||||
{
|
{
|
||||||
private Bindable<double> minStars;
|
private Bindable<double> lowerStars;
|
||||||
private Bindable<double> maxStars;
|
private Bindable<double> upperStars;
|
||||||
|
|
||||||
private StarsSlider lowerSlider;
|
private StarsSlider lowerSlider;
|
||||||
private MaximumStarsSlider upperSlider;
|
private MaximumStarsSlider upperSlider;
|
||||||
@ -45,46 +45,75 @@ namespace osu.Game.Screens.Select
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Y = vertical_offset,
|
Y = vertical_offset,
|
||||||
},
|
},
|
||||||
lowerSlider = new StarsSlider
|
lowerSlider = new MinimumStarsSlider
|
||||||
{
|
{
|
||||||
Current = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum),
|
Current = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum),
|
||||||
KeyboardStep = 0.1f,
|
KeyboardStep = 0.1f,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Y = vertical_offset,
|
Y = vertical_offset,
|
||||||
},
|
},
|
||||||
lowerSlider.Nub.CreateProxy(),
|
|
||||||
upperSlider.Nub.CreateProxy(),
|
upperSlider.Nub.CreateProxy(),
|
||||||
|
lowerSlider.Nub.CreateProxy(),
|
||||||
};
|
};
|
||||||
|
|
||||||
lowerSlider.LeftBox.Height = 6;
|
lowerStars = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum);
|
||||||
|
upperStars = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum);
|
||||||
minStars = config.GetBindable<double>(OsuSetting.DisplayStarsMinimum);
|
|
||||||
maxStars = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum);
|
|
||||||
|
|
||||||
lowerSlider.AccentColour = lowerSlider.BackgroundColour;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
minStars.ValueChanged += min => maxStars.Value = Math.Max(min.NewValue, maxStars.Value);
|
lowerStars.ValueChanged += min => upperStars.Value = Math.Max(min.NewValue + 0.1, upperStars.Value);
|
||||||
maxStars.ValueChanged += max => minStars.Value = Math.Min(max.NewValue, minStars.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;
|
||||||
|
|
||||||
|
public override LocalisableString TooltipText => Current.IsDefault ? UserInterfaceStrings.NoLimit : base.TooltipText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MaximumStarsSlider : StarsSlider
|
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;
|
||||||
public override LocalisableString TooltipText => Current.IsDefault ? UserInterfaceStrings.NoLimit : base.TooltipText;
|
public override LocalisableString TooltipText => Current.IsDefault ? UserInterfaceStrings.NoLimit : base.TooltipText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StarsSlider : OsuSliderBar<double>
|
private class StarsSlider : OsuSliderBar<double>
|
||||||
{
|
{
|
||||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Nub.ReceivePositionalInputAt(screenSpacePos);
|
|
||||||
|
|
||||||
public override LocalisableString TooltipText => Current.Value.ToString(@"0.## stars");
|
public override LocalisableString TooltipText => Current.Value.ToString(@"0.## stars");
|
||||||
|
|
||||||
public new Nub Nub => base.Nub;
|
public new Nub Nub => base.Nub;
|
||||||
public new Box LeftBox => base.LeftBox;
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Nub.Width = Nub.HEIGHT;
|
||||||
|
RangePadding = Nub.Width / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user