2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-01-09 04:43:44 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2019-09-17 07:12:18 +00:00
|
|
|
|
using osu.Framework.Threading;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public class SongProgressBar : SliderBar<double>
|
|
|
|
|
{
|
|
|
|
|
public Action<double> OnSeek;
|
|
|
|
|
|
|
|
|
|
private readonly Box fill;
|
|
|
|
|
private readonly Container handleBase;
|
2019-07-04 09:59:38 +00:00
|
|
|
|
private readonly Container handleContainer;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-24 05:21:22 +00:00
|
|
|
|
private bool showHandle;
|
|
|
|
|
|
|
|
|
|
public bool ShowHandle
|
|
|
|
|
{
|
|
|
|
|
get => showHandle;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == showHandle)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
showHandle = value;
|
|
|
|
|
|
|
|
|
|
handleBase.FadeTo(showHandle ? 1 : 0, 200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Color4 FillColour
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
set => fill.Colour = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double StartTime
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
set => CurrentNumber.MinValue = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double EndTime
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
set => CurrentNumber.MaxValue = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double CurrentTime
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
set => CurrentNumber.Value = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 03:18:47 +00:00
|
|
|
|
protected override bool AllowKeyboardInputWhenNotHovered => true;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize)
|
|
|
|
|
{
|
|
|
|
|
CurrentNumber.MinValue = 0;
|
|
|
|
|
CurrentNumber.MaxValue = 1;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = barHeight + handleBarHeight + handleSize.Y;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "Background",
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = barHeight,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
Depth = 1,
|
|
|
|
|
},
|
|
|
|
|
fill = new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "Fill",
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Height = barHeight,
|
|
|
|
|
},
|
|
|
|
|
handleBase = new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "HandleBar container",
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Width = 2,
|
2020-01-24 05:21:22 +00:00
|
|
|
|
Alpha = 0,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Position = new Vector2(2, 0),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "HandleBar box",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2019-07-04 09:59:38 +00:00
|
|
|
|
handleContainer = new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Name = "Handle container",
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Size = handleSize,
|
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "Handle box",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.White
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateValue(float value)
|
|
|
|
|
{
|
2019-05-09 09:05:28 +00:00
|
|
|
|
// handled in update
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-07-04 09:59:38 +00:00
|
|
|
|
handleBase.Height = Height - handleContainer.Height;
|
2019-11-20 12:19:49 +00:00
|
|
|
|
float newX = (float)Interpolation.Lerp(handleBase.X, NormalizedValue * UsableWidth, Math.Clamp(Time.Elapsed / 40, 0, 1));
|
2019-05-09 09:05:28 +00:00
|
|
|
|
|
|
|
|
|
fill.Width = newX;
|
|
|
|
|
handleBase.X = newX;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 07:12:18 +00:00
|
|
|
|
private ScheduledDelegate scheduledSeek;
|
|
|
|
|
|
|
|
|
|
protected override void OnUserChange(double value)
|
|
|
|
|
{
|
|
|
|
|
scheduledSeek?.Cancel();
|
2020-01-24 05:21:22 +00:00
|
|
|
|
scheduledSeek = Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (showHandle)
|
|
|
|
|
OnSeek?.Invoke(value);
|
|
|
|
|
});
|
2019-09-17 07:12:18 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|