1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 07:42:58 +08:00

Move ScrollAlgorithm inside IScrollingInfo

This commit is contained in:
smoogipoo 2018-11-07 16:51:28 +09:00
parent 54668a0dec
commit e7969ecec7
5 changed files with 30 additions and 31 deletions

View File

@ -10,10 +10,8 @@ using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Objects.Drawables;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Game.Rulesets.Mania.Edit.Blueprints;
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Mania.Edit
{

View File

@ -3,6 +3,7 @@
using osu.Framework.Configuration;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
namespace osu.Game.Rulesets.UI.Scrolling
{
@ -12,5 +13,10 @@ namespace osu.Game.Rulesets.UI.Scrolling
/// The direction <see cref="HitObject"/>s should scroll in.
/// </summary>
IBindable<ScrollingDirection> Direction { get; }
/// <summary>
/// The algorithm which controls <see cref="HitObject"/> positions and sizes.
/// </summary>
IScrollAlgorithm Algorithm { get; }
}
}

View File

@ -7,7 +7,6 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
namespace osu.Game.Rulesets.UI.Scrolling
{
@ -24,9 +23,6 @@ namespace osu.Game.Rulesets.UI.Scrolling
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
[Resolved]
private IScrollAlgorithm algorithm { get; set; }
[Resolved]
private IScrollingInfo scrollingInfo { get; set; }
@ -87,7 +83,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
break;
}
algorithm.Reset();
scrollingInfo.Algorithm.Reset();
foreach (var obj in Objects)
computeInitialStateRecursive(obj);
@ -97,7 +93,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
private void computeInitialStateRecursive(DrawableHitObject hitObject)
{
hitObject.LifetimeStart = algorithm.GetDisplayStartTime(hitObject.HitObject.StartTime, TimeRange);
hitObject.LifetimeStart = scrollingInfo.Algorithm.GetDisplayStartTime(hitObject.HitObject.StartTime, TimeRange);
if (hitObject.HitObject is IHasEndTime endTime)
{
@ -105,11 +101,11 @@ namespace osu.Game.Rulesets.UI.Scrolling
{
case ScrollingDirection.Up:
case ScrollingDirection.Down:
hitObject.Height = algorithm.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
hitObject.Height = scrollingInfo.Algorithm.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
break;
case ScrollingDirection.Left:
case ScrollingDirection.Right:
hitObject.Width = algorithm.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
hitObject.Width = scrollingInfo.Algorithm.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
break;
}
}
@ -137,16 +133,16 @@ namespace osu.Game.Rulesets.UI.Scrolling
switch (direction.Value)
{
case ScrollingDirection.Up:
hitObject.Y = algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
hitObject.Y = scrollingInfo.Algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
break;
case ScrollingDirection.Down:
hitObject.Y = -algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
hitObject.Y = -scrollingInfo.Algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
break;
case ScrollingDirection.Left:
hitObject.X = algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
hitObject.X = scrollingInfo.Algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
break;
case ScrollingDirection.Right:
hitObject.X = -algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
hitObject.X = -scrollingInfo.Algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
break;
}
}

View File

@ -35,30 +35,29 @@ namespace osu.Game.Rulesets.UI.Scrolling
/// <returns></returns>
private readonly SortedList<MultiplierControlPoint> controlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
[Cached(Type = typeof(IScrollingInfo))]
protected readonly IScrollingInfo ScrollingInfo;
protected IScrollingInfo ScrollingInfo => scrollingInfo;
[Cached(Type = typeof(IScrollAlgorithm))]
private readonly IScrollAlgorithm algorithm;
[Cached(Type = typeof(IScrollingInfo))]
private readonly LocalScrollingInfo scrollingInfo;
protected ScrollingRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap)
{
scrollingInfo = new LocalScrollingInfo();
scrollingInfo.Direction.BindTo(Direction);
switch (ScrollAlgorithm)
{
case ScrollAlgorithm.Sequential:
algorithm = new SequentialScrollAlgorithm(controlPoints);
scrollingInfo.Algorithm = new SequentialScrollAlgorithm(controlPoints);
break;
case ScrollAlgorithm.Overlapping:
algorithm = new OverlappingScrollAlgorithm(controlPoints);
scrollingInfo.Algorithm = new OverlappingScrollAlgorithm(controlPoints);
break;
case ScrollAlgorithm.Constant:
algorithm = new ConstantScrollAlgorithm();
scrollingInfo.Algorithm = new ConstantScrollAlgorithm();
break;
}
ScrollingInfo = CreateScrollingInfo();
ScrollingInfo.Direction.BindTo(Direction);
}
[BackgroundDependencyLoader]
@ -109,11 +108,11 @@ namespace osu.Game.Rulesets.UI.Scrolling
controlPoints.Add(new MultiplierControlPoint { Velocity = Beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier });
}
protected virtual IScrollingInfo CreateScrollingInfo() => new LocalScrollingInfo();
private class LocalScrollingInfo : IScrollingInfo
{
public IBindable<ScrollingDirection> Direction { get; } = new Bindable<ScrollingDirection>();
public IScrollAlgorithm Algorithm { get; set; }
}
}
}

View File

@ -18,16 +18,13 @@ namespace osu.Game.Tests.Visual
/// </summary>
public class ScrollingTestContainer : Container
{
public SortedList<MultiplierControlPoint> ControlPoints => scrollAlgorithm.ControlPoints;
public SortedList<MultiplierControlPoint> ControlPoints => scrollingInfo.Algorithm.ControlPoints;
public ScrollAlgorithm ScrollAlgorithm { set => scrollAlgorithm.Algorithm = value; }
public ScrollAlgorithm ScrollAlgorithm { set => scrollingInfo.Algorithm.Algorithm = value; }
[Cached(Type = typeof(IScrollingInfo))]
private readonly TestScrollingInfo scrollingInfo = new TestScrollingInfo();
[Cached(Type = typeof(IScrollAlgorithm))]
private readonly TestScrollAlgorithm scrollAlgorithm = new TestScrollAlgorithm();
public ScrollingTestContainer(ScrollingDirection direction)
{
scrollingInfo.Direction.Value = direction;
@ -39,6 +36,9 @@ namespace osu.Game.Tests.Visual
{
public readonly Bindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
IBindable<ScrollingDirection> IScrollingInfo.Direction => Direction;
public readonly TestScrollAlgorithm Algorithm = new TestScrollAlgorithm();
IScrollAlgorithm IScrollingInfo.Algorithm => Algorithm;
}
private class TestScrollAlgorithm : IScrollAlgorithm