mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Add tests and expand functionality to ensure single fire
This commit is contained in:
62
osu.Game.Tests/Visual/TestCaseHoldToConfirmOverlay.cs
Normal file
62
osu.Game.Tests/Visual/TestCaseHoldToConfirmOverlay.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Screens.Menu;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual
|
||||||
|
{
|
||||||
|
public class TestCaseHoldToConfirmOverlay : OsuTestCase
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(ExitConfirmOverlay) };
|
||||||
|
|
||||||
|
public TestCaseHoldToConfirmOverlay()
|
||||||
|
{
|
||||||
|
bool fired = false;
|
||||||
|
|
||||||
|
var abortText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = "Aborted!",
|
||||||
|
TextSize = 50,
|
||||||
|
Alpha = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
var overlay = new TestHoldToConfirmOverlay
|
||||||
|
{
|
||||||
|
Action = () =>
|
||||||
|
{
|
||||||
|
fired = true;
|
||||||
|
abortText.FadeTo(1).Then().FadeOut(1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
overlay,
|
||||||
|
abortText
|
||||||
|
};
|
||||||
|
|
||||||
|
AddStep("start confirming", () => overlay.Begin());
|
||||||
|
AddStep("abort confirming", () => overlay.Abort());
|
||||||
|
|
||||||
|
AddAssert("ensure aborted", () => !fired);
|
||||||
|
|
||||||
|
AddStep("start confirming", () => overlay.Begin());
|
||||||
|
|
||||||
|
AddUntilStep(() => fired, "wait until confirmed");
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestHoldToConfirmOverlay : ExitConfirmOverlay
|
||||||
|
{
|
||||||
|
protected override bool AllowMultipleFires => true;
|
||||||
|
|
||||||
|
public void Begin() => BeginConfirm();
|
||||||
|
public void Abort() => AbortConfirm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,11 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private bool fired;
|
private bool fired;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the overlay should be allowed to return from a fired state.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool AllowMultipleFires => false;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
@ -42,18 +47,20 @@ namespace osu.Game.Overlays
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BeginConfirm() => overlay.FadeIn(activate_delay, Easing.Out);
|
protected void BeginConfirm()
|
||||||
|
|
||||||
protected void AbortConfirm() => overlay.FadeOut(fadeout_delay, Easing.Out);
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
{
|
||||||
base.Update();
|
if (!AllowMultipleFires && fired) return;
|
||||||
if (!fired && overlay.Alpha == 1)
|
overlay.FadeIn(activate_delay * (1 - overlay.Alpha), Easing.Out).OnComplete(_ =>
|
||||||
{
|
{
|
||||||
fired = true;
|
|
||||||
Action?.Invoke();
|
Action?.Invoke();
|
||||||
|
fired = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void AbortConfirm()
|
||||||
|
{
|
||||||
|
if (!AllowMultipleFires && fired) return;
|
||||||
|
overlay.FadeOut(fadeout_delay, Easing.Out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user