osu/osu.Game/Modes/UI/Playfield.cs

79 lines
2.7 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-03-06 04:59:11 +00:00
using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables;
2017-03-07 06:43:44 +00:00
using OpenTK;
using osu.Game.Modes.Judgements;
2016-11-14 09:54:24 +00:00
namespace osu.Game.Modes.UI
{
public abstract class Playfield<TObject, TJudgement> : Container
where TObject : HitObject
where TJudgement : JudgementInfo
{
public HitObjectContainer<DrawableHitObject<TObject, TJudgement>> HitObjects;
2017-03-06 04:59:11 +00:00
public virtual void Add(DrawableHitObject<TObject, TJudgement> h) => HitObjects.Add(h);
2017-03-06 04:59:11 +00:00
internal Container<Drawable> ScaledContent;
public override bool Contains(Vector2 screenSpacePos) => true;
2017-03-09 06:53:16 +00:00
protected override Container<Drawable> Content => content;
private Container<Drawable> content;
2017-03-07 06:43:44 +00:00
/// <summary>
/// A container for keeping track of DrawableHitObjects.
/// </summary>
/// <param name="customWidth">Whether we want our internal coordinate system to be scaled to a specified width.</param>
protected Playfield(float? customWidth = null)
{
AddInternal(ScaledContent = new ScaledContainer
{
2017-03-07 06:43:44 +00:00
CustomWidth = customWidth,
RelativeSizeAxes = Axes.Both,
2017-02-28 11:14:48 +00:00
Children = new[]
{
2017-03-09 06:53:16 +00:00
content = new Container
2017-02-28 11:14:48 +00:00
{
RelativeSizeAxes = Axes.Both,
}
}
});
Add(HitObjects = new HitObjectContainer<DrawableHitObject<TObject, TJudgement>>
{
RelativeSizeAxes = Axes.Both,
});
}
2017-02-10 05:16:23 +00:00
public virtual void PostProcess()
{
}
2017-03-07 06:43:44 +00:00
private class ScaledContainer : Container
{
2017-03-08 02:54:52 +00:00
/// <summary>
/// A value (in game pixels that we should scale our content to match).
/// </summary>
2017-03-07 06:43:44 +00:00
public float? CustomWidth;
2017-03-08 02:54:52 +00:00
//dividing by the customwidth will effectively scale our content to the required container size.
2017-03-07 06:43:44 +00:00
protected override Vector2 DrawScale => CustomWidth.HasValue ? new Vector2(DrawSize.X / CustomWidth.Value) : base.DrawScale;
public override bool Contains(Vector2 screenSpacePos) => true;
}
2017-03-07 06:43:44 +00:00
public class HitObjectContainer<U> : Container<U> where U : Drawable
{
public override bool Contains(Vector2 screenSpacePos) => true;
}
public virtual void OnJudgement(DrawableHitObject<TObject, TJudgement> judgedObject) { }
}
}