// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; namespace osu.Game.Rulesets.Timing { /// /// A container that provides the speed adjustments defined by s to affect the scroll speed /// of container s. /// public class SpeedAdjustmentContainer : Container { private readonly Bindable visibleTimeRange = new Bindable { Default = 1000 }; /// /// Gets or sets the range of time that is visible by the length of the scrolling axes. /// public Bindable VisibleTimeRange { get { return visibleTimeRange; } set { visibleTimeRange.BindTo(value); } } private readonly BindableBool reversed = new BindableBool(); /// /// Whether to reverse the scrolling direction is reversed. /// public BindableBool Reversed { get { return reversed; } set { reversed.BindTo(value); } } protected override Container Content => content; private Container content; /// /// The axes which the content of this container will scroll through. /// public Axes ScrollingAxes { get; internal set; } /// /// The that defines the speed adjustments. /// public readonly MultiplierControlPoint ControlPoint; private ScrollingContainer scrollingContainer; /// /// Creates a new . /// /// The that defines the speed adjustments. public SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) { ControlPoint = controlPoint; RelativeSizeAxes = Axes.Both; } [BackgroundDependencyLoader] private void load() { scrollingContainer = CreateScrollingContainer(); scrollingContainer.ScrollingAxes = ScrollingAxes; scrollingContainer.ControlPoint = ControlPoint; scrollingContainer.VisibleTimeRange.BindTo(VisibleTimeRange); scrollingContainer.RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); AddInternal(content = scrollingContainer); } protected override void Update() { 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); if (Reversed) { RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)-VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)-VisibleTimeRange : 1); RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 0); } else { RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); RelativeChildOffset = Vector2.Zero; } } public override double LifetimeStart => ControlPoint.StartTime - VisibleTimeRange; public override double LifetimeEnd => ControlPoint.StartTime + scrollingContainer.Duration + VisibleTimeRange; public override void Add(DrawableHitObject drawable) { var scrollingHitObject = drawable as IScrollingHitObject; if (scrollingHitObject != null) { scrollingHitObject.LifetimeOffset.BindTo(VisibleTimeRange); scrollingHitObject.ScrollingAxes = ScrollingAxes; } base.Add(drawable); } /// /// Whether a falls within this s affecting timespan. /// public bool CanContain(DrawableHitObject hitObject) => CanContain(hitObject.HitObject.StartTime); /// /// Whether a point in time falls within this s affecting timespan. /// public bool CanContain(double startTime) => ControlPoint.StartTime <= startTime; /// /// Creates the which contains the scrolling s of this container. /// /// The . protected virtual ScrollingContainer CreateScrollingContainer() => new LinearScrollingContainer(ScrollingAxes, ControlPoint); } }