// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Modes.Objects; using osu.Game.Modes.Objects.Drawables; using OpenTK; using osu.Game.Modes.Judgements; namespace osu.Game.Modes.UI { public abstract class Playfield : Container where TObject : HitObject where TJudgement : JudgementInfo { /// /// The HitObjects contained in this Playfield. /// public HitObjectContainer> HitObjects; public override bool Contains(Vector2 screenSpacePos) => true; internal Container ScaledContent; protected override Container Content => content; private Container content; /// /// A container for keeping track of DrawableHitObjects. /// /// Whether we want our internal coordinate system to be scaled to a specified width. protected Playfield(float? customWidth = null) { AddInternal(ScaledContent = new ScaledContainer { CustomWidth = customWidth, RelativeSizeAxes = Axes.Both, Children = new[] { content = new Container { RelativeSizeAxes = Axes.Both, } } }); Add(HitObjects = new HitObjectContainer> { RelativeSizeAxes = Axes.Both, }); } /// /// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield. /// public virtual void PostProcess() { } /// /// Adds a DrawableHitObject to this Playfield. /// /// The DrawableHitObject to add. public virtual void Add(DrawableHitObject h) => HitObjects.Add(h); /// /// Triggered when an object's Judgement is updated. /// /// The object that Judgement has been updated for. public virtual void OnJudgement(DrawableHitObject judgedObject) { } private class ScaledContainer : Container { /// /// A value (in game pixels that we should scale our content to match). /// public float? CustomWidth; //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 override bool Contains(Vector2 screenSpacePos) => true; } public class HitObjectContainer : Container where U : Drawable { public override bool Contains(Vector2 screenSpacePos) => true; } } }