diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index 8334992d5a..7f067efa78 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -24,8 +24,6 @@ namespace osu.Desktop.Tests.Visual /// public class TestCaseScrollingPlayfield : OsuTestCase { - private readonly TestHitRenderer hitRenderer; - public TestCaseScrollingPlayfield() { Clock = new FramedClock(); @@ -52,6 +50,7 @@ namespace osu.Desktop.Tests.Visual WorkingBeatmap beatmap = new TestWorkingBeatmap(b); + TestHitRenderer hitRenderer; Add(hitRenderer = new TestHitRenderer(beatmap, true)); AddStep("Reverse direction", () => hitRenderer.Playfield.Reversed.Value = !hitRenderer.Playfield.Reversed); diff --git a/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs b/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs index e80ac933c8..2604b1ee8a 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs @@ -80,9 +80,9 @@ namespace osu.Game.Rulesets.Osu.UI public override void PostProcess() { - connectionLayer.HitObjects = HitObjects.Children + connectionLayer.HitObjects = HitObjects.Objects .Select(d => d.HitObject) - .OrderBy(h => h.StartTime); + .OrderBy(h => h.StartTime).OfType(); } public override void OnJudgement(DrawableHitObject judgedObject) diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index f521fa18c4..d582f19660 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -85,11 +85,13 @@ namespace osu.Game.Rulesets.Timing { 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); + Origin = Anchor = Anchor.BottomLeft; } else { RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); RelativeChildOffset = Vector2.Zero; + Anchor = Anchor = Anchor.TopLeft; } } diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index ade2c2d070..cc16eff6d6 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -9,6 +9,8 @@ using osu.Game.Rulesets.Objects.Drawables; using OpenTK; using osu.Game.Rulesets.Judgements; using osu.Framework.Allocation; +using System.Collections.Generic; +using System.Linq; namespace osu.Game.Rulesets.UI { @@ -19,7 +21,7 @@ namespace osu.Game.Rulesets.UI /// /// The HitObjects contained in this Playfield. /// - public HitObjectContainer> HitObjects { get; protected set; } + public HitObjectContainer HitObjects { get; protected set; } internal Container ScaledContent; @@ -53,7 +55,7 @@ namespace osu.Game.Rulesets.UI } }); - HitObjects = new HitObjectContainer> + HitObjects = new HitObjectContainer { RelativeSizeAxes = Axes.Both, }; @@ -94,6 +96,13 @@ namespace osu.Game.Rulesets.UI /// The object that Judgement has been updated for. public virtual void OnJudgement(DrawableHitObject judgedObject) { } + public class HitObjectContainer : CompositeDrawable + { + public virtual IEnumerable Objects => InternalChildren.OfType(); + public virtual void Add(DrawableHitObject hitObject) => AddInternal(hitObject); + public virtual bool Remove(DrawableHitObject hitObject) => RemoveInternal(hitObject); + } + private class ScaledContainer : Container { /// @@ -104,10 +113,5 @@ namespace osu.Game.Rulesets.UI //dividing by the customwidth will effectively scale our content to the required container size. protected override Vector2 DrawScale => CustomWidth.HasValue ? new Vector2(DrawSize.X / CustomWidth.Value) : base.DrawScale; } - - public class HitObjectContainer : Container - where U : Drawable - { - } } } diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index adfcb6c971..a54ece4c05 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -141,7 +141,7 @@ namespace osu.Game.Rulesets.UI /// /// A container that provides the foundation for sorting s into s. /// - internal class ScrollingHitObjectContainer : HitObjectContainer> + internal class ScrollingHitObjectContainer : HitObjectContainer { private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; /// @@ -164,13 +164,11 @@ namespace osu.Game.Rulesets.UI set { reversed.BindTo(value); } } - protected override Container> Content => content; - private readonly Container> content; - /// /// Hit objects that are to be re-processed on the next update. /// - private readonly List> queuedHitObjects = new List>(); + private readonly List queuedHitObjects = new List(); + private readonly Container speedAdjustments; private readonly Axes scrollingAxes; @@ -182,8 +180,7 @@ namespace osu.Game.Rulesets.UI { this.scrollingAxes = scrollingAxes; - // The following is never used - it only exists for the purpose of being able to use AddInternal below. - content = new Container>(); + AddInternal(speedAdjustments = new Container { RelativeSizeAxes = Axes.Both }); } /// @@ -195,15 +192,17 @@ namespace osu.Game.Rulesets.UI speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); speedAdjustment.ScrollingAxes = scrollingAxes; speedAdjustment.Reversed = Reversed; - AddInternal(speedAdjustment); + speedAdjustments.Add(speedAdjustment); } + public override IEnumerable Objects => speedAdjustments.SelectMany(s => s.Children); + /// /// Adds a hit object to this . The hit objects will be queued to be processed /// new s are added to this . /// /// The hit object to add. - public override void Add(DrawableHitObject hitObject) + public override void Add(DrawableHitObject hitObject) { if (!(hitObject is IScrollingHitObject)) throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}."); @@ -211,13 +210,7 @@ namespace osu.Game.Rulesets.UI queuedHitObjects.Add(hitObject); } - public override bool Remove(DrawableHitObject hitObject) - { - bool removed = InternalChildren.OfType().Any(c => c.Remove(hitObject)); - removed = removed || queuedHitObjects.Remove(hitObject); - - return removed; - } + public override bool Remove(DrawableHitObject hitObject) => speedAdjustments.Any(s => s.Remove(hitObject)) || queuedHitObjects.Remove(hitObject); protected override void Update() { @@ -246,7 +239,7 @@ namespace osu.Game.Rulesets.UI /// /// The hit object to find the active for. /// The active at 's start time. Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(hitObject)) ?? InternalChildren.OfType().LastOrDefault(); + private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => speedAdjustments.FirstOrDefault(c => c.CanContain(hitObject)) ?? speedAdjustments.LastOrDefault(); /// /// Finds the which provides the speed adjustment active at a time. @@ -254,7 +247,7 @@ namespace osu.Game.Rulesets.UI /// /// The time to find the active at. /// The active at . Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerAt(double time) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(time)) ?? InternalChildren.OfType().LastOrDefault(); + private SpeedAdjustmentContainer adjustmentContainerAt(double time) => speedAdjustments.FirstOrDefault(c => c.CanContain(time)) ?? speedAdjustments.LastOrDefault(); } } } \ No newline at end of file