2016-12-15 03:59:23 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-12-08 04:39:21 +08:00
|
|
|
|
using OpenTK;
|
2016-12-09 06:12:12 +08:00
|
|
|
|
using OpenTK.Input;
|
2016-11-30 22:08:11 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2016-12-08 04:56:00 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2016-11-30 22:08:11 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-12-08 04:39:21 +08:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-11-30 22:08:11 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2016-12-09 06:12:12 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-01-10 06:18:47 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-01-13 12:49:05 +08:00
|
|
|
|
using System.Linq;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2016-11-30 22:08:11 +08:00
|
|
|
|
|
2016-12-08 04:39:21 +08:00
|
|
|
|
namespace osu.Game.Overlays.Options
|
|
|
|
|
{
|
2017-01-31 17:37:11 +08:00
|
|
|
|
public class OptionSlider<T> : FlowContainer where T : struct
|
2016-12-08 04:39:21 +08:00
|
|
|
|
{
|
|
|
|
|
private SliderBar<T> slider;
|
|
|
|
|
private SpriteText text;
|
|
|
|
|
|
|
|
|
|
public string LabelText
|
|
|
|
|
{
|
|
|
|
|
get { return text.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
text.Text = value;
|
|
|
|
|
text.Alpha = string.IsNullOrEmpty(value) ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BindableNumber<T> Bindable
|
|
|
|
|
{
|
|
|
|
|
get { return slider.Bindable; }
|
|
|
|
|
set { slider.Bindable = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 17:37:11 +08:00
|
|
|
|
public OptionSlider()
|
2016-12-08 04:39:21 +08:00
|
|
|
|
{
|
|
|
|
|
Direction = FlowDirection.VerticalOnly;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-01-31 17:53:52 +08:00
|
|
|
|
text = new OsuSpriteText {
|
2017-01-31 17:37:11 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
2016-12-08 04:39:21 +08:00
|
|
|
|
slider = new OsuSliderBar<T>
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Top = 5 },
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-16 11:50:23 +08:00
|
|
|
|
private class OsuSliderBar<U> : SliderBar<U> where U : struct
|
2016-12-08 04:39:21 +08:00
|
|
|
|
{
|
2016-12-08 04:56:00 +08:00
|
|
|
|
private AudioSample sample;
|
2016-12-16 14:27:57 +08:00
|
|
|
|
private double lastSampleTime;
|
2016-12-09 06:12:12 +08:00
|
|
|
|
|
|
|
|
|
private Container nub;
|
|
|
|
|
private Box leftBox, rightBox;
|
2016-12-16 14:27:57 +08:00
|
|
|
|
|
|
|
|
|
private float innerWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return DrawWidth - Height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 04:39:21 +08:00
|
|
|
|
public OsuSliderBar()
|
|
|
|
|
{
|
2017-01-31 17:37:11 +08:00
|
|
|
|
Height = 20;
|
2016-12-16 14:27:57 +08:00
|
|
|
|
Padding = new MarginPadding { Left = Height / 2, Right = Height / 2 };
|
2016-12-09 06:12:12 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-12-08 04:39:21 +08:00
|
|
|
|
{
|
2016-12-09 06:12:12 +08:00
|
|
|
|
leftBox = new Box
|
|
|
|
|
{
|
|
|
|
|
Height = 2,
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
|
|
|
|
rightBox = new Box
|
2016-12-08 04:39:21 +08:00
|
|
|
|
{
|
2016-12-09 06:12:12 +08:00
|
|
|
|
Height = 2,
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
},
|
|
|
|
|
nub = new Container
|
|
|
|
|
{
|
|
|
|
|
Width = Height,
|
|
|
|
|
Height = Height,
|
|
|
|
|
CornerRadius = Height / 2,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.None,
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderThickness = 3,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2016-12-16 13:37:37 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
}
|
2016-12-09 06:12:12 +08:00
|
|
|
|
}
|
2016-12-16 14:27:57 +08:00
|
|
|
|
}
|
2016-12-09 06:12:12 +08:00
|
|
|
|
};
|
2016-12-08 04:39:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 04:56:00 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-01-13 12:49:05 +08:00
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
2016-12-08 04:56:00 +08:00
|
|
|
|
{
|
|
|
|
|
sample = audio.Sample.Get(@"Sliderbar/sliderbar");
|
2017-01-13 12:49:05 +08:00
|
|
|
|
leftBox.Colour = colours.Pink;
|
|
|
|
|
rightBox.Colour = colours.Pink;
|
|
|
|
|
nub.BorderColour = colours.Pink;
|
|
|
|
|
(nub.Children.First() as Box).Colour = colours.Pink.Opacity(0);
|
2016-12-08 04:56:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 06:12:12 +08:00
|
|
|
|
private void playSample()
|
|
|
|
|
{
|
2016-12-16 14:27:57 +08:00
|
|
|
|
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
|
2016-12-09 06:12:12 +08:00
|
|
|
|
return;
|
2016-12-16 14:27:57 +08:00
|
|
|
|
lastSampleTime = Clock.CurrentTime;
|
|
|
|
|
sample.Frequency.Value = 1 + NormalizedValue * 0.2f;
|
|
|
|
|
sample.Play();
|
2016-12-09 06:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
playSample();
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
|
|
|
|
playSample();
|
|
|
|
|
return base.OnDrag(state);
|
|
|
|
|
}
|
2016-12-15 03:57:41 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
2016-12-15 13:11:37 +08:00
|
|
|
|
base.Update();
|
2016-12-15 03:57:41 +08:00
|
|
|
|
leftBox.Scale = new Vector2(MathHelper.Clamp(
|
2016-12-16 14:27:57 +08:00
|
|
|
|
nub.DrawPosition.X - nub.DrawWidth / 2 + 2, 0, innerWidth), 1);
|
2016-12-15 03:57:41 +08:00
|
|
|
|
rightBox.Scale = new Vector2(MathHelper.Clamp(
|
2016-12-16 14:27:57 +08:00
|
|
|
|
innerWidth - nub.DrawPosition.X - nub.DrawWidth / 2 + 2, 0, innerWidth), 1);
|
2016-12-15 03:57:41 +08:00
|
|
|
|
}
|
2016-12-09 06:12:12 +08:00
|
|
|
|
|
2016-12-15 13:11:37 +08:00
|
|
|
|
protected override void UpdateValue(float value)
|
2016-12-08 04:39:21 +08:00
|
|
|
|
{
|
2016-12-16 14:27:57 +08:00
|
|
|
|
nub.MoveToX(innerWidth * value);
|
2016-12-08 04:39:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-09 21:18:58 +08:00
|
|
|
|
}
|