// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Rulesets.Objects.Drawables; using osu.Framework.Allocation; namespace osu.Game.Rulesets.UI { public abstract class Playfield : ScalableContainer { /// /// The HitObjects contained in this Playfield. /// public HitObjectContainer HitObjects { get; private set; } /// /// All the s nested inside this playfield. /// public IReadOnlyList NestedPlayfields => nestedPlayfields; private List nestedPlayfields; /// /// A container for keeping track of DrawableHitObjects. /// /// The width to scale the internal coordinate space to. /// May be null if scaling based on is desired. If is also null, no scaling will occur. /// /// The height to scale the internal coordinate space to. /// May be null if scaling based on is desired. If is also null, no scaling will occur. /// protected Playfield(float? customWidth = null, float? customHeight = null) : base(customWidth, customHeight) { RelativeSizeAxes = Axes.Both; } [BackgroundDependencyLoader] private void load() { HitObjects = CreateHitObjectContainer(); HitObjects.RelativeSizeAxes = Axes.Both; Add(HitObjects); } /// /// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield. /// public virtual void PostProcess() => nestedPlayfields?.ForEach(p => p.PostProcess()); /// /// Adds a DrawableHitObject to this Playfield. /// /// The DrawableHitObject to add. public virtual void Add(DrawableHitObject h) => HitObjects.Add(h); /// /// Remove a DrawableHitObject from this Playfield. /// /// The DrawableHitObject to remove. public virtual void Remove(DrawableHitObject h) => HitObjects.Remove(h); /// /// Registers a as a nested . /// This does not add the to the draw hierarchy. /// /// The to add. protected void AddNested(Playfield otherPlayfield) { if (nestedPlayfields == null) nestedPlayfields = new List(); nestedPlayfields.Add(otherPlayfield); } /// /// Creates the container that will be used to contain the s. /// protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer(); } }