Add tests and expand functionality to ensure single fire

This commit is contained in:
Dean Herbert
2018-05-10 17:30:24 +09:00
parent 63e10ec3c2
commit fadb1a5e0b
2 changed files with 78 additions and 9 deletions

View File

@ -25,6 +25,11 @@ namespace osu.Game.Overlays
private bool fired;
/// <summary>
/// Whether the overlay should be allowed to return from a fired state.
/// </summary>
protected virtual bool AllowMultipleFires => false;
[BackgroundDependencyLoader]
private void load()
{
@ -42,18 +47,20 @@ namespace osu.Game.Overlays
};
}
protected void BeginConfirm() => overlay.FadeIn(activate_delay, Easing.Out);
protected void AbortConfirm() => overlay.FadeOut(fadeout_delay, Easing.Out);
protected override void Update()
protected void BeginConfirm()
{
base.Update();
if (!fired && overlay.Alpha == 1)
if (!AllowMultipleFires && fired) return;
overlay.FadeIn(activate_delay * (1 - overlay.Alpha), Easing.Out).OnComplete(_ =>
{
fired = true;
Action?.Invoke();
}
fired = true;
});
}
protected void AbortConfirm()
{
if (!AllowMultipleFires && fired) return;
overlay.FadeOut(fadeout_delay, Easing.Out);
}
}
}