diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs b/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs index 2d30d5603a..62e5cda052 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs @@ -152,11 +152,13 @@ namespace osu.Desktop.VisualTests.Tests } } - private class TestDrawableHitObject : DrawableHitObject + private class TestDrawableHitObject : DrawableHitObject, IScrollingHitObject { private readonly Box background; private const float height = 14; + public BindableDouble LifetimeOffset { get; } = new BindableDouble(); + public TestDrawableHitObject(HitObject hitObject) : base(hitObject) { diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs index 4e276fddb7..cb1352fc4a 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets.Objects.Drawables; namespace osu.Game.Rulesets.Mania.Objects.Drawables { - public abstract class DrawableManiaHitObject : DrawableHitObject + public abstract class DrawableManiaHitObject : DrawableScrollingHitObject where TObject : ManiaHitObject { /// diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index f23fab6d1b..79265d6266 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -18,22 +18,6 @@ namespace osu.Game.Rulesets.Objects.Drawables { public abstract class DrawableHitObject : Container { - private readonly BindableDouble lifetimeOffset = new BindableDouble(); - /// - /// Time offset before the hit object start time at which this becomes visible and the time offset - /// after the hit object's end time after which it expires. - /// - /// - /// This provides only a default life time range, however classes inheriting from should expire their state through - /// if more tight control over the life time is desired. - /// - /// - public BindableDouble LifetimeOffset - { - get { return lifetimeOffset; } - set { lifetimeOffset.BindTo(value); } - } - public readonly HitObject HitObject; /// @@ -45,22 +29,6 @@ namespace osu.Game.Rulesets.Objects.Drawables { HitObject = hitObject; } - - public override double LifetimeStart - { - get { return Math.Min(HitObject.StartTime - lifetimeOffset, base.LifetimeStart); } - set { base.LifetimeStart = value; } - } - - public override double LifetimeEnd - { - get - { - var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime; - return Math.Max(endTime + LifetimeOffset, base.LifetimeEnd); - } - set { base.LifetimeEnd = value; } - } } public abstract class DrawableHitObject : DrawableHitObject @@ -217,13 +185,12 @@ namespace osu.Game.Rulesets.Objects.Drawables private List> nestedHitObjects; protected IEnumerable> NestedHitObjects => nestedHitObjects; - protected void AddNested(DrawableHitObject h) + protected virtual void AddNested(DrawableHitObject h) { if (nestedHitObjects == null) nestedHitObjects = new List>(); h.OnJudgement += d => OnJudgement?.Invoke(d); - h.LifetimeOffset = LifetimeOffset; nestedHitObjects.Add(h); } diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs new file mode 100644 index 0000000000..ff6ee35745 --- /dev/null +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -0,0 +1,49 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Configuration; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects.Types; + +namespace osu.Game.Rulesets.Objects.Drawables +{ + /// + /// A basic class that overrides and implements . + /// + public abstract class DrawableScrollingHitObject : DrawableHitObject, IScrollingHitObject + where TObject : HitObject + where TJudgement : Judgement + { + public BindableDouble LifetimeOffset { get; } = new BindableDouble(); + + public DrawableScrollingHitObject(TObject hitObject) + : base(hitObject) + { + } + + public override double LifetimeStart + { + get { return Math.Min(HitObject.StartTime - LifetimeOffset, base.LifetimeStart); } + set { base.LifetimeStart = value; } + } + + public override double LifetimeEnd + { + get + { + var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime; + return Math.Max(endTime + LifetimeOffset, base.LifetimeEnd); + } + set { base.LifetimeEnd = value; } + } + + protected override void AddNested(DrawableHitObject h) + { + var scrollingHitObject = h as IScrollingHitObject; + scrollingHitObject?.LifetimeOffset.BindTo(LifetimeOffset); + + base.AddNested(h); + } + } +} \ No newline at end of file diff --git a/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs new file mode 100644 index 0000000000..560f15f133 --- /dev/null +++ b/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Configuration; +using osu.Framework.Graphics; + +namespace osu.Game.Rulesets.Objects.Drawables +{ + /// + /// An interface that exposes properties required for scrolling hit objects to be properly displayed. + /// + public interface IScrollingHitObject : IDrawable + { + /// + /// Time offset before the hit object start time at which this becomes visible and the time offset + /// after the hit object's end time after which it expires. + /// + /// + /// This provides only a default life time range, however classes inheriting from should override + /// their life times if more tight control is desired. + /// + /// + BindableDouble LifetimeOffset { get; } + } +} \ No newline at end of file diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs index 53ad00c5e1..1323bb14a1 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs @@ -51,6 +51,13 @@ namespace osu.Game.Rulesets.Timing this.scrollingAxes = scrollingAxes; } + public override void Add(SpeedAdjustmentContainer speedAdjustment) + { + speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); + speedAdjustment.ScrollingAxes = scrollingAxes; + base.Add(speedAdjustment); + } + /// /// Adds a hit object to this . The hit objects will be kept in a queue /// and will be processed when new s are added to this . @@ -58,14 +65,10 @@ namespace osu.Game.Rulesets.Timing /// The hit object to add. public void Add(DrawableHitObject hitObject) { - queuedHitObjects.Enqueue(hitObject); - } + if (!(hitObject is IScrollingHitObject)) + throw new InvalidOperationException($"Hit objects added to a {nameof(SpeedAdjustmentCollection)} must implement {nameof(IScrollingHitObject)}."); - public override void Add(SpeedAdjustmentContainer speedAdjustment) - { - speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); - speedAdjustment.ScrollingAxes = scrollingAxes; - base.Add(speedAdjustment); + queuedHitObjects.Enqueue(hitObject); } protected override void Update() diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index 0024b3c9c8..f41ef21c1e 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -82,7 +82,9 @@ namespace osu.Game.Rulesets.Timing public override void Add(DrawableHitObject drawable) { - drawable.LifetimeOffset.BindTo(VisibleTimeRange); + var scrollingHitObject = drawable as IScrollingHitObject; + scrollingHitObject?.LifetimeOffset.BindTo(VisibleTimeRange); + base.Add(drawable); } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 36f358801e..21cf1f0687 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -185,6 +185,7 @@ + @@ -223,6 +224,7 @@ +