From d70cbd37dd779f907dbefd89d2062c7b1669a938 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Mon, 30 Jan 2017 04:08:14 -0400 Subject: [PATCH] Made the pause progress graph it's own class, to be implemented, made it so the user couldn't double click the pause buttons and made it so the action wasn't called a second time when the mouse button was released, made PopIn and PopOut in PauseOverlay one line each, made Player.IsPaused a public getter with a private getter/setter, implemented restarting in Player --- .../Tests/TestCasePauseOverlay.cs | 46 +++++++++++++---- osu.Game/Overlays/Pause/PauseButton.cs | 28 ++++++++-- osu.Game/Overlays/Pause/PauseOverlay.cs | 32 ++++++------ osu.Game/Overlays/Pause/PauseProgressBar.cs | 20 +++++--- osu.Game/Overlays/Pause/PauseProgressGraph.cs | 28 ++++++++++ osu.Game/Screens/Play/Player.cs | 51 +++++++++++++++---- osu.Game/osu.Game.csproj | 1 + 7 files changed, 157 insertions(+), 49 deletions(-) create mode 100644 osu.Game/Overlays/Pause/PauseProgressGraph.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs index 8b48779666..e311074124 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs @@ -18,6 +18,7 @@ namespace osu.Desktop.VisualTests.Tests public override string Description => @"Tests the pause overlay"; private PauseOverlay pauseOverlay; + private int retryCount; public override void Reset() { @@ -26,19 +27,46 @@ namespace osu.Desktop.VisualTests.Tests Add(new Box { ColourInfo = ColourInfo.GradientVertical(Color4.Gray, Color4.WhiteSmoke), - RelativeSizeAxes = Framework.Graphics.Axes.Both, + RelativeSizeAxes = Framework.Graphics.Axes.Both }); - Add(pauseOverlay = new PauseOverlay { Depth = -1 }); - Add(new Button + Add(pauseOverlay = new PauseOverlay { Depth = -1 }); + pauseOverlay.OnResume += (() => Logger.Log(@"Resume")); + pauseOverlay.OnRetry += (() => Logger.Log(@"Retry")); + pauseOverlay.OnQuit += (() => Logger.Log(@"Quit")); + + Add(new FlowContainer { - Text = @"Pause", - Anchor = Anchor.TopLeft, + RelativeSizeAxes = Axes.Both, Origin = Anchor.TopLeft, - Width = 100, - Height = 50, - Colour = Color4.Black, - Action = (() => pauseOverlay.Show()), + Anchor = Anchor.TopLeft, + Direction = FlowDirection.VerticalOnly, + Children = new Drawable[] + { + new Button + { + Text = @"Pause", + Anchor = Anchor.TopLeft, + Origin = Anchor.TopLeft, + Width = 100, + Height = 50, + Colour = Color4.Black, + Action = (() => pauseOverlay.Show()) + }, + new Button + { + Text = @"Add Retry", + Anchor = Anchor.TopLeft, + Origin = Anchor.TopLeft, + Width = 100, + Height = 50, + Colour = Color4.Black, + Action = (delegate { + retryCount++; + pauseOverlay.SetRetries(retryCount); + }), + } + } }); } } diff --git a/osu.Game/Overlays/Pause/PauseButton.cs b/osu.Game/Overlays/Pause/PauseButton.cs index 9914caf37d..d4a12101d2 100644 --- a/osu.Game/Overlays/Pause/PauseButton.cs +++ b/osu.Game/Overlays/Pause/PauseButton.cs @@ -1,7 +1,7 @@ -using OpenTK; +using System; +using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; -using osu.Game.Graphics; using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; using osu.Framework.Graphics.Colour; @@ -9,6 +9,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Containers; using osu.Framework.Audio; using osu.Framework.Audio.Sample; +using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; namespace osu.Game.Overlays.Pause @@ -55,16 +56,28 @@ namespace osu.Game.Overlays.Pause private Container colourContainer; private Container glowContainer; + private bool didClick; + public override bool Contains(Vector2 screenSpacePos) => backgroundContainer.Contains(screenSpacePos); protected override bool OnMouseDown(Framework.Input.InputState state, MouseDownEventArgs args) { - colourContainer.ResizeTo(new Vector2(1.1f, 1f), 200, EasingTypes.In); + didClick = true; + colourContainer.ResizeTo(new Vector2(1.5f, 1f), 200, EasingTypes.In); sampleClick?.Play(); Action?.Invoke(); + + Delay(200); + Schedule(delegate { + colourContainer.ResizeTo(new Vector2(colourWidth, 1f), 0, EasingTypes.None); + glowContainer.Alpha = 0; + }); + return true; } + protected override bool OnClick(Framework.Input.InputState state) => false; + protected override bool OnHover(Framework.Input.InputState state) { colourContainer.ResizeTo(new Vector2(colourExpandedWidth, 1f), colourExpandTime, EasingTypes.OutElastic); @@ -75,8 +88,13 @@ namespace osu.Game.Overlays.Pause protected override void OnHoverLost(Framework.Input.InputState state) { - colourContainer.ResizeTo(new Vector2(colourWidth, 1f), colourExpandTime, EasingTypes.OutElastic); - glowContainer.FadeTo(0f, colourExpandTime / 2, EasingTypes.Out); + if (!didClick) + { + colourContainer.ResizeTo(new Vector2(colourWidth, 1f), colourExpandTime, EasingTypes.OutElastic); + glowContainer.FadeTo(0f, colourExpandTime / 2, EasingTypes.Out); + } + + didClick = false; } [BackgroundDependencyLoader] diff --git a/osu.Game/Overlays/Pause/PauseOverlay.cs b/osu.Game/Overlays/Pause/PauseOverlay.cs index 3d345eb404..728dc9e8de 100644 --- a/osu.Game/Overlays/Pause/PauseOverlay.cs +++ b/osu.Game/Overlays/Pause/PauseOverlay.cs @@ -24,7 +24,23 @@ namespace osu.Game.Overlays.Pause private SpriteText retryCounter; public override bool Contains(Vector2 screenSpacePos) => true; + public override bool HandleInput => State == Visibility.Visible; + protected override void PopIn() => FadeIn(fadeDuration, EasingTypes.In); + protected override void PopOut() => FadeOut(fadeDuration, EasingTypes.In); + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + switch (args.Key) + { + case Key.Escape: + if (State == Visibility.Hidden) return false; + Hide(); + Task.Delay(fadeDuration * 2).ContinueWith(task => OnResume?.Invoke()); + return true; + } + return base.OnKeyDown(state, args); + } [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -149,22 +165,6 @@ namespace osu.Game.Overlays.Pause retryCounter.Text = $"You've retried {String.Format("{0:n0}", count)} time{(count == 1) ? "" : "s"} in this session"; } - protected override void PopIn() => FadeIn(fadeDuration, EasingTypes.In); - protected override void PopOut() => FadeOut(fadeDuration, EasingTypes.In); - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - switch (args.Key) - { - case Key.Escape: - if (State == Visibility.Hidden) return false; - Hide(); - Task.Delay(fadeDuration * 2).ContinueWith(task => OnResume?.Invoke()); - return true; - } - return base.OnKeyDown(state, args); - } - public PauseOverlay() { RelativeSizeAxes = Axes.Both; diff --git a/osu.Game/Overlays/Pause/PauseProgressBar.cs b/osu.Game/Overlays/Pause/PauseProgressBar.cs index 2c48bf8689..f3b404a4c0 100644 --- a/osu.Game/Overlays/Pause/PauseProgressBar.cs +++ b/osu.Game/Overlays/Pause/PauseProgressBar.cs @@ -1,15 +1,8 @@ -using System; -using OpenTK; -using OpenTK.Input; -using OpenTK.Graphics; -using osu.Game.Graphics; -using osu.Framework.Input; +using OpenTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Transformations; -using osu.Framework.Graphics.UserInterface; using osu.Game.Beatmaps; using osu.Framework.Graphics.Primitives; @@ -43,6 +36,17 @@ namespace osu.Game.Overlays.Pause Children = new Drawable[] { + new PauseProgressGraph + { + RelativeSizeAxes = Axes.X, + Origin = Anchor.BottomCentre, + Anchor = Anchor.BottomCentre, + Height = 35, + Margin = new MarginPadding + { + Bottom = 5 + } + }, new Container { Origin = Anchor.BottomRight, diff --git a/osu.Game/Overlays/Pause/PauseProgressGraph.cs b/osu.Game/Overlays/Pause/PauseProgressGraph.cs new file mode 100644 index 0000000000..08667c94c7 --- /dev/null +++ b/osu.Game/Overlays/Pause/PauseProgressGraph.cs @@ -0,0 +1,28 @@ +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Configuration; + +namespace osu.Game.Overlays.Pause +{ + public class PauseProgressGraph : FlowContainer + { + private WorkingBeatmap current; + + [BackgroundDependencyLoader] + private void load(OsuGameBase osuGame) + { + current = osuGame.Beatmap.Value; + } + + public PauseProgressGraph() + { + // TODO: Implement the pause progress graph + } + } +} diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 02a5f93a36..9b4c151e3c 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -41,10 +41,19 @@ namespace osu.Game.Screens.Play public PlayMode PreferredPlayMode; - public bool IsPaused; + private bool isPaused; + public bool IsPaused + { + get + { + return isPaused; + } + } + + public int RestartCount; private double pauseCooldown = 1000; - private double lastActionTime = 0; + private double lastPauseActionTime = 0; private IAdjustableClock sourceClock; @@ -140,41 +149,57 @@ namespace osu.Game.Screens.Play public void Pause(bool force = false) { - if (Time.Current >= (lastActionTime + pauseCooldown) || force) + if (Time.Current >= (lastPauseActionTime + pauseCooldown) || force) { - lastActionTime = Time.Current; + lastPauseActionTime = Time.Current; playerInputManager.PassThrough = true; scoreOverlay.KeyCounter.IsCounting = false; + pauseOverlay.SetRetries(RestartCount); pauseOverlay.Show(); sourceClock.Stop(); - IsPaused = true; + isPaused = true; } else { - IsPaused = false; + isPaused = false; } } public void Resume() { - lastActionTime = Time.Current; + lastPauseActionTime = Time.Current; playerInputManager.PassThrough = false; scoreOverlay.KeyCounter.IsCounting = true; pauseOverlay.Hide(); sourceClock.Start(); - IsPaused = false; + isPaused = false; } public void TogglePaused() { - IsPaused = !IsPaused; + isPaused = !IsPaused; if (IsPaused) Pause(); else Resume(); } public void Restart() { - // TODO: Implement retrying - if (IsPaused) Resume(); + sourceClock.Stop(); // If the clock is not stopped and Restart is called alot of lag will happen until the game is relaunched + + var newPlayer = new Player(); + + newPlayer.Preload(Game, delegate + { + RestartCount++; + newPlayer.RestartCount = RestartCount; + Exit(); + + if (!(last?.Push(newPlayer) ?? false)) + { + // Error(?) + } + + Dispose(); + }); } protected override void LoadComplete() @@ -218,6 +243,8 @@ namespace osu.Game.Screens.Play }); } + private GameMode last; + protected override void OnEntering(GameMode last) { base.OnEntering(last); @@ -227,6 +254,8 @@ namespace osu.Game.Screens.Play Content.Alpha = 0; dimLevel.ValueChanged += dimChanged; + + this.last = last; } protected override bool OnExiting(GameMode next) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index cf0fc50373..f143afc498 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -239,6 +239,7 @@ +