1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 06:33:20 +08:00

Improve gameplay cursor test scene + refactor (#6045)

Improve gameplay cursor test scene + refactor

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-09-09 17:53:59 +09:00 committed by GitHub
commit 570e211db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 34 deletions

View File

@ -6,23 +6,68 @@ using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing.Input;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class TestSceneGameplayCursor : SkinnableTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(CursorTrail) };
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(OsuCursorContainer),
typeof(CursorTrail)
};
[BackgroundDependencyLoader]
private void load()
{
SetContents(() => new OsuCursorContainer
SetContents(() => new MovingCursorInputManager
{
Child = new ClickingCursorContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
}
});
}
private class ClickingCursorContainer : OsuCursorContainer
{
protected override void Update()
{
base.Update();
double currentTime = Time.Current;
if (((int)(currentTime / 1000)) % 2 == 0)
OnPressed(OsuAction.LeftButton);
else
OnReleased(OsuAction.LeftButton);
}
}
private class MovingCursorInputManager : ManualInputManager
{
public MovingCursorInputManager()
{
UseParentInput = false;
}
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));
}
}
}
}

View File

@ -22,28 +22,14 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
{
internal class CursorTrail : Drawable, IRequireHighFrequencyMousePosition
{
private int currentIndex;
private IShader shader;
private Texture texture;
private Vector2 size => texture.Size * Scale;
private double timeOffset;
private float time;
public override bool IsPresent => true;
private const int max_sprites = 2048;
private readonly TrailPart[] parts = new TrailPart[max_sprites];
private Vector2? lastPosition;
private readonly InputResampler resampler = new InputResampler();
protected override DrawNode CreateDrawNode() => new TrailDrawNode(this);
private int currentIndex;
private IShader shader;
private Texture texture;
private double timeOffset;
private float time;
public CursorTrail()
{
@ -60,8 +46,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
}
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
[BackgroundDependencyLoader]
private void load(ShaderManager shaders, TextureStore textures)
{
@ -76,6 +60,8 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
resetTime();
}
public override bool IsPresent => true;
protected override void Update()
{
base.Update();
@ -101,6 +87,13 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
timeOffset = Time.Current;
}
private Vector2 size => texture.Size * Scale;
private Vector2? lastPosition;
private readonly InputResampler resampler = new InputResampler();
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
protected override bool OnMouseMove(MouseMoveEvent e)
{
Vector2 pos = e.ScreenSpaceMousePosition;
@ -127,21 +120,19 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
for (float d = interval; d < distance; d += interval)
{
lastPosition = pos1 + direction * d;
addPosition(lastPosition.Value);
parts[currentIndex].Position = lastPosition.Value;
parts[currentIndex].Time = time;
++parts[currentIndex].InvalidationID;
currentIndex = (currentIndex + 1) % max_sprites;
}
}
return base.OnMouseMove(e);
}
private void addPosition(Vector2 pos)
{
parts[currentIndex].Position = pos;
parts[currentIndex].Time = time;
++parts[currentIndex].InvalidationID;
currentIndex = (currentIndex + 1) % max_sprites;
}
protected override DrawNode CreateDrawNode() => new TrailDrawNode(this);
private struct TrailPart
{