diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs b/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs index 2427b6d12c..ba17cfc3d8 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs @@ -16,7 +16,7 @@ namespace osu.Desktop.VisualTests.Tests base.Reset(); Add(new BackButton()); - Add(new SkipButton()); + Add(new SkipButton(Clock.CurrentTime + 5000)); } } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index d9585b8c04..06c9b29d48 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -63,8 +63,6 @@ namespace osu.Game.Screens.Play #endregion - private SkipButton skipButton; - private HUDOverlay hudOverlay; private FailOverlay failOverlay; @@ -169,8 +167,9 @@ namespace osu.Game.Screens.Play Children = new Drawable[] { HitRenderer, - skipButton = new SkipButton + new SkipButton(firstObjectTime) { + AudioClock = decoupledClock, Alpha = 0, Margin = new MarginPadding { Bottom = 140 } // this is temporary }, @@ -219,33 +218,6 @@ namespace osu.Game.Screens.Play scoreProcessor.Failed += onFail; } - private void initializeSkipButton() - { - const double skip_required_cutoff = 3000; - const double fade_time = 300; - - double firstHitObject = Beatmap.Beatmap.HitObjects.First().StartTime; - - if (firstHitObject < skip_required_cutoff) - { - skipButton.Alpha = 0; - skipButton.Expire(); - return; - } - - skipButton.FadeInFromZero(fade_time); - - skipButton.Action = () => - { - decoupledClock.Seek(firstHitObject - skip_required_cutoff - fade_time); - skipButton.Action = null; - }; - - skipButton.Delay(firstHitObject - skip_required_cutoff - fade_time); - skipButton.FadeOut(fade_time); - skipButton.Expire(); - } - public void Restart() { ValidForResume = false; @@ -308,7 +280,6 @@ namespace osu.Game.Screens.Play Schedule(() => { decoupledClock.Start(); - initializeSkipButton(); }); pauseContainer.Alpha = 0; diff --git a/osu.Game/Screens/Play/SkipButton.cs b/osu.Game/Screens/Play/SkipButton.cs index f57bbd4cb0..47f382dc0e 100644 --- a/osu.Game/Screens/Play/SkipButton.cs +++ b/osu.Game/Screens/Play/SkipButton.cs @@ -5,6 +5,7 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Graphics; using osu.Framework.Input; +using osu.Framework.Timing; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; using OpenTK.Input; @@ -13,8 +14,12 @@ namespace osu.Game.Screens.Play { public class SkipButton : TwoLayerButton { - public SkipButton() + private readonly double startTime; + public IAdjustableClock AudioClock; + + public SkipButton(double startTime) { + this.startTime = startTime; Text = @"Skip"; Icon = FontAwesome.fa_osu_right_o; Anchor = Anchor.BottomRight; @@ -27,6 +32,24 @@ namespace osu.Game.Screens.Play ActivationSound = audio.Sample.Get(@"Menu/menuhit"); BackgroundColour = colours.Yellow; HoverColour = colours.YellowDark; + + const double skip_required_cutoff = 3000; + const double fade_time = 300; + + if (startTime < skip_required_cutoff) + { + Alpha = 0; + Expire(); + return; + } + + FadeInFromZero(fade_time); + + Action = () => AudioClock.Seek(startTime - skip_required_cutoff - fade_time); + + Delay(startTime - skip_required_cutoff - fade_time); + FadeOut(fade_time); + Expire(); } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)