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

Stop using SliderBar as a base

This commit is contained in:
Andrei Zavatski 2024-01-28 18:06:09 +03:00
parent ed9e0fe1db
commit b48f99ba4b
2 changed files with 46 additions and 23 deletions

View File

@ -98,7 +98,7 @@ namespace osu.Game.Screens.Play.HUD
base.Update();
handleBase.Height = Height - handleContainer.Height;
float newX = (float)Interpolation.Lerp(handleBase.X, NormalizedValue * UsableWidth, Math.Clamp(Time.Elapsed / 40, 0, 1));
float newX = (float)Interpolation.Lerp(handleBase.X, NormalizedValue * DrawWidth, Math.Clamp(Time.Elapsed / 40, 0, 1));
fill.Width = newX;
handleBase.X = newX;

View File

@ -3,12 +3,14 @@
using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
public abstract partial class SongProgressBar : SliderBar<double>
public abstract partial class SongProgressBar : Container
{
/// <summary>
/// Action which is invoked when a seek is requested, with the proposed millisecond value for the seek operation.
@ -26,45 +28,66 @@ namespace osu.Game.Screens.Play.HUD
protected readonly BindableBool InteractiveBindable = new BindableBool();
public double StartTime
public double StartTime { get; set; }
public double EndTime { get; set; } = 1.0;
public double CurrentTime { get; set; }
private double length => EndTime - StartTime;
protected double NormalizedValue => length == 0 ? 1 : Math.Clamp(CurrentTime - StartTime, 0.0, length) / length;
private bool handleClick;
protected override bool OnMouseDown(MouseDownEvent e)
{
get => CurrentNumber.MinValue;
set => CurrentNumber.MinValue = value;
handleClick = true;
return base.OnMouseDown(e);
}
public double EndTime
protected override bool OnClick(ClickEvent e)
{
get => CurrentNumber.MaxValue;
set => CurrentNumber.MaxValue = value;
if (handleClick)
handleMouseInput(e);
return true;
}
public double CurrentTime
protected override void OnDrag(DragEvent e)
{
get => CurrentNumber.Value;
set => CurrentNumber.Value = value;
handleMouseInput(e);
}
protected SongProgressBar()
protected override bool OnDragStart(DragStartEvent e)
{
StartTime = 0;
EndTime = 1;
Vector2 posDiff = e.MouseDownPosition - e.MousePosition;
if (Math.Abs(posDiff.X) < Math.Abs(posDiff.Y))
{
handleClick = false;
return false;
}
handleMouseInput(e);
return true;
}
protected override void UpdateValue(float value)
private void handleMouseInput(UIEvent e)
{
// handled in update
if (!Interactive)
return;
double relativeX = Math.Clamp(ToLocalSpace(e.ScreenSpaceMousePosition).X / DrawWidth, 0, 1);
onUserChange(StartTime + (EndTime - StartTime) * relativeX);
}
private ScheduledDelegate? scheduledSeek;
protected override void OnUserChange(double value)
private void onUserChange(double value)
{
scheduledSeek?.Cancel();
scheduledSeek = Schedule(() =>
{
if (Interactive)
OnSeek?.Invoke(value);
});
scheduledSeek = Schedule(() => OnSeek?.Invoke(value));
}
}
}