1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +08:00

Add small test case to demonstrate usage.

This commit is contained in:
smoogipooo 2017-06-12 17:31:24 +09:00
parent ba8014bbd9
commit 56244e0134
5 changed files with 142 additions and 13 deletions

View File

@ -0,0 +1,128 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Globalization;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Timing;
namespace osu.Desktop.VisualTests.Tests
{
public class TestCaseScrollingHitObjects : TestCase
{
public override string Description => "SpeedAdjustmentContainer/DrawableTimingSection";
private SpeedAdjustmentCollection adjustmentCollection;
private BindableDouble timeRangeBindable;
private SpriteText timeRangeText;
public override void Reset()
{
base.Reset();
timeRangeBindable = new BindableDouble(2000)
{
MinValue = 50,
MaxValue = 20000,
};
SliderBar<double> timeRange;
Add(timeRange = new BasicSliderBar<double>
{
Size = new Vector2(200, 20),
SelectionColor = Color4.Pink,
KeyboardStep = 100
});
Add(timeRangeText = new SpriteText
{
X = 210,
TextSize = 16,
});
timeRange.Current.BindTo(timeRangeBindable);
timeRangeBindable.ValueChanged += v => timeRangeText.Text = v.ToString(CultureInfo.InvariantCulture);
Add(new Drawable[]
{
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(100, 500),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.25f
},
adjustmentCollection = new SpeedAdjustmentCollection
{
RelativeSizeAxes = Axes.Both,
VisibleTimeRange = timeRangeBindable
}
}
}
});
adjustmentCollection.Add(new TestSpeedAdjustmentContainer(new MultiplierControlPoint()));
AddStep("Add hit object", () => adjustmentCollection.Add(new TestDrawableHitObject(new HitObject { StartTime = Time.Current + 5000 })));
}
private class TestSpeedAdjustmentContainer : SpeedAdjustmentContainer
{
public TestSpeedAdjustmentContainer(MultiplierControlPoint controlPoint)
: base(controlPoint, Axes.Y)
{
}
protected override DrawableTimingSection CreateTimingSection() => new TestDrawableTimingSection(ControlPoint);
private class TestDrawableTimingSection : DrawableTimingSection
{
private readonly MultiplierControlPoint controlPoint;
public TestDrawableTimingSection(MultiplierControlPoint controlPoint)
: base(Axes.Y)
{
this.controlPoint = controlPoint;
}
protected override void Update()
{
base.Update();
Y = (float)(controlPoint.StartTime - Time.Current);
}
}
}
private class TestDrawableHitObject : DrawableHitObject
{
public TestDrawableHitObject(HitObject hitObject)
: base(hitObject)
{
AutoSizeAxes = Axes.Both;
RelativePositionAxes = Axes.Y;
Y = (float)hitObject.StartTime;
Add(new Box
{
Size = new Vector2(100)
});
}
}
}
}

View File

@ -204,6 +204,7 @@
<Compile Include="Tests\TestCaseReplay.cs" />
<Compile Include="Tests\TestCaseResults.cs" />
<Compile Include="Tests\TestCaseScoreCounter.cs" />
<Compile Include="Tests\TestCaseScrollingHitObjects.cs" />
<Compile Include="Tests\TestCaseSkipButton.cs" />
<Compile Include="Tests\TestCaseTabControl.cs" />
<Compile Include="Tests\TestCaseTaikoHitObjects.cs" />

View File

@ -26,8 +26,8 @@ namespace osu.Game.Rulesets.Mania.Timing
return;
// This is very naive and can be improved, but is adequate for now
LifetimeStart = MultiplierControlPoint.StartTime - VisibleTimeRange;
LifetimeEnd = MultiplierControlPoint.StartTime + Content.Height * 2;
LifetimeStart = ControlPoint.StartTime - VisibleTimeRange;
LifetimeEnd = ControlPoint.StartTime + Content.Height * 2;
}
protected override DrawableTimingSection CreateTimingSection()
@ -36,9 +36,9 @@ namespace osu.Game.Rulesets.Mania.Timing
{
default:
case ScrollingAlgorithm.Basic:
return new BasicScrollingDrawableTimingSection(MultiplierControlPoint);
return new BasicScrollingDrawableTimingSection(ControlPoint);
case ScrollingAlgorithm.Gravity:
return new GravityScrollingDrawableTimingSection(MultiplierControlPoint);
return new GravityScrollingDrawableTimingSection(ControlPoint);
}
}
}

