2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-02-04 16:50:58 +08:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-02-25 20:12:39 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2017-02-04 16:50:58 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class OsuSliderBar<U> : SliderBar<U> where U : struct
|
|
|
|
|
{
|
2017-02-18 16:35:04 +08:00
|
|
|
|
private SampleChannel sample;
|
2017-02-04 16:50:58 +08:00
|
|
|
|
private double lastSampleTime;
|
|
|
|
|
|
2017-02-04 19:06:53 +08:00
|
|
|
|
private Nub nub;
|
2017-02-04 16:50:58 +08:00
|
|
|
|
private Box leftBox, rightBox;
|
|
|
|
|
|
|
|
|
|
public OsuSliderBar()
|
|
|
|
|
{
|
|
|
|
|
Height = 12;
|
|
|
|
|
RangePadding = 20;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
leftBox = new Box
|
|
|
|
|
{
|
|
|
|
|
Height = 2,
|
2017-02-04 19:56:14 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(0, 0.5f),
|
2017-02-04 16:50:58 +08:00
|
|
|
|
Position = new Vector2(2, 0),
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
|
|
|
|
rightBox = new Box
|
|
|
|
|
{
|
|
|
|
|
Height = 2,
|
2017-02-04 19:56:14 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(0, 0.5f),
|
2017-02-04 16:50:58 +08:00
|
|
|
|
Position = new Vector2(-2, 0),
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
},
|
2017-02-04 19:06:53 +08:00
|
|
|
|
nub = new Nub
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
State = CheckBoxState.Unchecked,
|
|
|
|
|
Expanded = true,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
sample = audio.Sample.Get(@"Sliderbar/sliderbar");
|
|
|
|
|
leftBox.Colour = colours.Pink;
|
|
|
|
|
rightBox.Colour = colours.Pink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void playSample()
|
|
|
|
|
{
|
|
|
|
|
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
|
|
|
|
|
return;
|
|
|
|
|
lastSampleTime = Clock.CurrentTime;
|
|
|
|
|
sample.Frequency.Value = 1 + NormalizedValue * 0.2f;
|
|
|
|
|
sample.Play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
nub.Glowing = true;
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
nub.Glowing = false;
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Key == Key.Left || args.Key == Key.Right)
|
|
|
|
|
playSample();
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
nub.State = CheckBoxState.Checked;
|
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
nub.State = CheckBoxState.Unchecked;
|
|
|
|
|
return base.OnMouseUp(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
playSample();
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
|
|
|
|
playSample();
|
|
|
|
|
return base.OnDrag(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 19:55:26 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2017-02-04 19:55:26 +08:00
|
|
|
|
base.UpdateAfterChildren();
|
2017-02-04 16:50:58 +08:00
|
|
|
|
leftBox.Scale = new Vector2(MathHelper.Clamp(
|
|
|
|
|
nub.DrawPosition.X - nub.DrawWidth / 2, 0, DrawWidth), 1);
|
|
|
|
|
rightBox.Scale = new Vector2(MathHelper.Clamp(
|
|
|
|
|
DrawWidth - nub.DrawPosition.X - nub.DrawWidth / 2, 0, DrawWidth), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateValue(float value)
|
|
|
|
|
{
|
|
|
|
|
nub.MoveToX(RangePadding + UsableWidth * value, 250, EasingTypes.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|