1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Added PauseOverlay.TogglePaused, renamed OnPlay and similar to OnResume, made Pause and Play public, added proper testing for the visual test(pause button instead of auto-pause, logging actions), made PauseOverlay's fade duration a constant instead of statically typed

This commit is contained in:
DrabWeb 2017-01-27 07:11:22 -04:00
parent 81de5a2097
commit 3ed88ea043
3 changed files with 36 additions and 14 deletions

View File

@ -1,11 +1,14 @@
using System;
using OpenTK.Graphics;
using osu.Framework.Logging;
using osu.Framework.Graphics;
using osu.Game.Overlays.Pause;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Colour;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics.UserInterface;
namespace osu.Desktop.VisualTests.Tests
{
class TestCasePauseOverlay : TestCase
@ -27,7 +30,20 @@ namespace osu.Desktop.VisualTests.Tests
});
Add(pauseOverlay = new PauseOverlay());
pauseOverlay.ToggleVisibility();
}
Add(new Button
{ Text = @"Pause",
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Width = 100,
Height = 50,
Colour = Color4.Black,
Action = (() => pauseOverlay.Pause())
});
pauseOverlay.OnPause += (() => Logger.Log(@"Pause"));
pauseOverlay.OnResume += (() => Logger.Log(@"Resume"));
pauseOverlay.OnRetry += (() => Logger.Log(@"Retry"));
pauseOverlay.OnQuit += (() => Logger.Log(@"Quit"));
}
}
}

View File

@ -16,9 +16,10 @@ namespace osu.Game.Overlays.Pause
public class PauseOverlay : OverlayContainer
{
private bool paused = false;
private int fadeDuration = 100;
public event Action OnPause;
public event Action OnPlay;
public event Action OnResume;
public event Action OnRetry;
public event Action OnQuit;
@ -39,7 +40,7 @@ namespace osu.Game.Overlays.Pause
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Position = new Vector2(0, -200),
Action = Play
Action = Resume
},
new PauseButton
{
@ -61,13 +62,13 @@ namespace osu.Game.Overlays.Pause
protected override void PopIn()
{
this.FadeTo(1, 100, EasingTypes.In);
this.FadeTo(1, fadeDuration, EasingTypes.In);
paused = true;
}
protected override void PopOut()
{
this.FadeTo(0, 100, EasingTypes.In);
this.FadeTo(0, fadeDuration, EasingTypes.In);
paused = false;
}
@ -76,23 +77,28 @@ namespace osu.Game.Overlays.Pause
switch (args.Key)
{
case Key.Escape:
paused = !paused;
(paused ? (Action)Pause : Play)?.Invoke();
TogglePaused();
return true;
}
return base.OnKeyDown(state, args);
}
private void Pause()
public void Pause()
{
Show();
OnPause?.Invoke();
}
private void Play()
public void Resume()
{
Hide();
OnPlay?.Invoke();
Hide();
OnResume?.Invoke();
}
public void TogglePaused()
{
ToggleVisibility();
(paused ? (Action)Pause : Resume)?.Invoke();
}
private void Retry()

View File

@ -101,7 +101,7 @@ namespace osu.Game.Screens.Play
pauseOverlay = new PauseOverlay();
pauseOverlay.OnPause += onPause;
pauseOverlay.OnPlay += onPlay;
pauseOverlay.OnResume += onResume;
pauseOverlay.OnRetry += onRetry;
pauseOverlay.OnQuit += onQuit;
@ -180,7 +180,7 @@ namespace osu.Game.Screens.Play
sourceClock.Stop();
}
private void onPlay()
private void onResume()
{
scoreOverlay.KeyCounter.IsCounting = true;
sourceClock.Start();