1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 13:32:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestSceneCursorTrail.cs

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

156 lines
4.6 KiB
C#
Raw Normal View History

2019-09-11 12:30:07 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2019-09-11 12:30:07 +08:00
using System;
using System.Collections.Generic;
2019-09-11 12:30:07 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2022-08-02 18:50:57 +08:00
using osu.Framework.Graphics.Rendering;
2019-09-11 12:30:07 +08:00
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing.Input;
using osu.Game.Audio;
2020-12-04 19:21:53 +08:00
using osu.Game.Rulesets.Osu.Skinning.Legacy;
2019-09-11 12:30:07 +08:00
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestSceneCursorTrail : OsuTestScene
{
2022-08-02 19:18:45 +08:00
[Resolved]
private IRenderer renderer { get; set; }
2019-09-11 12:30:07 +08:00
[Test]
public void TestSmoothCursorTrail()
{
2019-09-11 12:40:53 +08:00
Container scalingContainer = null;
createTest(() => scalingContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Child = new CursorTrail()
});
AddStep("set large scale", () => scalingContainer.Scale = new Vector2(10));
2019-09-11 12:30:07 +08:00
}
[Test]
public void TestLegacySmoothCursorTrail()
{
2021-06-06 21:26:27 +08:00
createTest(() =>
2019-09-11 12:30:07 +08:00
{
2022-08-02 19:18:45 +08:00
var skinContainer = new LegacySkinContainer(renderer, false);
2021-06-06 21:26:27 +08:00
var legacyCursorTrail = new LegacyCursorTrail(skinContainer);
skinContainer.Child = legacyCursorTrail;
return skinContainer;
2019-09-11 12:30:07 +08:00
});
}
[Test]
public void TestLegacyDisjointCursorTrail()
{
2021-06-06 21:26:27 +08:00
createTest(() =>
2019-09-11 12:30:07 +08:00
{
2022-08-02 19:18:45 +08:00
var skinContainer = new LegacySkinContainer(renderer, true);
2021-06-06 21:26:27 +08:00
var legacyCursorTrail = new LegacyCursorTrail(skinContainer);
skinContainer.Child = legacyCursorTrail;
return skinContainer;
2019-09-11 12:30:07 +08:00
});
}
private void createTest(Func<Drawable> createContent) => AddStep("create trail", () =>
{
Clear();
Add(new Container
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.8f),
Child = new MovingCursorInputManager { Child = createContent?.Invoke() }
});
});
[Cached(typeof(ISkinSource))]
private class LegacySkinContainer : Container, ISkinSource
{
2022-08-02 19:18:45 +08:00
private readonly IRenderer renderer;
2019-09-11 12:30:07 +08:00
private readonly bool disjoint;
2022-08-02 19:18:45 +08:00
public LegacySkinContainer(IRenderer renderer, bool disjoint)
2019-09-11 12:30:07 +08:00
{
2022-08-02 19:18:45 +08:00
this.renderer = renderer;
2019-09-11 12:30:07 +08:00
this.disjoint = disjoint;
RelativeSizeAxes = Axes.Both;
}
public Drawable GetDrawableComponent(ISkinComponent component) => null;
2019-09-11 12:30:07 +08:00
2020-07-17 15:54:30 +08:00
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
2019-09-11 12:30:07 +08:00
{
switch (componentName)
{
case "cursortrail":
2022-08-02 18:50:57 +08:00
var tex = new Texture(renderer.WhitePixel);
2019-09-11 12:30:07 +08:00
if (disjoint)
tex.ScaleAdjust = 1 / 25f;
return tex;
case "cursormiddle":
2022-08-02 18:50:57 +08:00
return disjoint ? null : renderer.WhitePixel;
2019-09-11 12:30:07 +08:00
}
return null;
}
public ISample GetSample(ISampleInfo sampleInfo) => null;
2019-09-11 12:30:07 +08:00
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => null;
2019-09-11 12:30:07 +08:00
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : null;
2021-05-31 16:25:21 +08:00
public IEnumerable<ISkin> AllSources => new[] { this };
2019-10-30 23:43:13 +08:00
public event Action SourceChanged
{
add { }
remove { }
}
2019-09-11 12:30:07 +08:00
}
private class MovingCursorInputManager : ManualInputManager
{
public MovingCursorInputManager()
{
UseParentInput = false;
}
protected override void Update()
{
base.Update();
const double spin_duration = 1000;
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));
}
}
}
}