mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:43:20 +08:00
Merge pull request #21093 from peppy/auto-skip-multiple-times
Fix automated skip not skipping more than once when required
This commit is contained in:
commit
e336d486a6
@ -93,6 +93,15 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
checkRequestCount(1);
|
checkRequestCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAutomaticSkipActuatesOnce()
|
||||||
|
{
|
||||||
|
createTest();
|
||||||
|
AddStep("start automated skip", () => skip.SkipWhenReady());
|
||||||
|
AddUntilStep("wait for button disabled", () => !skip.IsButtonVisible);
|
||||||
|
checkRequestCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestClickOnlyActuatesOnce()
|
public void TestClickOnlyActuatesOnce()
|
||||||
{
|
{
|
||||||
@ -110,6 +119,16 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
checkRequestCount(1);
|
checkRequestCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAutomaticSkipActuatesMultipleTimes()
|
||||||
|
{
|
||||||
|
createTest();
|
||||||
|
AddStep("set increment lower", () => increment = 3000);
|
||||||
|
AddStep("start automated skip", () => skip.SkipWhenReady());
|
||||||
|
AddUntilStep("wait for button disabled", () => !skip.IsButtonVisible);
|
||||||
|
checkRequestCount(2);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestClickOnlyActuatesMultipleTimes()
|
public void TestClickOnlyActuatesMultipleTimes()
|
||||||
{
|
{
|
||||||
@ -137,8 +156,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
checkRequestCount(0);
|
checkRequestCount(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRequestCount(int expected) =>
|
private void checkRequestCount(int expected)
|
||||||
AddAssert($"request count is {expected}", () => requestCount == expected);
|
{
|
||||||
|
AddAssert($"skip count is {expected}", () => skip.SkipCount, () => Is.EqualTo(expected));
|
||||||
|
AddAssert($"request count is {expected}", () => requestCount, () => Is.EqualTo(expected));
|
||||||
|
}
|
||||||
|
|
||||||
private class TestSkipOverlay : SkipOverlay
|
private class TestSkipOverlay : SkipOverlay
|
||||||
{
|
{
|
||||||
|
@ -27,6 +27,11 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
public class SkipOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
public class SkipOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The total number of successful skips performed by this overlay.
|
||||||
|
/// </summary>
|
||||||
|
public int SkipCount { get; private set; }
|
||||||
|
|
||||||
private readonly double startTime;
|
private readonly double startTime;
|
||||||
|
|
||||||
public Action RequestSkip;
|
public Action RequestSkip;
|
||||||
@ -124,23 +129,36 @@ namespace osu.Game.Screens.Play
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.Action = () => RequestSkip?.Invoke();
|
button.Action = () =>
|
||||||
|
{
|
||||||
|
SkipCount++;
|
||||||
|
RequestSkip?.Invoke();
|
||||||
|
};
|
||||||
|
|
||||||
fadeContainer.TriggerShow();
|
fadeContainer.TriggerShow();
|
||||||
|
|
||||||
if (skipQueued)
|
|
||||||
{
|
|
||||||
Scheduler.AddDelayed(() => button.TriggerClick(), 200);
|
|
||||||
skipQueued = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Triggers an "automated" skip to happen as soon as available.
|
||||||
|
/// </summary>
|
||||||
public void SkipWhenReady()
|
public void SkipWhenReady()
|
||||||
{
|
{
|
||||||
if (IsLoaded)
|
if (skipQueued) return;
|
||||||
button.TriggerClick();
|
|
||||||
else
|
|
||||||
skipQueued = true;
|
skipQueued = true;
|
||||||
|
attemptNextSkip();
|
||||||
|
|
||||||
|
void attemptNextSkip() => Scheduler.AddDelayed(() =>
|
||||||
|
{
|
||||||
|
if (!button.Enabled.Value)
|
||||||
|
{
|
||||||
|
skipQueued = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.TriggerClick();
|
||||||
|
attemptNextSkip();
|
||||||
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
|
Loading…
Reference in New Issue
Block a user