1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:52:56 +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 System;
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
{
public class RetryOverlay : Container
public class HotkeyRetryOverlay : Container
{
public Action Action;
public Action OnKeyPressed;
public Action OnKeyReleased;
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]
private void load(AudioManager audio)
{
retrySample = audio.Sample.Get(@"Menu/menuback");
RelativeSizeAxes = Axes.Both;
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)
@ -33,17 +51,14 @@ namespace osu.Game.Screens.Play
if (args.Key == Key.Tilde)
{
keyIsHeld = true;
OnKeyPressed();
overlay.FadeIn(activate_delay);
Delay(500).Schedule(() =>
task = Scheduler.AddDelayed(() =>
{
if (keyIsHeld)
{
retrySample.Play();
Action();
}
});
retrySample.Play();
Action();
}, activate_delay);
return true;
}
@ -54,8 +69,8 @@ namespace osu.Game.Screens.Play
{
if (args.Key == Key.Tilde)
{
keyIsHeld = false;
OnKeyReleased();
task?.Cancel();
overlay.FadeOut(fadeout_delay);
return true;
}

View File

@ -159,11 +159,9 @@ namespace osu.Game.Screens.Play
OnRetry = Restart,
OnQuit = Exit,
},
new RetryOverlay
new HotkeyRetryOverlay
{
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\Charts\ChartInfo.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\Loader.cs" />
<Compile Include="Screens\Menu\Button.cs" />