View File

@ -77,11 +77,11 @@ namespace osu.Game.Rulesets.Timing
var speedAdjustmentY = y as SpeedAdjustmentContainer;
// If either of the two drawables are not hit objects, fall back to the base comparer
if (speedAdjustmentX?.MultiplierControlPoint == null || speedAdjustmentY?.MultiplierControlPoint == null)
if (speedAdjustmentX?.ControlPoint == null || speedAdjustmentY?.ControlPoint == null)
return base.Compare(x, y);
// Compare by start time
int i = speedAdjustmentY.MultiplierControlPoint.StartTime.CompareTo(speedAdjustmentX.MultiplierControlPoint.StartTime);
int i = speedAdjustmentY.ControlPoint.StartTime.CompareTo(speedAdjustmentX.ControlPoint.StartTime);
return i != 0 ? i : base.Compare(x, y);
}

View File

@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Timing
/// <summary>
/// The <see cref="MultiplierControlPoint"/> which provides the speed adjustments for this container.
/// </summary>
public readonly MultiplierControlPoint MultiplierControlPoint;
public readonly MultiplierControlPoint ControlPoint;
protected override Container<DrawableHitObject> Content => content;
private Container<DrawableHitObject> content;
@ -44,15 +44,15 @@ namespace osu.Game.Rulesets.Timing
/// <summary>
/// Creates a new <see cref="SpeedAdjustmentContainer"/>.
/// </summary>
/// <param name="multiplierControlPoint">The <see cref="MultiplierControlPoint"/> which provides the speed adjustments for this container.</param>
/// <param name="controlPoint">The <see cref="MultiplierControlPoint"/> which provides the speed adjustments for this container.</param>
/// <param name="scrollingAxes">The axes through which the content of this container should scroll through.</param>
protected SpeedAdjustmentContainer(MultiplierControlPoint multiplierControlPoint, Axes scrollingAxes)
protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint, Axes scrollingAxes)
{
this.scrollingAxes = scrollingAxes;
RelativeSizeAxes = Axes.Both;
MultiplierControlPoint = multiplierControlPoint;
ControlPoint = controlPoint;
}
[BackgroundDependencyLoader]
@ -61,14 +61,14 @@ namespace osu.Game.Rulesets.Timing
DrawableTimingSection timingSection = CreateTimingSection();
timingSection.VisibleTimeRange.BindTo(VisibleTimeRange);
timingSection.RelativeChildOffset = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)MultiplierControlPoint.StartTime : 0, (scrollingAxes & Axes.Y) > 0 ? (float)MultiplierControlPoint.StartTime : 0);
timingSection.RelativeChildOffset = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (scrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0);
AddInternal(content = timingSection);
}
protected override void Update()
{
float multiplier = (float)MultiplierControlPoint.Multiplier;
float multiplier = (float)ControlPoint.Multiplier;
// The speed adjustment happens by modifying our size by the multiplier while maintaining the visible time range as the relatve size for our children
Size = new Vector2((scrollingAxes & Axes.X) > 0 ? multiplier : 1, (scrollingAxes & Axes.Y) > 0 ? multiplier : 1);
@ -78,7 +78,7 @@ namespace osu.Game.Rulesets.Timing
/// <summary>
/// Whether this speed adjustment can contain a hit object. This is true if the hit object occurs after this speed adjustment with respect to time.
/// </summary>
public bool CanContain(DrawableHitObject hitObject) => MultiplierControlPoint.StartTime <= hitObject.HitObject.StartTime;
public bool CanContain(DrawableHitObject hitObject) => ControlPoint.StartTime <= hitObject.HitObject.StartTime;
/// <summary>
/// Creates the container which handles the movement of a collection of hit objects.