2017-02-07 04:59:30 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-02 11:30:27 +00:00
2017-04-10 10:21:27 +00:00
using System ;
2016-11-19 10:07:57 +00:00
using osu.Framework.Graphics ;
2016-09-02 11:30:27 +00:00
using osu.Framework.Graphics.Containers ;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Objects ;
using osu.Game.Rulesets.Objects.Drawables ;
2017-03-07 06:43:44 +00:00
using OpenTK ;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Judgements ;
2017-03-21 05:53:55 +00:00
using osu.Framework.Allocation ;
2016-09-02 11:30:27 +00:00
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.UI
2016-09-02 11:30:27 +00:00
{
2017-03-15 09:55:38 +00:00
public abstract class Playfield < TObject , TJudgement > : Container
where TObject : HitObject
2017-03-23 10:00:18 +00:00
where TJudgement : Judgement
2016-09-02 11:30:27 +00:00
{
2017-03-15 09:58:41 +00:00
/// <summary>
/// The HitObjects contained in this Playfield.
/// </summary>
2017-05-11 05:43:57 +00:00
protected HitObjectContainer < DrawableHitObject < TObject , TJudgement > > HitObjects ;
2017-03-06 04:59:11 +00:00
2017-03-07 10:30:39 +00:00
internal Container < Drawable > ScaledContent ;
2016-11-19 10:07:57 +00:00
2017-04-05 08:38:13 +00:00
/// <summary>
/// Whether we are currently providing the local user a gameplay cursor.
/// </summary>
public virtual bool ProvidingUserCursor = > false ;
2017-03-09 06:53:16 +00:00
protected override Container < Drawable > Content = > content ;
2017-03-23 04:41:50 +00:00
private readonly Container < Drawable > content ;
2016-12-06 12:14:38 +00:00
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 )
2016-11-19 10:07:57 +00:00
{
2017-03-16 08:38:36 +00:00
AlwaysReceiveInput = true ;
2017-04-12 06:06:46 +00:00
2017-04-12 06:04:11 +00:00
// Default height since we force relative size axes
2017-04-12 03:36:31 +00:00
Size = Vector2 . One ;
2017-03-16 08:38:36 +00:00
2017-03-07 10:30:39 +00:00
AddInternal ( ScaledContent = new ScaledContainer
2016-12-06 12:14:38 +00:00
{
2017-03-07 06:43:44 +00:00
CustomWidth = customWidth ,
2016-12-06 12:14:38 +00:00
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
{
2017-04-29 07:59:23 +00:00
AlwaysReceiveInput = true ,
2017-02-28 11:14:48 +00:00
RelativeSizeAxes = Axes . Both ,
}
}
2016-12-06 12:14:38 +00:00
} ) ;
2017-03-21 05:53:55 +00:00
HitObjects = new HitObjectContainer < DrawableHitObject < TObject , TJudgement > >
2016-11-19 10:07:57 +00:00
{
RelativeSizeAxes = Axes . Both ,
2017-03-21 05:53:55 +00:00
} ;
}
[BackgroundDependencyLoader]
private void load ( )
{
Add ( HitObjects ) ;
2016-11-19 10:07:57 +00:00
}
2017-04-10 10:21:27 +00:00
public override Axes RelativeSizeAxes
{
get { return Axes . Both ; }
set { throw new InvalidOperationException ( $@"{nameof(Playfield<TObject, TJudgement>)}'s {nameof(RelativeSizeAxes)} should never be changed from {Axes.Both}" ) ; }
}
2017-03-15 09:58:41 +00:00
/// <summary>
/// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield.
/// </summary>
public virtual void PostProcess ( ) { }
/// <summary>
/// Adds a DrawableHitObject to this Playfield.
/// </summary>
/// <param name="h">The DrawableHitObject to add.</param>
public virtual void Add ( DrawableHitObject < TObject , TJudgement > h ) = > HitObjects . Add ( h ) ;
/// <summary>
/// Triggered when an object's Judgement is updated.
/// </summary>
/// <param name="judgedObject">The object that Judgement has been updated for.</param>
public virtual void OnJudgement ( DrawableHitObject < TObject , TJudgement > judgedObject ) { }
2017-02-10 05:16:23 +00:00
2017-03-07 06:43:44 +00:00
private class ScaledContainer : Container
2016-11-19 10:07:57 +00:00
{
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 ;
2016-12-11 09:09:58 +00:00
2017-03-16 08:38:36 +00:00
public ScaledContainer ( )
{
AlwaysReceiveInput = true ;
}
2016-12-06 12:14:38 +00:00
}
2016-11-24 09:58:06 +00:00
2017-03-07 06:43:44 +00:00
public class HitObjectContainer < U > : Container < U > where U : Drawable
2016-12-06 12:14:38 +00:00
{
2017-03-16 08:38:36 +00:00
public HitObjectContainer ( )
{
AlwaysReceiveInput = true ;
}
2016-11-19 10:07:57 +00:00
}
2016-09-02 11:30:27 +00:00
}
}