2018-01-05 20:21:19 +09:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-02-07 13:59:30 +09:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-02 20:30:27 +09:00
2018-01-15 20:22:41 +09:00
using System.Collections.Generic ;
2016-11-19 19:07:57 +09:00
using osu.Framework.Graphics ;
2017-04-18 16:05:58 +09:00
using osu.Game.Rulesets.Objects.Drawables ;
2017-03-21 14:53:55 +09:00
using osu.Framework.Allocation ;
2016-09-02 20:30:27 +09:00
2017-04-18 16:05:58 +09:00
namespace osu.Game.Rulesets.UI
2016-09-02 20:30:27 +09:00
{
2018-02-20 13:50:31 +09:00
public abstract class Playfield : ScalableContainer
2016-09-02 20:30:27 +09:00
{
2017-03-15 18:58:41 +09:00
/// <summary>
/// The HitObjects contained in this Playfield.
/// </summary>
2018-01-08 11:34:37 +09:00
public HitObjectContainer HitObjects { get ; private set ; }
2017-03-06 13:59:11 +09:00
2018-01-15 20:22:41 +09:00
/// <summary>
/// All the <see cref="Playfield"/>s nested inside this playfield.
/// </summary>
public IReadOnlyList < Playfield > NestedPlayfields = > nestedPlayfields ;
2018-02-20 13:50:31 +09:00
private List < Playfield > nestedPlayfields ;
2018-01-15 20:22:41 +09:00
2017-03-07 15:43:44 +09:00
/// <summary>
/// A container for keeping track of DrawableHitObjects.
/// </summary>
2018-02-20 13:50:31 +09:00
/// <param name="customWidth">The width to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customHeight"/> is desired. If <paramref name="customHeight"/> is also null, no scaling will occur.
/// </param>
/// <param name="customHeight">The height to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customWidth"/> is desired. If <paramref name="customWidth"/> is also null, no scaling will occur.
/// </param>
protected Playfield ( float? customWidth = null , float? customHeight = null )
: base ( customWidth , customHeight )
2016-11-19 19:07:57 +09:00
{
2018-01-15 19:44:42 +09:00
RelativeSizeAxes = Axes . Both ;
2017-03-21 14:53:55 +09:00
}
[BackgroundDependencyLoader]
private void load ( )
{
2018-01-11 16:51:46 +09:00
HitObjects = CreateHitObjectContainer ( ) ;
HitObjects . RelativeSizeAxes = Axes . Both ;
2017-03-21 14:53:55 +09:00
Add ( HitObjects ) ;
2016-11-19 19:07:57 +09:00
}
2017-03-15 18:58:41 +09:00
/// <summary>
/// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield.
/// </summary>
2018-01-15 20:22:41 +09:00
public virtual void PostProcess ( ) = > nestedPlayfields ? . ForEach ( p = > p . PostProcess ( ) ) ;
2017-03-15 18:58:41 +09:00
/// <summary>
/// Adds a DrawableHitObject to this Playfield.
/// </summary>
/// <param name="h">The DrawableHitObject to add.</param>
2017-09-12 18:19:28 +09:00
public virtual void Add ( DrawableHitObject h ) = > HitObjects . Add ( h ) ;
2017-03-15 18:58:41 +09:00
2017-08-08 10:53:59 +09:00
/// <summary>
/// Remove a DrawableHitObject from this Playfield.
/// </summary>
/// <param name="h">The DrawableHitObject to remove.</param>
2017-09-12 18:19:28 +09:00
public virtual void Remove ( DrawableHitObject h ) = > HitObjects . Remove ( h ) ;
2017-08-08 10:53:59 +09:00
2017-03-15 18:58:41 +09:00
/// <summary>
2018-01-15 20:22:41 +09:00
/// Registers a <see cref="Playfield"/> as a nested <see cref="Playfield"/>.
/// This does not add the <see cref="Playfield"/> to the draw hierarchy.
2017-03-15 18:58:41 +09:00
/// </summary>
2018-01-15 20:22:41 +09:00
/// <param name="otherPlayfield">The <see cref="Playfield"/> to add.</param>
protected void AddNested ( Playfield otherPlayfield )
{
if ( nestedPlayfields = = null )
nestedPlayfields = new List < Playfield > ( ) ;
nestedPlayfields . Add ( otherPlayfield ) ;
}
2017-02-10 06:16:23 +01:00
2018-01-07 12:47:09 +09:00
/// <summary>
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
/// </summary>
protected virtual HitObjectContainer CreateHitObjectContainer ( ) = > new HitObjectContainer ( ) ;
2016-09-02 20:30:27 +09:00
}
}