1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 11:12:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestSceneResumeOverlay.cs

133 lines
4.9 KiB
C#
Raw Normal View History

2023-06-23 00:37:25 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-03-25 14:30:51 +08:00
// See the LICENCE file in the repository root for full licence text.
2023-11-07 09:52:48 +08:00
using System.Linq;
2023-11-05 11:28:34 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
2019-03-25 14:30:51 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2023-11-07 09:52:48 +08:00
using osu.Framework.Testing;
using osu.Game.Configuration;
2019-03-25 14:30:51 +08:00
using osu.Game.Rulesets.Osu.UI;
2023-11-07 09:52:48 +08:00
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Rulesets.UI;
2019-03-25 14:30:51 +08:00
using osu.Game.Screens.Play;
using osu.Game.Tests.Gameplay;
2019-03-25 14:30:51 +08:00
using osu.Game.Tests.Visual;
2023-11-07 09:52:48 +08:00
using osuTK;
2019-03-25 14:30:51 +08:00
namespace osu.Game.Rulesets.Osu.Tests
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneResumeOverlay : OsuManualInputManagerTestScene
2019-03-25 14:30:51 +08:00
{
2023-11-05 11:28:34 +08:00
private ManualOsuInputManager osuInputManager = null!;
private GameplayCursorContainer cursor = null!;
2023-11-05 11:28:34 +08:00
private ResumeOverlay resume = null!;
2019-03-25 14:30:51 +08:00
2023-11-05 11:28:34 +08:00
private bool resumeFired;
2019-03-25 14:30:51 +08:00
private OsuConfigManager localConfig = null!;
[Cached]
private GameplayState gameplayState;
public TestSceneResumeOverlay()
{
gameplayState = TestGameplayState.Create(new OsuRuleset());
}
[BackgroundDependencyLoader]
private void load()
2023-11-05 11:28:34 +08:00
{
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
}
protected override void LoadComplete()
{
base.LoadComplete();
AddSliderStep("cursor size", 0.1f, 2f, 1f, v => localConfig.SetValue(OsuSetting.GameplayCursorSize, v));
AddSliderStep("circle size", 0f, 10f, 0f, val =>
2019-03-25 14:30:51 +08:00
{
gameplayState.Beatmap.Difficulty.CircleSize = val;
SetUp();
});
2019-03-25 14:30:51 +08:00
AddToggleStep("auto size", v => localConfig.SetValue(OsuSetting.AutoCursorSize, v));
}
[SetUp]
public void SetUp() => Schedule(loadContent);
2019-03-25 14:30:51 +08:00
2023-11-07 09:52:48 +08:00
[TestCase(1)]
[TestCase(0.5f)]
[TestCase(2)]
public void TestResume(float cursorSize)
2023-11-05 11:28:34 +08:00
{
2023-11-07 09:52:48 +08:00
AddStep($"set cursor size to {cursorSize}", () => localConfig.SetValue(OsuSetting.GameplayCursorSize, cursorSize));
2019-03-25 14:30:51 +08:00
AddStep("move mouse to center", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre));
AddStep("show", () => resume.Show());
AddStep("move mouse away", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.TopLeft));
AddStep("click", () => osuInputManager.GameClick());
AddAssert("not dismissed", () => !resumeFired && resume.State.Value == Visibility.Visible);
2019-03-25 14:30:51 +08:00
2023-11-07 09:52:48 +08:00
AddStep("move mouse just out of range", () =>
{
var resumeOverlay = this.ChildrenOfType<OsuResumeOverlay>().Single();
var resumeOverlayCursor = resumeOverlay.ChildrenOfType<OsuResumeOverlay.OsuClickToResumeCursor>().Single();
Vector2 offset = resumeOverlay.ToScreenSpace(new Vector2(OsuCursor.SIZE / 2)) - resumeOverlay.ToScreenSpace(Vector2.Zero);
InputManager.MoveMouseTo(resumeOverlayCursor.ScreenSpaceDrawQuad.Centre - offset - new Vector2(1));
});
AddStep("click", () => osuInputManager.GameClick());
AddAssert("not dismissed", () => !resumeFired && resume.State.Value == Visibility.Visible);
AddStep("move mouse just within range", () =>
{
var resumeOverlay = this.ChildrenOfType<OsuResumeOverlay>().Single();
var resumeOverlayCursor = resumeOverlay.ChildrenOfType<OsuResumeOverlay.OsuClickToResumeCursor>().Single();
Vector2 offset = resumeOverlay.ToScreenSpace(new Vector2(OsuCursor.SIZE / 2)) - resumeOverlay.ToScreenSpace(Vector2.Zero);
InputManager.MoveMouseTo(resumeOverlayCursor.ScreenSpaceDrawQuad.Centre - offset + new Vector2(1));
});
2019-03-25 14:30:51 +08:00
AddStep("click", () => osuInputManager.GameClick());
AddAssert("dismissed", () => resumeFired && resume.State.Value == Visibility.Hidden);
2019-03-25 14:30:51 +08:00
}
private void loadContent()
{
Child = osuInputManager = new ManualOsuInputManager(new OsuRuleset().RulesetInfo)
{
Children = new Drawable[]
{
cursor = new GameplayCursorContainer(),
resume = new OsuResumeOverlay
{
GameplayCursor = cursor
},
}
};
resumeFired = false;
resume.ResumeAction = () => resumeFired = true;
}
2022-11-24 13:32:20 +08:00
private partial class ManualOsuInputManager : OsuInputManager
2019-03-25 14:30:51 +08:00
{
public ManualOsuInputManager(RulesetInfo ruleset)
: base(ruleset)
{
}
public void GameClick()
{
KeyBindingContainer.TriggerPressed(OsuAction.LeftButton);
KeyBindingContainer.TriggerReleased(OsuAction.LeftButton);
}
}
}
}