From 9b5b313193d61c603c6e42773a8fc6ea7e05fb94 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 26 Jan 2024 04:49:23 +0300 Subject: [PATCH] Move common logic into own SongProgressBar class --- .../Screens/Play/HUD/ArgonSongProgressBar.cs | 46 +----------- .../Play/HUD/DefaultSongProgressBar.cs | 64 ++--------------- osu.Game/Screens/Play/HUD/SongProgressBar.cs | 70 +++++++++++++++++++ 3 files changed, 76 insertions(+), 104 deletions(-) create mode 100644 osu.Game/Screens/Play/HUD/SongProgressBar.cs diff --git a/osu.Game/Screens/Play/HUD/ArgonSongProgressBar.cs b/osu.Game/Screens/Play/HUD/ArgonSongProgressBar.cs index 40311da646..5fe3b97f15 100644 --- a/osu.Game/Screens/Play/HUD/ArgonSongProgressBar.cs +++ b/osu.Game/Screens/Play/HUD/ArgonSongProgressBar.cs @@ -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 + public partial class ArgonSongProgressBar : SongProgressBar { - public Action? 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; diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgressBar.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgressBar.cs index 0e16067dcc..4079351baf 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgressBar.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgressBar.cs @@ -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 + public partial class DefaultSongProgressBar : SongProgressBar { - /// - /// Action which is invoked when a seek is requested, with the proposed millisecond value for the seek operation. - /// - public Action? OnSeek { get; set; } - - /// - /// Whether the progress bar should allow interaction, ie. to perform seek operations. - /// - 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); - }); - } } } diff --git a/osu.Game/Screens/Play/HUD/SongProgressBar.cs b/osu.Game/Screens/Play/HUD/SongProgressBar.cs new file mode 100644 index 0000000000..db9c8901b4 --- /dev/null +++ b/osu.Game/Screens/Play/HUD/SongProgressBar.cs @@ -0,0 +1,70 @@ +// Copyright (c) ppy Pty Ltd . 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 + { + /// + /// Action which is invoked when a seek is requested, with the proposed millisecond value for the seek operation. + /// + public Action? OnSeek { get; set; } + + /// + /// Whether the progress bar should allow interaction, ie. to perform seek operations. + /// + 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); + }); + } + } +}