2023-10-26 01:56:51 +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.
|
|
|
|
|
2023-10-26 02:27:07 +08:00
|
|
|
using System.Linq;
|
2023-10-26 01:56:51 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Input;
|
2023-11-10 14:52:02 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Timing;
|
2023-10-26 01:56:51 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2023-10-26 02:27:07 +08:00
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Input;
|
2023-11-09 16:48:43 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-10-26 01:56:51 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2023-11-10 14:52:02 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Storyboards;
|
2023-10-26 01:56:51 +08:00
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests.Mods
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
public partial class TestSceneOsuModTouchDevice : RateAdjustedBeatmapTestScene
|
2023-10-26 01:56:51 +08:00
|
|
|
{
|
2023-10-26 02:27:07 +08:00
|
|
|
[Resolved]
|
|
|
|
private SessionStatics statics { get; set; } = null!;
|
|
|
|
|
2023-11-10 14:52:02 +08:00
|
|
|
private ScoreAccessibleSoloPlayer currentPlayer = null!;
|
2024-03-26 23:38:34 +08:00
|
|
|
private readonly ManualClock manualClock = new ManualClock { Rate = 1 };
|
2023-10-26 01:56:51 +08:00
|
|
|
|
2023-11-10 14:52:02 +08:00
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard? storyboard = null)
|
|
|
|
=> new ClockBackedTestWorkingBeatmap(beatmap, storyboard, new FramedClock(manualClock), Audio);
|
2023-10-26 01:56:51 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2023-10-26 02:27:07 +08:00
|
|
|
Add(new TouchInputInterceptor());
|
2023-10-26 01:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
2023-10-26 02:27:07 +08:00
|
|
|
AddStep("reset static", () => statics.SetValue(Static.TouchInputActive, false));
|
|
|
|
base.SetUpSteps();
|
2023-10-26 01:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-10-26 02:27:07 +08:00
|
|
|
public void TestUserAlreadyHasTouchDeviceActive()
|
2023-10-26 01:56:51 +08:00
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
loadPlayer();
|
2023-10-26 02:27:07 +08:00
|
|
|
AddStep("set up touchscreen user", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
currentPlayer.Score.ScoreInfo.Mods = currentPlayer.Score.ScoreInfo.Mods.Append(new OsuModTouchDevice()).ToArray();
|
2023-10-26 02:27:07 +08:00
|
|
|
statics.SetValue(Static.TouchInputActive, true);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
|
|
|
|
AddStep("seek to 0", () => currentPlayer.GameplayClockContainer.Seek(0));
|
|
|
|
AddUntilStep("wait until 0", () => currentPlayer.GameplayClockContainer.CurrentTime, () => Is.GreaterThanOrEqualTo(0));
|
2023-10-26 01:56:51 +08:00
|
|
|
AddStep("touch circle", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
var touch = new Touch(TouchSource.Touch1, currentPlayer.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.Centre);
|
2023-10-26 01:56:51 +08:00
|
|
|
InputManager.BeginTouch(touch);
|
|
|
|
InputManager.EndTouch(touch);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
AddAssert("touch device mod activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.One.InstanceOf<OsuModTouchDevice>());
|
2023-10-26 01:56:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2024-01-17 00:09:04 +08:00
|
|
|
public void TestTouchActivePriorToPlayerLoad()
|
|
|
|
{
|
|
|
|
AddStep("set touch input active", () => statics.SetValue(Static.TouchInputActive, true));
|
|
|
|
loadPlayer();
|
2024-01-17 00:54:49 +08:00
|
|
|
AddUntilStep("touch device mod activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.One.InstanceOf<OsuModTouchDevice>());
|
2024-01-17 00:09:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-10-26 01:56:51 +08:00
|
|
|
public void TestTouchDuringBreak()
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
loadPlayer();
|
|
|
|
AddStep("seek to 2000", () => currentPlayer.GameplayClockContainer.Seek(2000));
|
|
|
|
AddUntilStep("wait until 2000", () => currentPlayer.GameplayClockContainer.CurrentTime, () => Is.GreaterThanOrEqualTo(2000));
|
2023-11-10 15:30:21 +08:00
|
|
|
AddUntilStep("wait until break entered", () => currentPlayer.IsBreakTime.Value);
|
2023-10-26 01:56:51 +08:00
|
|
|
AddStep("touch playfield", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
var touch = new Touch(TouchSource.Touch1, currentPlayer.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.Centre);
|
2023-10-26 01:56:51 +08:00
|
|
|
InputManager.BeginTouch(touch);
|
|
|
|
InputManager.EndTouch(touch);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
AddAssert("touch device mod not activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.None.InstanceOf<OsuModTouchDevice>());
|
2023-10-26 01:56:51 +08:00
|
|
|
}
|
|
|
|
|
2023-11-06 16:17:19 +08:00
|
|
|
[Test]
|
|
|
|
public void TestTouchMiss()
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
loadPlayer();
|
2023-11-06 16:17:19 +08:00
|
|
|
// ensure mouse is active (and that it's not suppressed due to touches in previous tests)
|
|
|
|
AddStep("click mouse", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
2023-11-10 14:52:02 +08:00
|
|
|
AddStep("seek to 200", () => currentPlayer.GameplayClockContainer.Seek(200));
|
|
|
|
AddUntilStep("wait until 200", () => currentPlayer.GameplayClockContainer.CurrentTime, () => Is.GreaterThanOrEqualTo(200));
|
2023-11-06 16:17:19 +08:00
|
|
|
AddStep("touch playfield", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
var touch = new Touch(TouchSource.Touch1, currentPlayer.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.Centre);
|
2023-11-06 16:17:19 +08:00
|
|
|
InputManager.BeginTouch(touch);
|
|
|
|
InputManager.EndTouch(touch);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
AddAssert("touch device mod activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.One.InstanceOf<OsuModTouchDevice>());
|
2023-11-06 16:17:19 +08:00
|
|
|
}
|
|
|
|
|
2023-11-09 16:48:43 +08:00
|
|
|
[Test]
|
|
|
|
public void TestIncompatibleModActive()
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
loadPlayer();
|
2023-11-09 16:48:43 +08:00
|
|
|
// this is only a veneer of enabling autopilot as having it actually active from the start is annoying to make happen
|
|
|
|
// given the tests' structure.
|
2023-11-10 14:52:02 +08:00
|
|
|
AddStep("enable autopilot", () => currentPlayer.Score.ScoreInfo.Mods = new Mod[] { new OsuModAutopilot() });
|
2023-11-09 16:48:43 +08:00
|
|
|
|
2023-11-10 14:52:02 +08:00
|
|
|
AddStep("seek to 0", () => currentPlayer.GameplayClockContainer.Seek(0));
|
|
|
|
AddUntilStep("wait until 0", () => currentPlayer.GameplayClockContainer.CurrentTime, () => Is.GreaterThanOrEqualTo(0));
|
2023-11-09 16:48:43 +08:00
|
|
|
AddStep("touch playfield", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
var touch = new Touch(TouchSource.Touch1, currentPlayer.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.Centre);
|
2023-11-09 16:48:43 +08:00
|
|
|
InputManager.BeginTouch(touch);
|
|
|
|
InputManager.EndTouch(touch);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
AddAssert("touch device mod not activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.None.InstanceOf<OsuModTouchDevice>());
|
2023-11-09 16:48:43 +08:00
|
|
|
}
|
|
|
|
|
2023-10-26 01:56:51 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSecondObjectTouched()
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
loadPlayer();
|
2023-10-26 01:56:51 +08:00
|
|
|
// ensure mouse is active (and that it's not suppressed due to touches in previous tests)
|
|
|
|
AddStep("click mouse", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
2023-11-10 14:52:02 +08:00
|
|
|
AddStep("seek to 0", () => currentPlayer.GameplayClockContainer.Seek(0));
|
|
|
|
AddUntilStep("wait until 0", () => currentPlayer.GameplayClockContainer.CurrentTime, () => Is.GreaterThanOrEqualTo(0));
|
2023-10-26 01:56:51 +08:00
|
|
|
AddStep("click circle", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
InputManager.MoveMouseTo(currentPlayer.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.Centre);
|
2023-10-26 01:56:51 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
AddAssert("touch device mod not activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.None.InstanceOf<OsuModTouchDevice>());
|
2023-10-26 01:56:51 +08:00
|
|
|
|
2023-11-10 14:52:02 +08:00
|
|
|
AddStep("seek to 5000", () => currentPlayer.GameplayClockContainer.Seek(5000));
|
|
|
|
AddUntilStep("wait until 5000", () => currentPlayer.GameplayClockContainer.CurrentTime, () => Is.GreaterThanOrEqualTo(5000));
|
2023-10-26 01:56:51 +08:00
|
|
|
AddStep("touch playfield", () =>
|
|
|
|
{
|
2023-11-10 14:52:02 +08:00
|
|
|
var touch = new Touch(TouchSource.Touch1, currentPlayer.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.Centre);
|
2023-10-26 01:56:51 +08:00
|
|
|
InputManager.BeginTouch(touch);
|
|
|
|
InputManager.EndTouch(touch);
|
|
|
|
});
|
2023-11-10 14:52:02 +08:00
|
|
|
AddAssert("touch device mod activated", () => currentPlayer.Score.ScoreInfo.Mods, () => Has.One.InstanceOf<OsuModTouchDevice>());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadPlayer()
|
|
|
|
{
|
|
|
|
AddStep("load player", () =>
|
|
|
|
{
|
|
|
|
Beatmap.Value = CreateWorkingBeatmap(new OsuBeatmap
|
|
|
|
{
|
|
|
|
HitObjects =
|
|
|
|
{
|
|
|
|
new HitCircle
|
|
|
|
{
|
|
|
|
Position = OsuPlayfield.BASE_SIZE / 2,
|
|
|
|
StartTime = 0,
|
|
|
|
},
|
|
|
|
new HitCircle
|
|
|
|
{
|
|
|
|
Position = OsuPlayfield.BASE_SIZE / 2,
|
|
|
|
StartTime = 5000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Breaks =
|
|
|
|
{
|
|
|
|
new BreakPeriod(2000, 3000)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var p = new ScoreAccessibleSoloPlayer();
|
|
|
|
|
|
|
|
LoadScreen(currentPlayer = p);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
|
|
|
|
AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class ScoreAccessibleSoloPlayer : SoloPlayer
|
|
|
|
{
|
|
|
|
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
|
|
|
|
|
|
|
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
|
|
|
|
|
|
|
|
protected override bool PauseOnFocusLost => false;
|
|
|
|
|
|
|
|
public ScoreAccessibleSoloPlayer()
|
|
|
|
: base(new PlayerConfiguration
|
|
|
|
{
|
|
|
|
AllowPause = false,
|
|
|
|
ShowResults = false,
|
|
|
|
})
|
|
|
|
{
|
|
|
|
}
|
2023-10-26 01:56:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|