2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.UI
|
|
|
|
|
{
|
2018-12-13 05:55:28 +00:00
|
|
|
|
public class HitObjectContainer : LifetimeManagementContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-06 05:18:38 +00:00
|
|
|
|
public IEnumerable<DrawableHitObject> Objects => InternalChildren.Cast<DrawableHitObject>().OrderBy(h => h.HitObject.StartTime);
|
|
|
|
|
public IEnumerable<DrawableHitObject> AliveObjects => AliveInternalChildren.Cast<DrawableHitObject>().OrderBy(h => h.HitObject.StartTime);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-21 05:35:50 +00:00
|
|
|
|
public HitObjectContainer()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public virtual void Add(DrawableHitObject hitObject) => AddInternal(hitObject);
|
|
|
|
|
public virtual bool Remove(DrawableHitObject hitObject) => RemoveInternal(hitObject);
|
|
|
|
|
|
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
|
{
|
|
|
|
|
if (!(x is DrawableHitObject xObj) || !(y is DrawableHitObject yObj))
|
|
|
|
|
return base.Compare(x, y);
|
|
|
|
|
|
|
|
|
|
// Put earlier hitobjects towards the end of the list, so they handle input first
|
|
|
|
|
int i = yObj.HitObject.StartTime.CompareTo(xObj.HitObject.StartTime);
|
|
|
|
|
return i == 0 ? CompareReverseChildID(x, y) : i;
|
|
|
|
|
}
|
2019-01-29 06:25:27 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnChildLifetimeBoundaryCrossed(LifetimeBoundaryCrossedEvent e)
|
|
|
|
|
{
|
2019-07-16 09:19:13 +00:00
|
|
|
|
if (!(e.Child is DrawableHitObject hitObject))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-07-17 13:38:17 +00:00
|
|
|
|
if ((e.Kind == LifetimeBoundaryKind.End && e.Direction == LifetimeBoundaryCrossingDirection.Forward)
|
|
|
|
|
|| (e.Kind == LifetimeBoundaryKind.Start && e.Direction == LifetimeBoundaryCrossingDirection.Backward))
|
2019-07-16 09:19:13 +00:00
|
|
|
|
{
|
|
|
|
|
hitObject.OnKilled();
|
|
|
|
|
}
|
2019-01-29 06:25:27 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|