mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +08:00
Move common logic into own SongProgressBar class
This commit is contained in:
parent
d2af05b30e
commit
9b5b313193
@ -7,19 +7,15 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public partial class ArgonSongProgressBar : SliderBar<double>
|
||||
public partial class ArgonSongProgressBar : SongProgressBar
|
||||
{
|
||||
public Action<double>? OnSeek { get; set; }
|
||||
|
||||
// Parent will handle restricting the area of valid input.
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
@ -33,35 +29,12 @@ namespace osu.Game.Screens.Play.HUD
|
||||
private readonly ColourInfo mainColour;
|
||||
private ColourInfo catchUpColour;
|
||||
|
||||
public double StartTime
|
||||
{
|
||||
private get => CurrentNumber.MinValue;
|
||||
set => CurrentNumber.MinValue = value;
|
||||
}
|
||||
|
||||
public double EndTime
|
||||
{
|
||||
private get => CurrentNumber.MaxValue;
|
||||
set => CurrentNumber.MaxValue = value;
|
||||
}
|
||||
|
||||
public double CurrentTime
|
||||
{
|
||||
private get => CurrentNumber.Value;
|
||||
set => CurrentNumber.Value = value;
|
||||
}
|
||||
|
||||
public double TrackTime { private get; set; }
|
||||
|
||||
private double length => EndTime - StartTime;
|
||||
|
||||
public bool Interactive { get; set; }
|
||||
|
||||
public ArgonSongProgressBar(float barHeight)
|
||||
{
|
||||
StartTime = 0;
|
||||
EndTime = 1;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = this.barHeight = barHeight;
|
||||
|
||||
@ -136,11 +109,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
protected override void UpdateValue(float value)
|
||||
{
|
||||
// Handled in Update
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@ -167,18 +135,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
catchupBar.Alpha = Math.Max(1, catchupBar.Length);
|
||||
}
|
||||
|
||||
private ScheduledDelegate? scheduledSeek;
|
||||
|
||||
protected override void OnUserChange(double value)
|
||||
{
|
||||
scheduledSeek?.Cancel();
|
||||
scheduledSeek = Schedule(() =>
|
||||
{
|
||||
if (Interactive)
|
||||
OnSeek?.Invoke(value);
|
||||
});
|
||||
}
|
||||
|
||||
private partial class RoundedBar : Container
|
||||
{
|
||||
private readonly Box fill;
|
||||
|
@ -7,67 +7,23 @@ using osuTK.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Framework.Threading;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public partial class DefaultSongProgressBar : SliderBar<double>
|
||||
public partial class DefaultSongProgressBar : SongProgressBar
|
||||
{
|
||||
/// <summary>
|
||||
/// Action which is invoked when a seek is requested, with the proposed millisecond value for the seek operation.
|
||||
/// </summary>
|
||||
public Action<double>? OnSeek { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the progress bar should allow interaction, ie. to perform seek operations.
|
||||
/// </summary>
|
||||
public bool Interactive
|
||||
{
|
||||
get => showHandle;
|
||||
set
|
||||
{
|
||||
if (value == showHandle)
|
||||
return;
|
||||
|
||||
showHandle = value;
|
||||
|
||||
handleBase.FadeTo(showHandle ? 1 : 0, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public Color4 FillColour
|
||||
{
|
||||
set => fill.Colour = value;
|
||||
}
|
||||
|
||||
public double StartTime
|
||||
{
|
||||
set => CurrentNumber.MinValue = value;
|
||||
}
|
||||
|
||||
public double EndTime
|
||||
{
|
||||
set => CurrentNumber.MaxValue = value;
|
||||
}
|
||||
|
||||
public double CurrentTime
|
||||
{
|
||||
set => CurrentNumber.Value = value;
|
||||
}
|
||||
|
||||
private readonly Box fill;
|
||||
private readonly Container handleBase;
|
||||
private readonly Container handleContainer;
|
||||
|
||||
private bool showHandle;
|
||||
|
||||
public DefaultSongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize)
|
||||
{
|
||||
CurrentNumber.MinValue = 0;
|
||||
CurrentNumber.MaxValue = 1;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = barHeight + handleBarHeight + handleSize.Y;
|
||||
|
||||
@ -130,9 +86,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateValue(float value)
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
// handled in update
|
||||
base.LoadComplete();
|
||||
|
||||
InteractiveBindable.BindValueChanged(i => handleBase.FadeTo(i.NewValue ? 1 : 0, 200), true);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@ -145,17 +103,5 @@ namespace osu.Game.Screens.Play.HUD
|
||||
fill.Width = newX;
|
||||
handleBase.X = newX;
|
||||
}
|
||||
|
||||
private ScheduledDelegate? scheduledSeek;
|
||||
|
||||
protected override void OnUserChange(double value)
|
||||
{
|
||||
scheduledSeek?.Cancel();
|
||||
scheduledSeek = Schedule(() =>
|
||||
{
|
||||
if (showHandle)
|
||||
OnSeek?.Invoke(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
70
osu.Game/Screens/Play/HUD/SongProgressBar.cs
Normal file
70
osu.Game/Screens/Play/HUD/SongProgressBar.cs
Normal file
@ -0,0 +1,70 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Threading;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public abstract partial class SongProgressBar : SliderBar<double>
|
||||
{
|
||||
/// <summary>
|
||||
/// Action which is invoked when a seek is requested, with the proposed millisecond value for the seek operation.
|
||||
/// </summary>
|
||||
public Action<double>? OnSeek { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the progress bar should allow interaction, ie. to perform seek operations.
|
||||
/// </summary>
|
||||
public bool Interactive
|
||||
{
|
||||
get => InteractiveBindable.Value;
|
||||
set => InteractiveBindable.Value = value;
|
||||
}
|
||||
|
||||
protected readonly BindableBool InteractiveBindable = new BindableBool();
|
||||
|
||||
public double StartTime
|
||||
{
|
||||
get => CurrentNumber.MinValue;
|
||||
set => CurrentNumber.MinValue = value;
|
||||
}
|
||||
|
||||
public double EndTime
|
||||
{
|
||||
get => CurrentNumber.MaxValue;
|
||||
set => CurrentNumber.MaxValue = value;
|
||||
}
|
||||
|
||||
public double CurrentTime
|
||||
{
|
||||
get => CurrentNumber.Value;
|
||||
set => CurrentNumber.Value = value;
|
||||
}
|
||||
|
||||
protected SongProgressBar()
|
||||
{
|
||||
StartTime = 0;
|
||||
EndTime = 1;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(float value)
|
||||
{
|
||||
// handled in update
|
||||
}
|
||||
|
||||
private ScheduledDelegate? scheduledSeek;
|
||||
|
||||
protected override void OnUserChange(double value)
|
||||
{
|
||||
scheduledSeek?.Cancel();
|
||||
scheduledSeek = Schedule(() =>
|
||||
{
|
||||
if (Interactive)
|
||||
OnSeek?.Invoke(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user