1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 22:19:30 +08:00

Fix up slider bugs

This commit is contained in:
Drew DeVault 2016-12-08 17:12:12 -05:00
parent 22c2a4757c
commit 9e75ecab4f

View File

@ -1,5 +1,6 @@
using System; using System;
using OpenTK; using OpenTK;
using OpenTK.Input;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -11,6 +12,7 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations; using osu.Framework.Graphics.Transformations;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
@ -55,37 +57,50 @@ namespace osu.Game.Overlays.Options
private class OsuSliderBar<U> : SliderBar<U> where U : struct, private class OsuSliderBar<U> : SliderBar<U> where U : struct,
IComparable, IFormattable, IConvertible, IComparable<U>, IEquatable<U> IComparable, IFormattable, IConvertible, IComparable<U>, IEquatable<U>
{ {
private Container nub;
private AudioSample sample; private AudioSample sample;
private float prevAmount = -1; private double lastSample;
private Container nub;
private Box leftBox, rightBox;
public OsuSliderBar() public OsuSliderBar()
{ {
Height = 22; Height = 22;
Color = Color4.White; Children = new Drawable[]
SelectionColor = new Color4(255, 102, 170, 255);
Add(nub = new Container
{ {
Width = Height, leftBox = new Box
Height = Height,
CornerRadius = Height / 2,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.None,
RelativeSizeAxes = Axes.None,
RelativePositionAxes = Axes.X,
Masking = true,
BorderColour = new Color4(255, 102, 170, 255),
BorderThickness = 2,
Children = new[]
{ {
new Box { Colour = Color4.Transparent, RelativeSizeAxes = Axes.Both } Height = 2,
} RelativeSizeAxes = Axes.None,
}); Anchor = Anchor.CentreLeft,
Box.Height = SelectionBox.Height = 2; Origin = Anchor.CentreLeft,
Box.RelativePositionAxes = Axes.None; Colour = new Color4(255, 102, 170, 255),
Box.RelativeSizeAxes = SelectionBox.RelativeSizeAxes = Axes.None; },
Box.Position = SelectionBox.Position = new Vector2(0, Height / 2 - 1); rightBox = new Box
Box.Colour = new Color4(255, 102, 170, 100); {
Height = 2,
RelativeSizeAxes = Axes.None,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Colour = new Color4(255, 102, 170, 255),
Alpha = 0.5f,
},
nub = new Container
{
Width = Height,
Height = Height,
CornerRadius = Height / 2,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.None,
RelativeSizeAxes = Axes.None,
Masking = true,
BorderColour = new Color4(255, 102, 170, 255),
BorderThickness = 3,
Children = new[]
{
new Box { Colour = Color4.Transparent, RelativeSizeAxes = Axes.Both }
}
},
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -94,20 +109,46 @@ namespace osu.Game.Overlays.Options
sample = audio.Sample.Get(@"Sliderbar/sliderbar"); sample = audio.Sample.Get(@"Sliderbar/sliderbar");
} }
protected override void UpdateAmount(float amt) private void playSample()
{ {
if (prevAmount != -1 && (int)(prevAmount * 10) != (int)(amt * 10)) if (Clock == null)
sample?.Play(); return;
prevAmount = amt; if (Clock.CurrentTime - lastSample > 50)
nub.MoveToX(amt, 300, EasingTypes.OutQuint); {
SelectionBox.ScaleTo( lastSample = Clock.CurrentTime;
new Vector2(DrawWidth * amt - Height / 2 + 1, 1), sample.Frequency.Value = 1 + NormalizedValue * 0.2f;
300, EasingTypes.OutQuint); sample.Play();
Box.MoveToX(DrawWidth * amt + Height / 2 - 1, }
300, EasingTypes.OutQuint); }
Box.ScaleTo(
new Vector2(DrawWidth * (1 - amt) - Height / 2 + 1, 1), protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
300, EasingTypes.OutQuint); {
if (args.Key == Key.Left || args.Key == Key.Right)
playSample();
return base.OnKeyDown(state, args);
}
protected override bool OnClick(InputState state)
{
playSample();
return base.OnClick(state);
}
protected override bool OnDrag(InputState state)
{
playSample();
return base.OnDrag(state);
}
protected override void UpdateValue(float value)
{
nub.MoveToX(DrawWidth * value, 300, EasingTypes.OutQuint);
leftBox.ScaleTo(new Vector2(
MathHelper.Clamp(DrawWidth * value - nub.Width / 2 + 2, 0, DrawWidth),
1), 300, EasingTypes.OutQuint);
rightBox.ScaleTo(new Vector2(
MathHelper.Clamp(DrawWidth * (1 - value) - nub.Width / 2 + 2, 0, DrawWidth),
1), 300, EasingTypes.OutQuint);
} }
} }
} }