2018-01-04 07:21:15 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
|
|
|
|
|
2018-01-04 07:38:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-01-04 07:21:15 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
public class TestCaseScrollingHitObjects : OsuTestCase
|
|
|
|
|
{
|
2018-01-04 07:38:07 +00:00
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(Playfield) };
|
|
|
|
|
|
|
|
|
|
private List<TestPlayfield> playfields = new List<TestPlayfield>();
|
|
|
|
|
|
2018-01-04 07:21:15 +00:00
|
|
|
|
public TestCaseScrollingHitObjects()
|
|
|
|
|
{
|
2018-01-04 07:38:07 +00:00
|
|
|
|
playfields.Add(new TestPlayfield(Direction.Vertical));
|
|
|
|
|
playfields.Add(new TestPlayfield(Direction.Horizontal));
|
2018-01-04 07:21:15 +00:00
|
|
|
|
|
2018-01-04 07:38:07 +00:00
|
|
|
|
AddRange(playfields);
|
2018-01-04 07:21:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 07:38:07 +00:00
|
|
|
|
protected override void LoadComplete()
|
2018-01-04 07:21:15 +00:00
|
|
|
|
{
|
2018-01-04 07:38:07 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <= 5000; i += 1000)
|
|
|
|
|
addHitObject(Time.Current + i);
|
|
|
|
|
|
|
|
|
|
Scheduler.AddDelayed(() => addHitObject(Time.Current + 5000), 1000, true);
|
2018-01-04 07:21:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 07:38:07 +00:00
|
|
|
|
private void addHitObject(double time)
|
2018-01-04 07:21:15 +00:00
|
|
|
|
{
|
2018-01-04 07:38:07 +00:00
|
|
|
|
playfields.ForEach(p =>
|
2018-01-04 07:21:15 +00:00
|
|
|
|
{
|
2018-01-04 07:38:07 +00:00
|
|
|
|
p.Add(new TestDrawableHitObject(new HitObject { StartTime = time })
|
|
|
|
|
{
|
|
|
|
|
Anchor = p.ScrollingDirection == Direction.Horizontal ? Anchor.CentreRight : Anchor.BottomCentre
|
|
|
|
|
});
|
2018-01-04 07:21:15 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ScrollingHitObjectContainer : Playfield.HitObjectContainer
|
|
|
|
|
{
|
|
|
|
|
public double TimeRange = 5000;
|
|
|
|
|
|
|
|
|
|
private readonly Direction scrollingDirection;
|
|
|
|
|
|
|
|
|
|
public ScrollingHitObjectContainer(Direction scrollingDirection)
|
|
|
|
|
{
|
|
|
|
|
this.scrollingDirection = scrollingDirection;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 07:38:43 +00:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2018-01-04 07:21:15 +00:00
|
|
|
|
{
|
2018-01-04 07:38:43 +00:00
|
|
|
|
base.UpdateAfterChildren();
|
2018-01-04 07:21:15 +00:00
|
|
|
|
|
2018-01-04 07:38:20 +00:00
|
|
|
|
foreach (var obj in AliveObjects)
|
2018-01-04 07:21:15 +00:00
|
|
|
|
{
|
|
|
|
|
var relativePosition = (Time.Current - obj.HitObject.StartTime) / TimeRange;
|
|
|
|
|
|
|
|
|
|
// Todo: We may need to consider scale here
|
|
|
|
|
var finalPosition = (float)relativePosition * DrawSize;
|
|
|
|
|
|
|
|
|
|
switch (scrollingDirection)
|
|
|
|
|
{
|
|
|
|
|
case Direction.Horizontal:
|
|
|
|
|
obj.X = finalPosition.X;
|
|
|
|
|
break;
|
|
|
|
|
case Direction.Vertical:
|
|
|
|
|
obj.Y = finalPosition.Y;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestPlayfield : Playfield
|
|
|
|
|
{
|
|
|
|
|
public readonly Direction ScrollingDirection;
|
|
|
|
|
|
|
|
|
|
public TestPlayfield(Direction scrollingDirection)
|
|
|
|
|
{
|
|
|
|
|
ScrollingDirection = scrollingDirection;
|
|
|
|
|
|
|
|
|
|
HitObjects = new ScrollingHitObjectContainer(scrollingDirection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestDrawableHitObject : DrawableHitObject<HitObject>
|
|
|
|
|
{
|
|
|
|
|
public TestDrawableHitObject(HitObject hitObject)
|
|
|
|
|
: base(hitObject)
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Add(new Box { Size = new Vector2(75) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|