2019-08-11 19:57:21 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2019-08-11 20:53:15 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-08-11 19:57:21 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-08-11 20:53:15 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-08-11 19:57:21 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2019-08-11 20:53:15 +08:00
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK;
|
2019-08-11 21:38:03 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using System.Collections.Generic;
|
2019-08-11 23:04:54 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-08-11 23:30:03 +08:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2019-08-11 19:57:21 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
2019-08-11 23:11:49 +08:00
|
|
|
|
public class HitErrorDisplay : Container
|
2019-08-11 19:57:21 +08:00
|
|
|
|
{
|
2019-08-11 23:30:03 +08:00
|
|
|
|
private const int bar_width = 4;
|
2019-08-11 20:53:15 +08:00
|
|
|
|
private const int bar_height = 250;
|
|
|
|
|
private const int spacing = 3;
|
|
|
|
|
|
2019-08-11 23:04:54 +08:00
|
|
|
|
public HitWindows HitWindows { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private Bindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
|
2019-08-11 20:53:15 +08:00
|
|
|
|
private readonly bool mirrored;
|
2019-08-11 21:38:03 +08:00
|
|
|
|
private readonly SpriteIcon arrow;
|
|
|
|
|
private readonly List<double> judgementOffsets = new List<double>();
|
2019-08-11 20:53:15 +08:00
|
|
|
|
|
2019-08-11 23:11:49 +08:00
|
|
|
|
public HitErrorDisplay(bool mirrored = false)
|
2019-08-11 19:57:21 +08:00
|
|
|
|
{
|
2019-08-11 20:53:15 +08:00
|
|
|
|
this.mirrored = mirrored;
|
|
|
|
|
|
|
|
|
|
Size = new Vector2(bar_width, bar_height);
|
2019-08-11 21:38:03 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
2019-08-11 20:53:15 +08:00
|
|
|
|
{
|
2019-08-11 23:30:03 +08:00
|
|
|
|
new FillFlowContainer
|
2019-08-11 21:38:03 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-08-11 23:30:03 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0), Color4.Orange),
|
|
|
|
|
Height = 0.3f
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Green,
|
|
|
|
|
Height = 0.15f
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Blue,
|
|
|
|
|
Height = 0.1f
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Green,
|
|
|
|
|
Height = 0.15f
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = ColourInfo.GradientVertical(Color4.Orange, Color4.Black.Opacity(0)),
|
|
|
|
|
Height = 0.3f
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-11 21:38:03 +08:00
|
|
|
|
},
|
|
|
|
|
arrow = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = mirrored ? Anchor.CentreLeft : Anchor.CentreRight,
|
|
|
|
|
Origin = mirrored ? Anchor.CentreRight : Anchor.CentreLeft,
|
|
|
|
|
X = mirrored ? -spacing : spacing,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Icon = mirrored ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
|
|
|
|
|
Size = new Vector2(10),
|
|
|
|
|
}
|
2019-08-11 20:53:15 +08:00
|
|
|
|
};
|
2019-08-11 19:57:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-11 23:04:54 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
HitWindows.SetDifficulty(beatmap.Value.BeatmapInfo.BaseDifficulty.OverallDifficulty);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-11 19:57:21 +08:00
|
|
|
|
public void OnNewJudgement(JudgementResult judgement)
|
|
|
|
|
{
|
2019-08-12 00:04:56 +08:00
|
|
|
|
if (!judgement.IsHit)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-08-11 20:53:15 +08:00
|
|
|
|
Container judgementLine;
|
|
|
|
|
|
2019-08-11 21:38:03 +08:00
|
|
|
|
Add(judgementLine = CreateJudgementLine(judgement));
|
2019-08-11 20:53:15 +08:00
|
|
|
|
|
2019-08-12 00:09:50 +08:00
|
|
|
|
judgementLine.FadeOut(10000, Easing.OutQuint);
|
2019-08-11 20:53:15 +08:00
|
|
|
|
judgementLine.Expire();
|
2019-08-11 21:38:03 +08:00
|
|
|
|
|
2019-08-11 23:04:54 +08:00
|
|
|
|
arrow.MoveToY(getRelativeJudgementPosition(calculateArrowPosition(judgement)), 500, Easing.OutQuint);
|
2019-08-11 19:57:21 +08:00
|
|
|
|
}
|
2019-08-11 20:53:15 +08:00
|
|
|
|
|
2019-08-11 21:38:03 +08:00
|
|
|
|
protected virtual Container CreateJudgementLine(JudgementResult judgement) => new CircularContainer
|
2019-08-11 20:53:15 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = mirrored ? Anchor.CentreRight : Anchor.CentreLeft,
|
|
|
|
|
Origin = mirrored ? Anchor.CentreLeft : Anchor.CentreRight,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Size = new Vector2(10, 2),
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
2019-08-11 23:04:54 +08:00
|
|
|
|
Y = getRelativeJudgementPosition(judgement.TimeOffset),
|
2019-08-11 20:53:15 +08:00
|
|
|
|
X = mirrored ? spacing : -spacing,
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-08-11 21:38:03 +08:00
|
|
|
|
|
2019-08-11 23:04:54 +08:00
|
|
|
|
private float getRelativeJudgementPosition(double value) => (float)(value / HitWindows.Miss);
|
|
|
|
|
|
|
|
|
|
private double calculateArrowPosition(JudgementResult judgement)
|
2019-08-11 21:38:03 +08:00
|
|
|
|
{
|
|
|
|
|
if (judgementOffsets.Count > 5)
|
|
|
|
|
judgementOffsets.RemoveAt(0);
|
|
|
|
|
|
|
|
|
|
judgementOffsets.Add(judgement.TimeOffset);
|
|
|
|
|
|
|
|
|
|
double offsets = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var offset in judgementOffsets)
|
|
|
|
|
offsets += offset;
|
|
|
|
|
|
2019-08-11 23:04:54 +08:00
|
|
|
|
return offsets / judgementOffsets.Count;
|
2019-08-11 21:38:03 +08:00
|
|
|
|
}
|
2019-08-11 19:57:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|