1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:02:55 +08:00

Applied suggestions

This commit is contained in:
Andrey Zavadskiy 2017-04-10 06:06:10 +03:00
parent c793878ae2
commit e73f543c4f
3 changed files with 32 additions and 19 deletions

View File

@ -8,23 +8,41 @@ using osu.Framework.Audio.Sample;
using osu.Framework.Audio; using osu.Framework.Audio;
using System; using System;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using OpenTK.Graphics;
using osu.Framework.Threading;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class RetryOverlay : Container public class HotkeyRetryOverlay : Container
{ {
public Action Action; public Action Action;
public Action OnKeyPressed;
public Action OnKeyReleased;
private SampleChannel retrySample; private SampleChannel retrySample;
private bool keyIsHeld; private ScheduledDelegate task;
private Box overlay;
private const int activate_delay = 500;
private const int fadeout_delay = 200;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)
{ {
retrySample = audio.Sample.Get(@"Menu/menuback"); retrySample = audio.Sample.Get(@"Menu/menuback");
RelativeSizeAxes = Axes.Both;
AlwaysPresent = true; AlwaysPresent = true;
Children = new Drawable[]
{
overlay = new Box
{
Alpha = 0,
AlwaysPresent = true,
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
}
};
} }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
@ -33,17 +51,14 @@ namespace osu.Game.Screens.Play
if (args.Key == Key.Tilde) if (args.Key == Key.Tilde)
{ {
keyIsHeld = true; overlay.FadeIn(activate_delay);
OnKeyPressed();
Delay(500).Schedule(() => task = Scheduler.AddDelayed(() =>
{ {
if (keyIsHeld) retrySample.Play();
{ Action();
retrySample.Play(); }, activate_delay);
Action();
}
});
return true; return true;
} }
@ -54,8 +69,8 @@ namespace osu.Game.Screens.Play
{ {
if (args.Key == Key.Tilde) if (args.Key == Key.Tilde)
{ {
keyIsHeld = false; task?.Cancel();
OnKeyReleased(); overlay.FadeOut(fadeout_delay);
return true; return true;
} }

View File

@ -159,11 +159,9 @@ namespace osu.Game.Screens.Play
OnRetry = Restart, OnRetry = Restart,
OnQuit = Exit, OnQuit = Exit,
}, },
new RetryOverlay new HotkeyRetryOverlay
{ {
Action = Restart, Action = Restart,
OnKeyPressed = () => Content.FadeColour(Color4.Black, 500),
OnKeyReleased = () => Content.FadeColour(Color4.White, 200),
} }
}; };
} }

View File

@ -180,7 +180,7 @@
<Compile Include="Screens\Backgrounds\BackgroundScreenEmpty.cs" /> <Compile Include="Screens\Backgrounds\BackgroundScreenEmpty.cs" />
<Compile Include="Screens\Charts\ChartInfo.cs" /> <Compile Include="Screens\Charts\ChartInfo.cs" />
<Compile Include="Screens\Edit\Editor.cs" /> <Compile Include="Screens\Edit\Editor.cs" />
<Compile Include="Screens\Play\RetryOverlay.cs" /> <Compile Include="Screens\Play\HotkeyRetryOverlay.cs" />
<Compile Include="Screens\ScreenWhiteBox.cs" /> <Compile Include="Screens\ScreenWhiteBox.cs" />
<Compile Include="Screens\Loader.cs" /> <Compile Include="Screens\Loader.cs" />
<Compile Include="Screens\Menu\Button.cs" /> <Compile Include="Screens\Menu\Button.cs" />