1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 02:46:43 +08:00

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

This commit is contained in:
DrabWeb 2017-01-30 04:08:14 -04:00
parent 28967cf77a
commit d70cbd37dd
7 changed files with 157 additions and 49 deletions

View File

@ -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);
}),
}
}
});
}
}

View File

@ -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]

View File

@ -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;

View File

@ -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,

View File

@ -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
}
}
}

View File

@ -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)

View File

@ -239,6 +239,7 @@
<Compile Include="Overlays\Pause\PauseButton.cs" />
<Compile Include="Overlays\Pause\PauseOverlay.cs" />
<Compile Include="Overlays\Pause\PauseProgressBar.cs" />
<Compile Include="Overlays\Pause\PauseProgressGraph.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">