Use CompositeDrawable for HitObjectContainer. Removes a looooooot of generics 👍.

This commit is contained in:
smoogipooo
2017-08-08 17:37:11 +09:00
parent 9e01b47a09
commit cae21869d0
3 changed files with 24 additions and 27 deletions

View File

@ -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
/// <summary>
/// The HitObjects contained in this Playfield.
/// </summary>
public HitObjectContainer<DrawableHitObject<TObject, TJudgement>> HitObjects { get; protected set; }
public HitObjectContainer HitObjects { get; protected set; }
internal Container<Drawable> ScaledContent;
@ -53,7 +55,7 @@ namespace osu.Game.Rulesets.UI
}
});
HitObjects = new HitObjectContainer<DrawableHitObject<TObject, TJudgement>>
HitObjects = new HitObjectContainer
{
RelativeSizeAxes = Axes.Both,
};
@ -94,6 +96,13 @@ namespace osu.Game.Rulesets.UI
/// <param name="judgedObject">The object that Judgement has been updated for.</param>
public virtual void OnJudgement(DrawableHitObject<TObject, TJudgement> judgedObject) { }
public class HitObjectContainer : CompositeDrawable
{
public virtual IEnumerable<DrawableHitObject> Objects => InternalChildren.OfType<DrawableHitObject>();
public virtual void Add(DrawableHitObject hitObject) => AddInternal(hitObject);
public virtual bool Remove(DrawableHitObject hitObject) => RemoveInternal(hitObject);
}
private class ScaledContainer : Container
{
/// <summary>
@ -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<U> : Container<U>
where U : Drawable
{
}
}
}