2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2020-07-10 05:47:26 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-09-09 03:48:34 +00:00
|
|
|
|
using osu.Framework.Testing.Input;
|
2020-07-10 05:47:26 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2020-02-14 03:30:11 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI.Cursor;
|
2020-02-14 03:30:11 +00:00
|
|
|
|
using osu.Game.Screens.Play;
|
2019-09-09 03:48:34 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2020-04-07 06:38:29 +00:00
|
|
|
|
public class TestSceneGameplayCursor : OsuSkinnableTestScene
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-02-14 03:30:11 +00:00
|
|
|
|
[Cached]
|
|
|
|
|
private GameplayBeatmap gameplayBeatmap;
|
|
|
|
|
|
|
|
|
|
private ClickingCursorContainer lastContainer;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
2020-07-10 05:47:26 +00:00
|
|
|
|
private Drawable background;
|
|
|
|
|
|
2020-02-14 03:30:11 +00:00
|
|
|
|
public TestSceneGameplayCursor()
|
|
|
|
|
{
|
|
|
|
|
gameplayBeatmap = new GameplayBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
|
2020-07-10 05:47:26 +00:00
|
|
|
|
|
|
|
|
|
AddStep("change background colour", () =>
|
|
|
|
|
{
|
|
|
|
|
background?.Expire();
|
|
|
|
|
|
|
|
|
|
Add(background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Depth = float.MaxValue,
|
|
|
|
|
Colour = new Colour4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddSliderStep("circle size", 0f, 10f, 0f, val =>
|
|
|
|
|
{
|
|
|
|
|
config.Set(OsuSetting.AutoCursorSize, true);
|
|
|
|
|
gameplayBeatmap.BeatmapInfo.BaseDifficulty.CircleSize = val;
|
|
|
|
|
Scheduler.AddOnce(recreate);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddStep("test cursor container", recreate);
|
|
|
|
|
|
|
|
|
|
void recreate() => SetContents(() => new OsuInputManager(new OsuRuleset().RulesetInfo) { Child = new OsuCursorContainer() });
|
2020-02-14 03:30:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(1, 1)]
|
|
|
|
|
[TestCase(5, 1)]
|
|
|
|
|
[TestCase(10, 1)]
|
|
|
|
|
[TestCase(1, 1.5f)]
|
|
|
|
|
[TestCase(5, 1.5f)]
|
|
|
|
|
[TestCase(10, 1.5f)]
|
|
|
|
|
public void TestSizing(int circleSize, float userScale)
|
|
|
|
|
{
|
|
|
|
|
AddStep($"set user scale to {userScale}", () => config.Set(OsuSetting.GameplayCursorSize, userScale));
|
|
|
|
|
AddStep($"adjust cs to {circleSize}", () => gameplayBeatmap.BeatmapInfo.BaseDifficulty.CircleSize = circleSize);
|
|
|
|
|
AddStep("turn on autosizing", () => config.Set(OsuSetting.AutoCursorSize, true));
|
|
|
|
|
|
|
|
|
|
AddStep("load content", loadContent);
|
|
|
|
|
|
|
|
|
|
AddUntilStep("cursor size correct", () => lastContainer.ActiveCursor.Scale.X == OsuCursorContainer.GetScaleForCircleSize(circleSize) * userScale);
|
|
|
|
|
|
|
|
|
|
AddStep("set user scale to 1", () => config.Set(OsuSetting.GameplayCursorSize, 1f));
|
|
|
|
|
AddUntilStep("cursor size correct", () => lastContainer.ActiveCursor.Scale.X == OsuCursorContainer.GetScaleForCircleSize(circleSize));
|
|
|
|
|
|
|
|
|
|
AddStep("turn off autosizing", () => config.Set(OsuSetting.AutoCursorSize, false));
|
|
|
|
|
AddUntilStep("cursor size correct", () => lastContainer.ActiveCursor.Scale.X == 1);
|
|
|
|
|
|
|
|
|
|
AddStep($"set user scale to {userScale}", () => config.Set(OsuSetting.GameplayCursorSize, userScale));
|
|
|
|
|
AddUntilStep("cursor size correct", () => lastContainer.ActiveCursor.Scale.X == userScale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadContent()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-09 03:48:34 +00:00
|
|
|
|
SetContents(() => new MovingCursorInputManager
|
2019-08-30 04:58:17 +00:00
|
|
|
|
{
|
2020-02-14 03:30:11 +00:00
|
|
|
|
Child = lastContainer = new ClickingCursorContainer
|
2019-09-09 03:48:34 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
}
|
2019-08-30 04:58:17 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-09-09 03:48:34 +00:00
|
|
|
|
|
2019-09-09 04:01:40 +00:00
|
|
|
|
private class ClickingCursorContainer : OsuCursorContainer
|
|
|
|
|
{
|
2020-07-10 05:47:11 +00:00
|
|
|
|
private bool pressed;
|
|
|
|
|
|
|
|
|
|
public bool Pressed
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == pressed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pressed = value;
|
|
|
|
|
if (value)
|
|
|
|
|
OnPressed(OsuAction.LeftButton);
|
|
|
|
|
else
|
|
|
|
|
OnReleased(OsuAction.LeftButton);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 04:01:40 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2020-07-10 05:47:11 +00:00
|
|
|
|
Pressed = ((int)(Time.Current / 1000)) % 2 == 0;
|
2019-09-09 04:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 03:48:34 +00:00
|
|
|
|
private class MovingCursorInputManager : ManualInputManager
|
|
|
|
|
{
|
|
|
|
|
public MovingCursorInputManager()
|
|
|
|
|
{
|
|
|
|
|
UseParentInput = false;
|
2020-07-10 05:46:49 +00:00
|
|
|
|
ShowVisualCursorGuide = false;
|
2019-09-09 03:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
const double spin_duration = 5000;
|
|
|
|
|
double currentTime = Time.Current;
|
|
|
|
|
|
|
|
|
|
double angle = (currentTime % spin_duration) / spin_duration * 2 * Math.PI;
|
|
|
|
|
Vector2 rPos = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
|
|
|
|
|
|
|
|
|
|
MoveMouseTo(ToScreenSpace(DrawSize / 2 + DrawSize / 3 * rPos));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|