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

239 lines
9.4 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
using System.Linq;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps.ControlPoints;
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.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;
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
{
private readonly ControlPointInfo controlPoints;
2018-04-13 17:19:50 +08:00
/// <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 = 178;
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
private ProxyContainer topLevelHitContainer;
private ProxyContainer barlineContainer;
private Container rightArea;
private Container leftArea;
2018-04-13 17:19:50 +08:00
private Container hitTargetOffsetContent;
2018-04-13 17:19:50 +08:00
public TaikoPlayfield(ControlPointInfo controlPoints)
{
this.controlPoints = controlPoints;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2018-04-13 17:19:50 +08:00
{
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()),
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 = "Masked 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
}
}
},
hitTargetOffsetContent = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
barlineContainer = new ProxyContainer
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
Name = "Hit objects",
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
HitObjectContainer,
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,
},
}
},
}
},
leftArea = new Container
{
Name = "Left overlay",
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
BorderColour = colours.Gray0,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.PlayfieldBackgroundLeft), _ => new PlayfieldBackgroundLeft()),
new InputDrum(controlPoints)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
}
},
mascot = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.Mascot), _ => Empty())
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.TopLeft,
2020-05-13 02:26:11 +08:00
RelativePositionAxes = Axes.Y,
RelativeSizeAxes = Axes.None,
2020-05-13 02:26:11 +08:00
Y = 0.2f
},
topLevelHitContainer = new ProxyContainer
{
Name = "Top level hit objects",
RelativeSizeAxes = Axes.Both,
2020-04-22 21:19:29 +08:00
},
drumRollHitContainer.CreateProxy(),
};
2018-04-13 17:19:50 +08:00
}
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 = leftArea.DrawWidth };
hitTargetOffsetContent.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
}
public override void Add(DrawableHitObject h)
{
h.OnNewResult += OnNewResult;
2018-04-13 17:19:50 +08:00
base.Add(h);
switch (h)
{
case DrawableBarLine barline:
barlineContainer.Add(barline.CreateProxy());
break;
2019-04-01 11:44:46 +08:00
case DrawableTaikoHitObject taikoObject:
topLevelHitContainer.Add(taikoObject.CreateProxiedContent());
break;
}
2018-04-13 17:19:50 +08:00
}
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
{
2018-08-03 15:56:46 +08:00
case TaikoStrongJudgement _:
2018-08-03 15:46:03 +08:00
if (result.IsHit)
hitExplosionContainer.Children.FirstOrDefault(e => e.JudgedObject == ((DrawableStrongNestedHit)judgedObject).MainObject)?.VisualiseSecondHit();
2018-08-03 15:46:03 +08:00
break;
2019-04-01 11:44:46 +08:00
2020-04-27 11:01:31 +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:
judgementContainer.Add(new DrawableTaikoJudgement(result, judgedObject)
{
Anchor = result.IsHit ? Anchor.TopLeft : Anchor.CentreLeft,
Origin = result.IsHit ? Anchor.BottomCentre : Anchor.Centre,
RelativePositionAxes = Axes.X,
X = result.IsHit ? judgedObject.Position.X : 0,
});
2018-04-13 17:19:50 +08:00
2018-08-03 15:46:03 +08:00
if (!result.IsHit)
break;
2018-04-13 17:19:50 +08:00
var type = (judgedObject.HitObject as Hit)?.Type ?? HitType.Centre;
addExplosion(judgedObject, 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
2020-04-27 11:23:53 +08:00
private void addExplosion(DrawableHitObject drawableObject, HitType type)
{
hitExplosionContainer.Add(new HitExplosion(drawableObject));
2020-04-27 11:23:53 +08:00
if (drawableObject.HitObject.Kiai)
kiaiExplosionContainer.Add(new KiaiHitExplosion(drawableObject, type));
}
2020-04-27 07:40:57 +08:00
private class ProxyContainer : LifetimeManagementContainer
2020-04-22 21:19:29 +08:00
{
2020-04-27 07:40:57 +08:00
public new MarginPadding Padding
{
set => base.Padding = value;
}
2020-04-22 21:19:29 +08:00
2020-04-27 07:40:57 +08:00
public void Add(Drawable proxy) => AddInternal(proxy);
}
2018-04-13 17:19:50 +08:00
}
}