2019-12-11 14:24:06 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2021-02-19 14:34:39 +08:00
|
|
|
using System.Collections.Generic;
|
2019-12-11 14:24:06 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets;
|
2021-02-19 14:34:39 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2021-02-19 16:43:33 +08:00
|
|
|
using osuTK;
|
2019-12-11 14:24:06 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
[HeadlessTest] // we alter unsafe properties on the game host to test inactive window state.
|
2020-06-12 18:40:54 +08:00
|
|
|
public class TestScenePauseWhenInactive : OsuPlayerTestScene
|
2019-12-11 14:24:06 +08:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDoesntPauseDuringIntro()
|
|
|
|
{
|
|
|
|
AddStep("set inactive", () => ((Bindable<bool>)host.IsActive).Value = false);
|
2019-12-11 14:47:34 +08:00
|
|
|
|
2019-12-11 14:24:06 +08:00
|
|
|
AddStep("resume player", () => Player.GameplayClockContainer.Start());
|
2019-12-11 14:47:34 +08:00
|
|
|
AddAssert("ensure not paused", () => !Player.GameplayClockContainer.IsPaused.Value);
|
2021-02-19 14:34:39 +08:00
|
|
|
|
|
|
|
AddStep("progress time to gameplay", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.GameplayStartTime));
|
|
|
|
AddUntilStep("wait for pause", () => Player.GameplayClockContainer.IsPaused.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests that if a pause from focus lose is performed while in pause cooldown,
|
|
|
|
/// the player will still pause after the cooldown is finished.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestPauseWhileInCooldown()
|
|
|
|
{
|
2021-02-19 16:43:33 +08:00
|
|
|
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
|
|
|
|
|
2021-02-19 14:34:39 +08:00
|
|
|
AddStep("resume player", () => Player.GameplayClockContainer.Start());
|
|
|
|
AddStep("skip to gameplay", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.GameplayStartTime));
|
|
|
|
|
|
|
|
AddStep("set inactive", () => ((Bindable<bool>)host.IsActive).Value = false);
|
|
|
|
AddUntilStep("wait for pause", () => Player.GameplayClockContainer.IsPaused.Value);
|
|
|
|
|
|
|
|
AddStep("set active", () => ((Bindable<bool>)host.IsActive).Value = true);
|
|
|
|
|
|
|
|
AddStep("resume player", () => Player.Resume());
|
2021-02-19 16:45:45 +08:00
|
|
|
AddAssert("unpaused", () => !Player.GameplayClockContainer.IsPaused.Value);
|
2021-02-19 16:43:33 +08:00
|
|
|
|
|
|
|
bool pauseCooldownActive = false;
|
|
|
|
|
|
|
|
AddStep("set inactive again", () =>
|
2021-02-19 14:34:39 +08:00
|
|
|
{
|
2021-02-19 16:43:33 +08:00
|
|
|
pauseCooldownActive = Player.PauseCooldownActive;
|
|
|
|
((Bindable<bool>)host.IsActive).Value = false;
|
2021-02-19 14:34:39 +08:00
|
|
|
});
|
2021-02-19 16:43:33 +08:00
|
|
|
AddAssert("pause cooldown active", () => pauseCooldownActive);
|
2019-12-11 14:24:06 +08:00
|
|
|
AddUntilStep("wait for pause", () => Player.GameplayClockContainer.IsPaused.Value);
|
|
|
|
}
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(true, true, true);
|
2021-02-19 14:34:39 +08:00
|
|
|
|
|
|
|
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset)
|
|
|
|
{
|
|
|
|
return new Beatmap
|
|
|
|
{
|
|
|
|
HitObjects = new List<HitObject>
|
|
|
|
{
|
|
|
|
new HitCircle { StartTime = 30000 },
|
|
|
|
new HitCircle { StartTime = 35000 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
|
|
|
=> new TestWorkingBeatmap(beatmap, storyboard, Audio);
|
2019-12-11 14:24:06 +08:00
|
|
|
}
|
|
|
|
}
|