2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2017-04-10 18:21:27 +08:00
|
|
|
|
using System;
|
2016-11-19 18:07:57 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-03-07 14:43:44 +08:00
|
|
|
|
using OpenTK;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2017-03-21 13:53:55 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.UI
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-09-12 17:19:28 +08:00
|
|
|
|
public abstract class Playfield : Container
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-03-15 17:58:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The HitObjects contained in this Playfield.
|
|
|
|
|
/// </summary>
|
2018-01-08 10:34:37 +08:00
|
|
|
|
public HitObjectContainer HitObjects { get; private set; }
|
2017-03-06 12:59:11 +08:00
|
|
|
|
|
2017-11-21 10:49:42 +08:00
|
|
|
|
public Container<Drawable> ScaledContent;
|
2016-11-19 18:07:57 +08:00
|
|
|
|
|
2017-04-05 16:38:13 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether we are currently providing the local user a gameplay cursor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual bool ProvidingUserCursor => false;
|
|
|
|
|
|
2017-03-09 14:53:16 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container<Drawable> content;
|
2016-12-06 20:14:38 +08:00
|
|
|
|
|
2017-03-07 14:43:44 +08: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 18:07:57 +08:00
|
|
|
|
{
|
2017-04-12 14:04:11 +08:00
|
|
|
|
// Default height since we force relative size axes
|
2017-04-12 11:36:31 +08:00
|
|
|
|
Size = Vector2.One;
|
2017-03-16 16:38:36 +08:00
|
|
|
|
|
2017-03-07 18:30:39 +08:00
|
|
|
|
AddInternal(ScaledContent = new ScaledContainer
|
2016-12-06 20:14:38 +08:00
|
|
|
|
{
|
2017-03-07 14:43:44 +08:00
|
|
|
|
CustomWidth = customWidth,
|
2016-12-06 20:14:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-28 19:14:48 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-03-09 14:53:16 +08:00
|
|
|
|
content = new Container
|
2017-02-28 19:14:48 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-06 20:14:38 +08:00
|
|
|
|
});
|
2017-03-21 13:53:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2018-01-11 15:51:46 +08:00
|
|
|
|
HitObjects = CreateHitObjectContainer();
|
|
|
|
|
HitObjects.RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2017-03-21 13:53:55 +08:00
|
|
|
|
Add(HitObjects);
|
2016-11-19 18:07:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:21:27 +08:00
|
|
|
|
public override Axes RelativeSizeAxes
|
|
|
|
|
{
|
|
|
|
|
get { return Axes.Both; }
|
2017-09-12 17:19:28 +08:00
|
|
|
|
set { throw new InvalidOperationException($@"{nameof(Playfield)}'s {nameof(RelativeSizeAxes)} should never be changed from {Axes.Both}"); }
|
2017-04-10 18:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 17:58:41 +08: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>
|
2017-09-12 17:19:28 +08:00
|
|
|
|
public virtual void Add(DrawableHitObject h) => HitObjects.Add(h);
|
2017-03-15 17:58:41 +08:00
|
|
|
|
|
2017-08-08 09:53:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove a DrawableHitObject from this Playfield.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="h">The DrawableHitObject to remove.</param>
|
2017-09-12 17:19:28 +08:00
|
|
|
|
public virtual void Remove(DrawableHitObject h) => HitObjects.Remove(h);
|
2017-08-08 09:53:59 +08:00
|
|
|
|
|
2017-03-15 17:58:41 +08:00
|
|
|
|
/// <summary>
|
2017-09-06 17:05:51 +08:00
|
|
|
|
/// Triggered when a new <see cref="Judgement"/> occurs on a <see cref="DrawableHitObject"/>.
|
2017-03-15 17:58:41 +08:00
|
|
|
|
/// </summary>
|
2017-09-06 17:05:51 +08:00
|
|
|
|
/// <param name="judgedObject">The object that <paramref name="judgement"/> occured for.</param>
|
|
|
|
|
/// <param name="judgement">The <see cref="Judgement"/> that occurred.</param>
|
2017-09-06 16:02:13 +08:00
|
|
|
|
public virtual void OnJudgement(DrawableHitObject judgedObject, Judgement judgement) { }
|
2017-02-10 13:16:23 +08:00
|
|
|
|
|
2018-01-07 11:47:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer();
|
2017-08-08 16:37:11 +08:00
|
|
|
|
|
2017-03-07 14:43:44 +08:00
|
|
|
|
private class ScaledContainer : Container
|
2016-11-19 18:07:57 +08:00
|
|
|
|
{
|
2017-03-08 10:54:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A value (in game pixels that we should scale our content to match).
|
|
|
|
|
/// </summary>
|
2017-03-07 14:43:44 +08:00
|
|
|
|
public float? CustomWidth;
|
|
|
|
|
|
2017-03-08 10:54:52 +08:00
|
|
|
|
//dividing by the customwidth will effectively scale our content to the required container size.
|
2017-03-07 14:43:44 +08:00
|
|
|
|
protected override Vector2 DrawScale => CustomWidth.HasValue ? new Vector2(DrawSize.X / CustomWidth.Value) : base.DrawScale;
|
2018-01-04 15:28:36 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-01-04 15:31:41 +08:00
|
|
|
|
RelativeChildSize = new Vector2(DrawScale.X, RelativeChildSize.Y);
|
2018-01-04 15:28:36 +08:00
|
|
|
|
}
|
2016-12-06 20:14:38 +08:00
|
|
|
|
}
|
2016-09-02 19:30:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|