1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 23:02:59 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs

363 lines
14 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
2021-03-06 22:06:16 +08:00
using System.Collections.Generic;
using System.Linq;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-03-06 22:06:16 +08:00
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Primitives;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
2020-09-25 18:25:58 +08:00
using osu.Game.Rulesets.Scoring;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements;
using osu.Game.Rulesets.Taiko.Objects;
2021-03-06 22:06:16 +08:00
using osu.Game.Rulesets.Taiko.Scoring;
2020-04-21 18:00:34 +08:00
using osu.Game.Skinning;
2020-05-13 02:26:11 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Taiko.UI
{
public class TaikoPlayfield : ScrollingPlayfield
{
/// <summary>
/// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="DrawableTaikoRuleset"/>.
2018-04-13 17:19:50 +08:00
/// </summary>
public const float DEFAULT_HEIGHT = 200;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Whether the hit target should be nudged further towards the left area, matching the stable "classic" position.
/// </summary>
public Bindable<bool> ClassicHitTargetPosition = new BindableBool();
private Container<HitExplosion> hitExplosionContainer;
private Container<KiaiHitExplosion> kiaiExplosionContainer;
private JudgementContainer<DrawableTaikoJudgement> judgementContainer;
private ScrollingHitObjectContainer drumRollHitContainer;
internal Drawable HitTarget;
2020-05-13 02:26:11 +08:00
private SkinnableDrawable mascot;
2018-04-13 17:19:50 +08:00
2021-03-06 22:06:16 +08:00
private readonly IDictionary<HitResult, DrawablePool<DrawableTaikoJudgement>> judgementPools = new Dictionary<HitResult, DrawablePool<DrawableTaikoJudgement>>();
private readonly IDictionary<HitResult, HitExplosionPool> explosionPools = new Dictionary<HitResult, HitExplosionPool>();
2021-03-06 22:06:16 +08:00
private ProxyContainer topLevelHitContainer;
private InputDrum inputDrum;
private Container rightArea;
2018-04-13 17:19:50 +08:00
/// <remarks>
/// <see cref="Playfield.AddNested"/> is purposefully not called on this to prevent i.e. being able to interact
/// with bar lines in the editor.
/// </remarks>
private BarLinePlayfield barLinePlayfield;
private Container playfieldContent;
private Container playfieldOverlay;
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2018-04-13 17:19:50 +08:00
{
2022-07-22 15:18:22 +08:00
inputDrum = new InputDrum
2022-04-13 09:38:07 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
};
2020-04-25 13:47:20 +08:00
InternalChildren = new[]
2018-04-13 17:19:50 +08:00
{
new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.PlayfieldBackgroundRight), _ => new PlayfieldBackgroundRight()),
2022-04-13 09:38:07 +08:00
new Container
{
Name = "Left overlay",
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
BorderColour = colours.Gray0,
2022-04-13 09:38:07 +08:00
Children = new[]
{
new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.PlayfieldBackgroundLeft), _ => new PlayfieldBackgroundLeft()),
2022-04-13 09:38:07 +08:00
inputDrum.CreateProxy(),
}
},
mascot = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.Mascot), _ => Empty())
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.TopLeft,
RelativePositionAxes = Axes.Y,
RelativeSizeAxes = Axes.None,
Y = 0.2f
},
rightArea = new Container
{
Name = "Right area",
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Container
2018-04-13 17:19:50 +08:00
{
Name = "Elements before hit objects",
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
2020-04-21 18:00:34 +08:00
Children = new[]
2018-04-13 17:19:50 +08:00
{
hitExplosionContainer = new Container<HitExplosion>
{
RelativeSizeAxes = Axes.Both,
},
HitTarget = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.HitTarget), _ => new TaikoHitTarget())
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
2018-04-13 17:19:50 +08:00
}
}
},
new Container
{
Name = "Masked hit objects content",
RelativeSizeAxes = Axes.Both,
Masking = true,
Child = playfieldContent = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
barLinePlayfield = new BarLinePlayfield(),
HitObjectContainer,
}
}
},
playfieldOverlay = new Container
{
Name = "Elements after hit objects",
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
drumRollHitContainer = new DrumRollHitContainer(),
kiaiExplosionContainer = new Container<KiaiHitExplosion>
{
Name = "Kiai hit explosions",
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
},
judgementContainer = new JudgementContainer<DrawableTaikoJudgement>
{
Name = "Judgements",
RelativeSizeAxes = Axes.Y,
},
}
},
}
},
topLevelHitContainer = new ProxyContainer
{
Name = "Top level hit objects",
RelativeSizeAxes = Axes.Both,
2020-04-22 21:19:29 +08:00
},
drumRollHitContainer.CreateProxy(),
new DrumSamplePlayer(HitObjectContainer),
2022-04-13 09:38:07 +08:00
// this is added at the end of the hierarchy to receive input before taiko objects.
// but is proxied below everything to not cover visual effects such as hit explosions.
inputDrum,
};
2020-12-21 01:16:05 +08:00
RegisterPool<Hit, DrawableHit>(50);
RegisterPool<Hit.StrongNestedHit, DrawableHit.StrongNestedHit>(50);
RegisterPool<DrumRoll, DrawableDrumRoll>(5);
RegisterPool<DrumRoll.StrongNestedHit, DrawableDrumRoll.StrongNestedHit>(5);
RegisterPool<DrumRollTick, DrawableDrumRollTick>(100);
RegisterPool<DrumRollTick.StrongNestedHit, DrawableDrumRollTick.StrongNestedHit>(100);
RegisterPool<Swell, DrawableSwell>(5);
RegisterPool<SwellTick, DrawableSwellTick>(100);
2021-03-06 22:06:16 +08:00
var hitWindows = new TaikoHitWindows();
2021-03-06 22:06:16 +08:00
foreach (var result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Where(r => hitWindows.IsHitResultAllowed(r)))
{
2021-03-06 22:06:16 +08:00
judgementPools.Add(result, new DrawablePool<DrawableTaikoJudgement>(15));
explosionPools.Add(result, new HitExplosionPool(result));
}
2021-03-06 22:06:16 +08:00
AddRangeInternal(judgementPools.Values);
AddRangeInternal(explosionPools.Values);
2018-04-13 17:19:50 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
NewResult += OnNewResult;
}
protected override void OnNewDrawableHitObject(DrawableHitObject drawableHitObject)
{
base.OnNewDrawableHitObject(drawableHitObject);
var taikoObject = (DrawableTaikoHitObject)drawableHitObject;
topLevelHitContainer.Add(taikoObject.CreateProxiedContent());
}
protected override void Update()
2018-04-13 17:19:50 +08:00
{
base.Update();
2018-04-13 17:19:50 +08:00
// Padding is required to be updated for elements which are based on "absolute" X sized elements.
// This is basically allowing for correct alignment as relative pieces move around them.
rightArea.Padding = new MarginPadding { Left = inputDrum.Width };
playfieldContent.Padding = new MarginPadding { Left = HitTarget.DrawWidth / 2 };
playfieldOverlay.Padding = new MarginPadding { Left = HitTarget.DrawWidth / 2 };
2020-05-13 02:26:11 +08:00
2020-05-14 00:53:47 +08:00
mascot.Scale = new Vector2(DrawHeight / DEFAULT_HEIGHT);
2018-04-13 17:19:50 +08:00
}
#region Pooling support
public override void Add(HitObject h)
{
switch (h)
{
case BarLine barLine:
barLinePlayfield.Add(barLine);
break;
case TaikoHitObject taikoHitObject:
base.Add(taikoHitObject);
break;
default:
throw new ArgumentException($"Unsupported {nameof(HitObject)} type: {h.GetType()}");
}
}
public override bool Remove(HitObject h)
{
switch (h)
{
case BarLine barLine:
return barLinePlayfield.Remove(barLine);
case TaikoHitObject taikoHitObject:
return base.Remove(taikoHitObject);
default:
throw new ArgumentException($"Unsupported {nameof(HitObject)} type: {h.GetType()}");
}
}
#endregion
#region Non-pooling support
2018-04-13 17:19:50 +08:00
public override void Add(DrawableHitObject h)
{
switch (h)
{
case DrawableBarLine barLine:
barLinePlayfield.Add(barLine);
break;
2019-04-01 11:44:46 +08:00
2022-06-24 20:25:23 +08:00
case DrawableTaikoHitObject:
base.Add(h);
break;
default:
throw new ArgumentException($"Unsupported {nameof(DrawableHitObject)} type: {h.GetType()}");
}
}
public override bool Remove(DrawableHitObject h)
{
switch (h)
{
case DrawableBarLine barLine:
return barLinePlayfield.Remove(barLine);
2022-06-24 20:25:23 +08:00
case DrawableTaikoHitObject:
return base.Remove(h);
default:
throw new ArgumentException($"Unsupported {nameof(DrawableHitObject)} type: {h.GetType()}");
}
2018-04-13 17:19:50 +08:00
}
#endregion
internal void OnNewResult(DrawableHitObject judgedObject, JudgementResult result)
2018-04-13 17:19:50 +08:00
{
2019-02-21 17:56:34 +08:00
if (!DisplayJudgements.Value)
return;
if (!judgedObject.DisplayResult)
return;
2018-08-03 15:46:03 +08:00
switch (result.Judgement)
2018-04-13 17:19:50 +08:00
{
2022-06-24 20:25:23 +08:00
case TaikoStrongJudgement:
2018-08-03 15:46:03 +08:00
if (result.IsHit)
hitExplosionContainer.Children.FirstOrDefault(e => e.JudgedObject == ((DrawableStrongNestedHit)judgedObject).ParentHitObject)?.VisualiseSecondHit(result);
2018-08-03 15:46:03 +08:00
break;
2019-04-01 11:44:46 +08:00
2022-06-24 20:25:23 +08:00
case TaikoDrumRollTickJudgement:
2020-04-27 11:23:53 +08:00
if (!result.IsHit)
break;
2020-04-27 11:23:53 +08:00
var drawableTick = (DrawableDrumRollTick)judgedObject;
addDrumRollHit(drawableTick);
2020-04-27 11:01:31 +08:00
break;
2018-08-03 15:46:03 +08:00
default:
2022-09-06 16:27:29 +08:00
if (!result.Type.IsScorable())
break;
2021-03-06 22:06:16 +08:00
judgementContainer.Add(judgementPools[result.Type].Get(j =>
2018-08-03 15:46:03 +08:00
{
2021-03-06 22:06:16 +08:00
j.Apply(result, judgedObject);
j.Anchor = result.IsHit ? Anchor.TopLeft : Anchor.CentreLeft;
j.Origin = result.IsHit ? Anchor.BottomCentre : Anchor.Centre;
j.RelativePositionAxes = Axes.X;
j.X = result.IsHit ? judgedObject.Position.X : 0;
}));
2018-04-13 17:19:50 +08:00
var type = (judgedObject.HitObject as Hit)?.Type ?? HitType.Centre;
2020-09-25 18:25:58 +08:00
addExplosion(judgedObject, result.Type, type);
2018-08-03 15:46:03 +08:00
break;
2018-04-13 17:19:50 +08:00
}
2020-04-22 21:19:29 +08:00
}
private void addDrumRollHit(DrawableDrumRollTick drawableTick) =>
drumRollHitContainer.Add(new DrawableFlyingHit(drawableTick));
2020-04-27 11:01:31 +08:00
private void addExplosion(DrawableHitObject drawableObject, HitResult result, HitType type)
2020-04-27 11:23:53 +08:00
{
hitExplosionContainer.Add(explosionPools[result]
.Get(explosion => explosion.Apply(drawableObject)));
2020-04-27 11:23:53 +08:00
if (drawableObject.HitObject.Kiai)
kiaiExplosionContainer.Add(new KiaiHitExplosion(drawableObject, type));
}
2020-04-27 11:23:53 +08:00
2020-04-27 07:40:57 +08:00
private class ProxyContainer : LifetimeManagementContainer
2020-04-22 21:19:29 +08:00
{
public void Add(Drawable proxy) => AddInternal(proxy);
public override bool UpdateSubTreeMasking(Drawable source, RectangleF maskingBounds)
2020-04-27 07:40:57 +08:00
{
// DrawableHitObject disables masking.
// Hitobject content is proxied and unproxied based on hit status and the IsMaskedAway value could get stuck because of this.
return false;
2020-04-27 07:40:57 +08:00
}
}
2018-04-13 17:19:50 +08:00
}
}