2019-09-10 06:27:40 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-06-08 09:10:07 +00:00
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-06-08 09:10:07 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-09-10 06:27:40 +00:00
|
|
|
using osu.Framework.Timing;
|
2018-06-08 09:10:07 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2019-02-12 04:04:46 +00:00
|
|
|
using osu.Game.Graphics;
|
2019-05-21 05:13:52 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-06-08 09:10:07 +00:00
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Tests.Visual;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-06-08 09:10:07 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Tests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2019-05-14 19:37:25 +00:00
|
|
|
public class TestSceneNotes : OsuTestScene
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
{
|
2019-09-10 06:27:40 +00:00
|
|
|
Clock = new FramedClock(new ManualClock()),
|
2018-06-08 09:10:07 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(20),
|
|
|
|
Children = new[]
|
|
|
|
{
|
2018-08-08 02:28:55 +00:00
|
|
|
createNoteDisplay(ScrollingDirection.Down, 1, out var note1),
|
|
|
|
createNoteDisplay(ScrollingDirection.Up, 2, out var note2),
|
|
|
|
createHoldNoteDisplay(ScrollingDirection.Down, 1, out var holdNote1),
|
|
|
|
createHoldNoteDisplay(ScrollingDirection.Up, 2, out var holdNote2),
|
2018-06-08 09:10:07 +00:00
|
|
|
}
|
|
|
|
};
|
2018-08-08 02:28:55 +00:00
|
|
|
|
|
|
|
AddAssert("note 1 facing downwards", () => verifyAnchors(note1, Anchor.y2));
|
|
|
|
AddAssert("note 2 facing upwards", () => verifyAnchors(note2, Anchor.y0));
|
|
|
|
AddAssert("hold note 1 facing downwards", () => verifyAnchors(holdNote1, Anchor.y2));
|
|
|
|
AddAssert("hold note 2 facing upwards", () => verifyAnchors(holdNote2, Anchor.y0));
|
2018-06-08 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 02:28:55 +00:00
|
|
|
private Drawable createNoteDisplay(ScrollingDirection direction, int identifier, out DrawableNote hitObject)
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
2019-09-10 06:27:40 +00:00
|
|
|
var note = new Note { StartTime = 0 };
|
2018-06-08 09:10:07 +00:00
|
|
|
note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
|
2018-06-08 12:41:20 +00:00
|
|
|
return new ScrollingTestContainer(direction)
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
2018-06-08 11:13:24 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-08-08 02:28:55 +00:00
|
|
|
Child = new NoteContainer(direction, $"note {identifier}, scrolling {direction.ToString().ToLowerInvariant()}")
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
2019-07-22 05:45:25 +00:00
|
|
|
Child = hitObject = new DrawableNote(note) { AccentColour = { Value = Color4.OrangeRed } }
|
2018-06-08 09:10:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-08 02:28:55 +00:00
|
|
|
private Drawable createHoldNoteDisplay(ScrollingDirection direction, int identifier, out DrawableHoldNote hitObject)
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
2019-09-10 06:27:40 +00:00
|
|
|
var note = new HoldNote { StartTime = 0, Duration = 5000 };
|
2018-06-08 09:10:07 +00:00
|
|
|
note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
|
2018-06-08 12:41:20 +00:00
|
|
|
return new ScrollingTestContainer(direction)
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
2018-06-08 11:13:24 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-08-08 02:28:55 +00:00
|
|
|
Child = new NoteContainer(direction, $"hold note {identifier}, scrolling {direction.ToString().ToLowerInvariant()}")
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
2018-08-08 02:28:55 +00:00
|
|
|
Child = hitObject = new DrawableHoldNote(note)
|
2018-06-08 11:13:24 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-07-22 05:45:25 +00:00
|
|
|
AccentColour = { Value = Color4.OrangeRed },
|
2018-06-08 11:13:24 +00:00
|
|
|
}
|
2018-06-08 09:10:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-08 02:28:55 +00:00
|
|
|
private bool verifyAnchors(DrawableHitObject hitObject, Anchor expectedAnchor)
|
|
|
|
=> hitObject.Anchor.HasFlag(expectedAnchor) && hitObject.Origin.HasFlag(expectedAnchor);
|
|
|
|
|
|
|
|
private bool verifyAnchors(DrawableHoldNote holdNote, Anchor expectedAnchor)
|
|
|
|
=> verifyAnchors((DrawableHitObject)holdNote, expectedAnchor) && holdNote.NestedHitObjects.All(n => verifyAnchors(n, expectedAnchor));
|
|
|
|
|
2018-06-08 09:10:07 +00:00
|
|
|
private class NoteContainer : Container
|
|
|
|
{
|
|
|
|
private readonly Container content;
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
private readonly ScrollingDirection direction;
|
|
|
|
|
|
|
|
public NoteContainer(ScrollingDirection direction, string description)
|
|
|
|
{
|
|
|
|
this.direction = direction;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Width = 45,
|
|
|
|
Height = 100,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 1.25f,
|
2019-09-10 06:27:40 +00:00
|
|
|
Colour = Color4.Green.Opacity(0.5f)
|
2018-06-08 09:10:07 +00:00
|
|
|
},
|
|
|
|
content = new Container { RelativeSizeAxes = Axes.Both }
|
|
|
|
}
|
|
|
|
},
|
2019-05-21 05:13:52 +00:00
|
|
|
new OsuSpriteText
|
2018-06-08 09:10:07 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2019-02-12 04:04:46 +00:00
|
|
|
Font = OsuFont.GetFont(size: 14),
|
2018-06-08 09:10:07 +00:00
|
|
|
Text = description
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-11 08:07:14 +00:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2018-07-02 03:31:41 +00:00
|
|
|
{
|
2018-07-11 08:07:14 +00:00
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-07-02 03:31:41 +00:00
|
|
|
dependencies.CacheAs<IBindable<ManiaAction>>(new Bindable<ManiaAction>());
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
2018-06-08 09:10:07 +00:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
foreach (var obj in content.OfType<DrawableHitObject>())
|
|
|
|
{
|
|
|
|
if (!(obj.HitObject is IHasEndTime endTime))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
foreach (var nested in obj.NestedHitObjects)
|
|
|
|
{
|
|
|
|
double finalPosition = (nested.HitObject.StartTime - obj.HitObject.StartTime) / endTime.Duration;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
2018-06-08 09:10:07 +00:00
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
nested.Y = (float)(finalPosition * content.DrawHeight);
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
2018-06-08 09:10:07 +00:00
|
|
|
case ScrollingDirection.Down:
|
|
|
|
nested.Y = (float)(-finalPosition * content.DrawHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|