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

Changed the roles of PauseOverlay and player in pausing, PauseOverlay is now only the UI portion and doesn't do things like actually pause the game, and only calls actions and hides itself, whereas Player actually pauses the game and brings up the pause overlay in the first place

This commit is contained in:
DrabWeb 2017-01-27 15:28:39 -04:00
parent 601a5ed39c
commit feba3f35ba
3 changed files with 89 additions and 68 deletions

View File

@ -38,13 +38,8 @@ namespace osu.Desktop.VisualTests.Tests
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"));
Action = (() => pauseOverlay.Show()),
});
}
}
}

View File

@ -3,30 +3,24 @@ using OpenTK;
using OpenTK.Input;
using OpenTK.Graphics;
using osu.Game.Graphics;
using osu.Framework.Audio;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
using osu.Framework.Input;
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.Game.Graphics.Backgrounds;
using osu.Game.Screens.Menu;
namespace osu.Game.Overlays.Pause
{
public class PauseOverlay : OverlayContainer
{
public event Action OnPause;
public event Action OnResume;
public event Action OnRetry;
public event Action OnQuit;
public bool isPaused = false;
private int fadeDuration = 100;
private double pauseCooldown = 1000;
private double lastActionTime = 0;
public Action OnResume;
public Action OnRetry;
public Action OnQuit;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
@ -96,23 +90,34 @@ namespace osu.Game.Overlays.Pause
Type = PauseButtonType.Resume,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Action = Resume,
Action = (delegate
{
Hide();
OnResume?.Invoke();
}),
},
new PauseButton
{
Type = PauseButtonType.Retry,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Action = Retry,
Action = (delegate
{
Hide();
OnRetry?.Invoke();
}),
},
new PauseButton
{
Type = PauseButtonType.Quit,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Action = Quit,
},
new Button(@"solo", @"freeplay", FontAwesome.fa_user, new Color4(102, 68, 204, 255), () => OnPause?.Invoke(), 300, Key.P),
Action = (delegate
{
Hide();
OnQuit?.Invoke();
}),
},
}
},
};
@ -121,65 +126,25 @@ namespace osu.Game.Overlays.Pause
protected override void PopIn()
{
FadeTo(1, fadeDuration, EasingTypes.In);
isPaused = true;
}
protected override void PopOut()
{
FadeTo(0, fadeDuration, EasingTypes.In);
isPaused = false;
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
TogglePaused();
case Key.Escape:
Hide();
OnResume?.Invoke();
return true;
}
return base.OnKeyDown(state, args);
}
public void Pause()
{
if (Time.Current >= (lastActionTime + pauseCooldown))
{
lastActionTime = Time.Current;
Show();
OnPause?.Invoke();
}
else
{
isPaused = false;
}
}
public void Resume()
{
lastActionTime = Time.Current;
Hide();
OnResume?.Invoke();
}
public void TogglePaused()
{
isPaused = !isPaused;
(isPaused ? (Action)Pause : Resume)?.Invoke();
}
private void Retry()
{
Hide();
OnRetry?.Invoke();
}
private void Quit()
{
Hide();
OnQuit?.Invoke();
}
public PauseOverlay()
{
RelativeSizeAxes = Axes.Both;

View File

@ -22,6 +22,7 @@ using osu.Framework.GameModes;
using osu.Game.Modes.UI;
using osu.Game.Screens.Ranking;
using osu.Game.Configuration;
using osu.Game.Overlays.Pause;
using osu.Framework.Configuration;
using System;
using OpenTK.Graphics;
@ -40,6 +41,11 @@ namespace osu.Game.Screens.Play
public PlayMode PreferredPlayMode;
public bool isPaused;
private double pauseCooldown = 1000;
private double lastActionTime = 0;
private IAdjustableClock sourceClock;
private Ruleset ruleset;
@ -48,6 +54,9 @@ namespace osu.Game.Screens.Play
private HitRenderer hitRenderer;
private Bindable<int> dimLevel;
private ScoreOverlay scoreOverlay;
private PauseOverlay pauseOverlay;
[BackgroundDependencyLoader]
private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuGameBase game, OsuConfigManager config)
{
@ -92,9 +101,14 @@ namespace osu.Game.Screens.Play
ruleset = Ruleset.GetRuleset(usablePlayMode);
var scoreOverlay = ruleset.CreateScoreOverlay();
scoreOverlay = ruleset.CreateScoreOverlay();
scoreOverlay.BindProcessor(scoreProcessor = ruleset.CreateScoreProcessor(beatmap.HitObjects.Count));
pauseOverlay = new PauseOverlay();
pauseOverlay.OnResume = Resume;
//pauseOverlay.OnRetry = Retry; Add when retrying is implemented
pauseOverlay.OnQuit = Exit;
hitRenderer = ruleset.CreateHitRendererWith(beatmap.HitObjects);
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
@ -119,9 +133,41 @@ namespace osu.Game.Screens.Play
}
},
scoreOverlay,
pauseOverlay
};
}
public void Pause()
{
if (Time.Current >= (lastActionTime + pauseCooldown))
{
lastActionTime = Time.Current;
isPaused = true;
scoreOverlay.KeyCounter.IsCounting = false;
pauseOverlay.Show();
sourceClock.Stop();
}
else
{
isPaused = false;
}
}
public void Resume()
{
lastActionTime = Time.Current;
isPaused = false;
scoreOverlay.KeyCounter.IsCounting = true;
pauseOverlay.Hide();
sourceClock.Start();
}
public void TogglePaused()
{
isPaused = !isPaused;
(isPaused ? (Action)Pause : Resume)?.Invoke();
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -181,6 +227,21 @@ namespace osu.Game.Screens.Play
return base.OnExiting(next);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
if (!isPaused)
{
Pause();
return true;
}
else { return false; }
}
return base.OnKeyDown(state, args);
}
private void dimChanged(object sender, EventArgs e)
{
Background?.FadeTo((100f - dimLevel) / 100, 800);