2018-01-04 18:20:43 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
using System;
|
2018-01-05 19:56:21 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Caching;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Lists;
|
2018-01-05 19:56:21 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-01-04 19:56:18 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
using osu.Game.Rulesets.Timing;
|
2018-01-04 19:56:18 +08:00
|
|
|
|
using OpenTK;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-04 18:22:15 +08:00
|
|
|
|
namespace osu.Game.Rulesets.UI.Scrolling
|
2018-01-04 18:20:43 +08:00
|
|
|
|
{
|
|
|
|
|
public class ScrollingHitObjectContainer : Playfield.HitObjectContainer
|
|
|
|
|
{
|
|
|
|
|
public readonly BindableDouble TimeRange = new BindableDouble
|
|
|
|
|
{
|
|
|
|
|
MinValue = 0,
|
|
|
|
|
MaxValue = double.MaxValue
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly ScrollingDirection direction;
|
|
|
|
|
|
2018-01-05 19:56:21 +08:00
|
|
|
|
private Cached positionCache = new Cached();
|
|
|
|
|
|
2018-01-04 18:20:43 +08:00
|
|
|
|
public ScrollingHitObjectContainer(ScrollingDirection direction)
|
|
|
|
|
{
|
|
|
|
|
this.direction = direction;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-01-05 19:56:21 +08:00
|
|
|
|
|
|
|
|
|
TimeRange.ValueChanged += v => positionCache.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Add(DrawableHitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
positionCache.Invalidate();
|
|
|
|
|
base.Add(hitObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Remove(DrawableHitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
var result = base.Remove(hitObject);
|
|
|
|
|
if (result)
|
|
|
|
|
positionCache.Invalidate();
|
|
|
|
|
return result;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-05 19:56:21 +08:00
|
|
|
|
private readonly SortedList<MultiplierControlPoint> controlPoints = new SortedList<MultiplierControlPoint>();
|
|
|
|
|
|
|
|
|
|
public void AddControlPoint(MultiplierControlPoint controlPoint)
|
2018-01-05 14:48:19 +08:00
|
|
|
|
{
|
2018-01-05 19:56:21 +08:00
|
|
|
|
controlPoints.Add(controlPoint);
|
|
|
|
|
positionCache.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool RemoveControlPoint(MultiplierControlPoint controlPoint)
|
|
|
|
|
{
|
|
|
|
|
var result = controlPoints.Remove(controlPoint);
|
|
|
|
|
if (result)
|
|
|
|
|
positionCache.Invalidate();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<DrawableHitObject, Vector2> hitObjectPositions = new Dictionary<DrawableHitObject, Vector2>();
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (positionCache.IsValid)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-01-05 14:48:19 +08:00
|
|
|
|
foreach (var obj in Objects)
|
|
|
|
|
{
|
2018-01-05 19:56:21 +08:00
|
|
|
|
var startPosition = hitObjectPositions[obj] = positionAt(obj.HitObject.StartTime);
|
|
|
|
|
|
|
|
|
|
obj.LifetimeStart = obj.HitObject.StartTime - TimeRange - 1000;
|
|
|
|
|
obj.LifetimeEnd = ((obj.HitObject as IHasEndTime)?.EndTime ?? obj.HitObject.StartTime) + TimeRange + 1000;
|
|
|
|
|
|
|
|
|
|
if (!(obj.HitObject is IHasEndTime endTime))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var endPosition = positionAt(endTime.EndTime);
|
|
|
|
|
|
|
|
|
|
float length = Vector2.Distance(startPosition, endPosition);
|
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
|
case ScrollingDirection.Down:
|
|
|
|
|
obj.Height = length;
|
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Left:
|
|
|
|
|
case ScrollingDirection.Right:
|
|
|
|
|
obj.Width = length;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-01-05 14:48:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-05 19:56:21 +08:00
|
|
|
|
positionCache.Validate();
|
2018-01-05 14:48:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 20:45:29 +08:00
|
|
|
|
protected override void UpdateAfterChildrenLife()
|
2018-01-04 18:20:43 +08:00
|
|
|
|
{
|
2018-01-04 20:45:29 +08:00
|
|
|
|
base.UpdateAfterChildrenLife();
|
|
|
|
|
|
2018-01-05 14:48:19 +08:00
|
|
|
|
// We need to calculate this as soon as possible after lifetimes so that hitobjects
|
2018-01-04 20:45:29 +08:00
|
|
|
|
// get the final say in their positions
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
var timelinePosition = positionAt(Time.Current);
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
|
|
|
|
foreach (var obj in AliveObjects)
|
|
|
|
|
{
|
2018-01-05 19:56:21 +08:00
|
|
|
|
var finalPosition = hitObjectPositions[obj];
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
2018-01-05 19:17:02 +08:00
|
|
|
|
obj.Y = finalPosition.Y - timelinePosition.Y;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Down:
|
2018-01-05 19:17:02 +08:00
|
|
|
|
obj.Y = -finalPosition.Y + timelinePosition.Y;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Left:
|
2018-01-05 19:17:02 +08:00
|
|
|
|
obj.X = finalPosition.X - timelinePosition.X;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Right:
|
2018-01-05 19:17:02 +08:00
|
|
|
|
obj.X = -finalPosition.X + timelinePosition.X;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
private Vector2 positionAt(double time)
|
2018-01-04 18:20:43 +08:00
|
|
|
|
{
|
2018-01-05 19:56:21 +08:00
|
|
|
|
double length = 0;
|
|
|
|
|
for (int i = 0; i < controlPoints.Count; i++)
|
2018-01-05 19:17:02 +08:00
|
|
|
|
{
|
2018-01-05 19:56:21 +08:00
|
|
|
|
var current = controlPoints[i];
|
|
|
|
|
var next = i < controlPoints.Count - 1 ? controlPoints[i + 1] : null;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
if (i > 0 && current.StartTime > time)
|
|
|
|
|
continue;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
// Duration of the current control point
|
|
|
|
|
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
length += (float)(Math.Min(currentDuration, time - current.StartTime) * current.Multiplier / TimeRange);
|
|
|
|
|
}
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-05 19:17:02 +08:00
|
|
|
|
return length * DrawSize;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|