1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 16:25:32 +08:00

Split out ScrollingHitObjectContainer into new file

This commit is contained in:
smoogipoo 2018-01-04 19:20:43 +09:00
parent 651e24e3cc
commit e0c921ff5c
4 changed files with 82 additions and 73 deletions

View File

@ -107,13 +107,13 @@ namespace osu.Game.Tests.Visual
public readonly ScrollingDirection Direction; public readonly ScrollingDirection Direction;
public new ScrollingPlayfield.ScrollingHitObjectContainer HitObjects => (ScrollingPlayfield.ScrollingHitObjectContainer)base.HitObjects; public new ScrollingHitObjectContainer HitObjects => (ScrollingHitObjectContainer)base.HitObjects;
public TestPlayfield(ScrollingDirection direction) public TestPlayfield(ScrollingDirection direction)
{ {
Direction = direction; Direction = direction;
base.HitObjects = new ScrollingPlayfield.ScrollingHitObjectContainer(direction); base.HitObjects = new ScrollingHitObjectContainer(direction);
HitObjects.TimeRange.BindTo(TimeRange); HitObjects.TimeRange.BindTo(TimeRange);
} }
} }

View File

@ -0,0 +1,79 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Lists;
using osu.Game.Rulesets.Timing;
namespace osu.Game.Rulesets.UI
{
public class ScrollingHitObjectContainer : Playfield.HitObjectContainer
{
public readonly BindableDouble TimeRange = new BindableDouble
{
MinValue = 0,
MaxValue = double.MaxValue
};
public readonly SortedList<MultiplierControlPoint> ControlPoints = new SortedList<MultiplierControlPoint>();
private readonly ScrollingDirection direction;
public ScrollingHitObjectContainer(ScrollingDirection direction)
{
this.direction = direction;
RelativeSizeAxes = Axes.Both;
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
var currentMultiplier = controlPointAt(Time.Current);
foreach (var obj in AliveObjects)
{
var relativePosition = (Time.Current - obj.HitObject.StartTime) / (TimeRange / currentMultiplier.Multiplier);
// Todo: We may need to consider scale here
var finalPosition = (float)relativePosition * DrawSize;
switch (direction)
{
case ScrollingDirection.Up:
obj.Y = -finalPosition.Y;
break;
case ScrollingDirection.Down:
obj.Y = finalPosition.Y;
break;
case ScrollingDirection.Left:
obj.X = -finalPosition.X;
break;
case ScrollingDirection.Right:
obj.X = finalPosition.X;
break;
}
}
}
private readonly MultiplierControlPoint searchingPoint = new MultiplierControlPoint();
private MultiplierControlPoint controlPointAt(double time)
{
if (ControlPoints.Count == 0)
return new MultiplierControlPoint(double.MinValue);
if (time < ControlPoints[0].StartTime)
return ControlPoints[0];
searchingPoint.StartTime = time;
int index = ControlPoints.BinarySearch(searchingPoint);
if (index < 0)
index = ~index - 1;
return ControlPoints[index];
}
}
}

View File

@ -7,10 +7,8 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.Transforms;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Lists;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Timing;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -122,74 +120,5 @@ namespace osu.Game.Rulesets.UI
protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time); protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time);
protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value; protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value;
} }
public class ScrollingHitObjectContainer : HitObjectContainer
{
public readonly BindableDouble TimeRange = new BindableDouble
{
MinValue = 0,
MaxValue = double.MaxValue
};
public readonly SortedList<MultiplierControlPoint> ControlPoints = new SortedList<MultiplierControlPoint>();
private readonly ScrollingDirection direction;
public ScrollingHitObjectContainer(ScrollingDirection direction)
{
this.direction = direction;
RelativeSizeAxes = Axes.Both;
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
var currentMultiplier = controlPointAt(Time.Current);
foreach (var obj in AliveObjects)
{
var relativePosition = (Time.Current - obj.HitObject.StartTime) / (TimeRange / currentMultiplier.Multiplier);
// Todo: We may need to consider scale here
var finalPosition = (float)relativePosition * DrawSize;
switch (direction)
{
case ScrollingDirection.Up:
obj.Y = -finalPosition.Y;
break;
case ScrollingDirection.Down:
obj.Y = finalPosition.Y;
break;
case ScrollingDirection.Left:
obj.X = -finalPosition.X;
break;
case ScrollingDirection.Right:
obj.X = finalPosition.X;
break;
}
}
}
private readonly MultiplierControlPoint searchingPoint = new MultiplierControlPoint();
private MultiplierControlPoint controlPointAt(double time)
{
if (ControlPoints.Count == 0)
return new MultiplierControlPoint(double.MinValue);
if (time < ControlPoints[0].StartTime)
return ControlPoints[0];
searchingPoint.StartTime = time;
int index = ControlPoints.BinarySearch(searchingPoint);
if (index < 0)
index = ~index - 1;
return ControlPoints[index];
}
}
} }
} }

View File

@ -315,6 +315,7 @@
<Compile Include="Rulesets\Mods\IApplicableMod.cs" /> <Compile Include="Rulesets\Mods\IApplicableMod.cs" />
<Compile Include="Rulesets\Mods\IApplicableToDrawableHitObject.cs" /> <Compile Include="Rulesets\Mods\IApplicableToDrawableHitObject.cs" />
<Compile Include="Rulesets\UI\ScrollingDirection.cs" /> <Compile Include="Rulesets\UI\ScrollingDirection.cs" />
<Compile Include="Rulesets\UI\ScrollingHitObjectContainer.cs" />
<Compile Include="Screens\Select\ImportFromStablePopup.cs" /> <Compile Include="Screens\Select\ImportFromStablePopup.cs" />
<Compile Include="Overlays\Settings\SettingsButton.cs" /> <Compile Include="Overlays\Settings\SettingsButton.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\OriginHandle.cs" /> <Compile Include="Rulesets\Edit\Layers\Selection\OriginHandle.cs" />