osu/osu.Game.Rulesets.Osu.Tests/TestSceneResumeOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
4.9 KiB
C#
Raw Permalink Normal View History

2019-03-25 06:30:51 +00: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-11-07 01:52:48 +00:00
using System.Linq;
2023-11-05 03:28:34 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
2019-03-25 06:30:51 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2023-11-07 01:52:48 +00:00
using osu.Framework.Testing;
using osu.Game.Configuration;
2019-03-25 06:30:51 +00:00
using osu.Game.Rulesets.Osu.UI;
2023-11-07 01:52:48 +00:00
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Rulesets.UI;
2019-03-25 06:30:51 +00:00
using osu.Game.Screens.Play;
using osu.Game.Tests.Gameplay;
2019-03-25 06:30:51 +00:00
using osu.Game.Tests.Visual;
2023-11-07 01:52:48 +00:00
using osuTK;
2019-03-25 06:30:51 +00:00
namespace osu.Game.Rulesets.Osu.Tests
{
public partial class TestSceneResumeOverlay : OsuManualInputManagerTestScene
2019-03-25 06:30:51 +00:00
{
2023-11-05 03:28:34 +00:00
private ManualOsuInputManager osuInputManager = null!;
private GameplayCursorContainer cursor = null!;
2023-11-05 03:28:34 +00:00
private ResumeOverlay resume = null!;
2019-03-25 06:30:51 +00:00
2023-11-05 03:28:34 +00:00
private bool resumeFired;
2019-03-25 06:30:51 +00:00
private OsuConfigManager localConfig = null!;
[Cached]
private GameplayState gameplayState;
public TestSceneResumeOverlay()
{
gameplayState = TestGameplayState.Create(new OsuRuleset());
}
[BackgroundDependencyLoader]
private void load()
2023-11-05 03:28:34 +00: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 06:30:51 +00:00
{
gameplayState.Beatmap.Difficulty.CircleSize = val;
SetUp();
});
2019-03-25 06:30:51 +00:00
AddToggleStep("auto size", v => localConfig.SetValue(OsuSetting.AutoCursorSize, v));
}
[SetUp]
public void SetUp() => Schedule(loadContent);
2019-03-25 06:30:51 +00:00
2023-11-07 01:52:48 +00:00
[TestCase(1)]
[TestCase(0.5f)]
[TestCase(2)]
public void TestResume(float cursorSize)
2023-11-05 03:28:34 +00:00
{
2023-11-07 01:52:48 +00:00
AddStep($"set cursor size to {cursorSize}", () => localConfig.SetValue(OsuSetting.GameplayCursorSize, cursorSize));
2019-03-25 06:30:51 +00: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 06:30:51 +00:00
2023-11-07 01:52:48 +00: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 06:30:51 +00:00
AddStep("click", () => osuInputManager.GameClick());
AddAssert("dismissed", () => resumeFired && resume.State.Value == Visibility.Hidden);
2019-03-25 06:30:51 +00: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;
}
2019-03-25 06:30:51 +00:00
private partial class ManualOsuInputManager : OsuInputManager
{
public ManualOsuInputManager(RulesetInfo ruleset)
: base(ruleset)
{
}
public void GameClick()
{
KeyBindingContainer.TriggerPressed(OsuAction.LeftButton);
KeyBindingContainer.TriggerReleased(OsuAction.LeftButton);
}
}
}
}