1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +08:00
osu-lazer/osu.Game/Screens/Play/HitErrorDisplay/BarHitErrorDisplay.cs

173 lines
6.9 KiB
C#
Raw Normal View History

2019-08-20 01:44:06 +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.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Judgements;
using osuTK.Graphics;
using osuTK;
using osu.Framework.Graphics.Sprites;
using System.Collections.Generic;
using osu.Game.Rulesets.Objects;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Colour;
using osu.Game.Graphics;
using osu.Framework.Extensions.Color4Extensions;
2019-08-21 15:13:59 +08:00
using System.Linq;
2019-08-20 01:44:06 +08:00
namespace osu.Game.Screens.Play.HitErrorDisplay
{
public class BarHitErrorDisplay : HitErrorDisplay
2019-08-20 01:44:06 +08:00
{
2019-08-20 13:51:41 +08:00
/// <summary>
/// The amount of <see cref="JudgementResult"/> which will be stored to calculate arrow position.
/// </summary>
2019-08-20 01:44:06 +08:00
private const int stored_judgements_amount = 5;
2019-08-20 14:03:31 +08:00
2019-08-20 13:51:41 +08:00
private const int judgement_fade_duration = 10000;
private const int arrow_move_duration = 500;
2019-08-20 01:44:06 +08:00
private const int judgement_line_width = 8;
private const int bar_height = 200;
2019-08-20 13:51:41 +08:00
private const int bar_width = 3;
2019-08-20 01:44:06 +08:00
private const int spacing = 3;
private readonly SpriteIcon arrow;
2019-08-20 13:00:09 +08:00
private readonly FillFlowContainer<Box> bar;
2019-08-20 01:44:06 +08:00
private readonly Container judgementsContainer;
private readonly List<double> judgementOffsets = new List<double>();
private readonly double maxHitWindows;
2019-08-20 01:44:06 +08:00
public BarHitErrorDisplay(HitWindows hitWindows, bool reversed = false)
: base(hitWindows)
2019-08-20 01:44:06 +08:00
{
maxHitWindows = HitWindows.Meh == 0 ? HitWindows.Good : HitWindows.Meh;
2019-08-20 01:44:06 +08:00
AutoSizeAxes = Axes.Both;
2019-08-20 01:44:06 +08:00
AddInternal(new FillFlowContainer
{
AutoSizeAxes = Axes.X,
Height = bar_height,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(spacing, 0),
Children = new Drawable[]
{
judgementsContainer = new Container
{
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Width = judgement_line_width,
RelativeSizeAxes = Axes.Y,
},
2019-08-20 13:00:09 +08:00
bar = new FillFlowContainer<Box>
2019-08-20 01:44:06 +08:00
{
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Width = bar_width,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
new Container
{
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Child = arrow = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Y,
Icon = reversed ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
Size = new Vector2(8),
}
},
}
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (HitWindows.Meh != 0)
2019-08-20 13:00:09 +08:00
{
bar.AddRange(new[]
2019-08-20 01:44:06 +08:00
{
2019-08-20 13:00:09 +08:00
createColoredPiece(ColourInfo.GradientVertical(colours.Yellow.Opacity(0), colours.Yellow),
(maxHitWindows - HitWindows.Good) / (maxHitWindows * 2)),
createColoredPiece(colours.Green, (HitWindows.Good - HitWindows.Great) / (maxHitWindows * 2)),
createColoredPiece(colours.BlueLight, HitWindows.Great / maxHitWindows),
createColoredPiece(colours.Green, (HitWindows.Good - HitWindows.Great) / (maxHitWindows * 2)),
createColoredPiece(ColourInfo.GradientVertical(colours.Yellow, colours.Yellow.Opacity(0)),
(maxHitWindows - HitWindows.Good) / (maxHitWindows * 2))
});
2019-08-20 13:00:09 +08:00
}
else
{
2019-08-20 13:00:09 +08:00
bar.AddRange(new[]
2019-08-20 01:44:06 +08:00
{
2019-08-20 13:00:09 +08:00
createColoredPiece(ColourInfo.GradientVertical(colours.Green.Opacity(0), colours.Green),
(HitWindows.Good - HitWindows.Great) / (maxHitWindows * 2)),
createColoredPiece(colours.BlueLight, HitWindows.Great / maxHitWindows),
createColoredPiece(ColourInfo.GradientVertical(colours.Green, colours.Green.Opacity(0)),
(HitWindows.Good - HitWindows.Great) / (maxHitWindows * 2)),
});
}
2019-08-20 01:44:06 +08:00
}
2019-08-20 13:00:09 +08:00
private Box createColoredPiece(ColourInfo colour, double height) => new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colour,
Height = (float)height
};
2019-08-20 01:44:06 +08:00
public override void OnNewJudgement(JudgementResult newJudgement)
{
if (!newJudgement.IsHit)
return;
var judgementLine = CreateJudgementLine(newJudgement);
judgementsContainer.Add(judgementLine);
2019-08-20 13:51:41 +08:00
judgementLine.FadeOut(judgement_fade_duration, Easing.OutQuint).Expire();
2019-08-20 01:44:06 +08:00
arrow.MoveToY(calculateArrowPosition(newJudgement), arrow_move_duration, Easing.OutQuint);
}
protected virtual Container CreateJudgementLine(JudgementResult judgement) => new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
RelativeSizeAxes = Axes.X,
Height = 2,
RelativePositionAxes = Axes.Y,
Y = getRelativeJudgementPosition(judgement.TimeOffset),
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
}
};
private float getRelativeJudgementPosition(double value) => (float)(value / maxHitWindows);
2019-08-20 01:44:06 +08:00
private float calculateArrowPosition(JudgementResult newJudgement)
{
2019-08-21 15:13:59 +08:00
judgementOffsets.Add(newJudgement.TimeOffset);
2019-08-21 15:13:59 +08:00
if (judgementOffsets.Count < stored_judgements_amount)
return getRelativeJudgementPosition(judgementOffsets.Average());
2019-08-21 15:13:59 +08:00
double sum = 0;
2019-08-20 01:44:06 +08:00
2019-08-21 15:13:59 +08:00
for (int i = judgementOffsets.Count - stored_judgements_amount; i < judgementOffsets.Count; i++)
sum += judgementOffsets[i];
2019-08-20 01:44:06 +08:00
return getRelativeJudgementPosition(sum / stored_judgements_amount);
2019-08-20 01:44:06 +08:00
}
}
}