1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00
osu-lazer/osu.Game/Screens/Play/HitErrorDisplay/BarHitErrorMeter.cs

178 lines
6.7 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 System;
2019-08-20 01:44:06 +08:00
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 osu.Game.Rulesets.Objects;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Colour;
using osu.Game.Graphics;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Screens.Play.HitErrorDisplay
{
2019-08-30 14:32:47 +08:00
public class BarHitErrorMeter : HitErrorMeter
2019-08-20 01:44:06 +08:00
{
private readonly bool rightAligned;
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 = 400;
2019-08-20 01:44:06 +08:00
private const int judgement_line_width = 8;
2019-08-20 01:44:06 +08:00
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 double maxHitWindow;
2019-08-20 01:44:06 +08:00
2019-08-30 14:51:36 +08:00
public BarHitErrorMeter(HitWindows hitWindows, bool rightAligned = false)
: base(hitWindows)
2019-08-20 01:44:06 +08:00
{
this.rightAligned = rightAligned;
maxHitWindow = Math.Max(Math.Max(HitWindows.Meh, HitWindows.Ok), HitWindows.Good);
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
{
2019-08-30 14:51:36 +08:00
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
2019-08-20 01:44:06 +08:00
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
{
2019-08-30 14:51:36 +08:00
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
2019-08-20 01:44:06 +08:00
Width = bar_width,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
new Container
{
2019-08-30 14:51:36 +08:00
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
2019-08-20 01:44:06 +08:00
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Child = arrow = new SpriteIcon
{
Anchor = Anchor.TopCentre,
2019-08-20 01:44:06 +08:00
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Y,
Y = 0.5f,
2019-08-30 14:51:36 +08:00
Icon = rightAligned ? FontAwesome.Solid.ChevronRight : FontAwesome.Solid.ChevronLeft,
2019-08-20 01:44:06 +08:00
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
{
createColoredPiece(ColourInfo.GradientVertical(colours.Yellow.Opacity(0), colours.Yellow), (maxHitWindow - HitWindows.Good) / (maxHitWindow * 2)),
createColoredPiece(colours.Green, (HitWindows.Good - HitWindows.Great) / (maxHitWindow * 2)),
createColoredPiece(colours.BlueLight, HitWindows.Great / maxHitWindow),
createColoredPiece(colours.Green, (HitWindows.Good - HitWindows.Great) / (maxHitWindow * 2)),
createColoredPiece(ColourInfo.GradientVertical(colours.Yellow, colours.Yellow.Opacity(0)), (maxHitWindow - HitWindows.Good) / (maxHitWindow * 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
{
createColoredPiece(ColourInfo.GradientVertical(colours.Green.Opacity(0), colours.Green), (HitWindows.Good - HitWindows.Great) / (maxHitWindow * 2)),
createColoredPiece(colours.BlueLight, HitWindows.Great / maxHitWindow),
createColoredPiece(ColourInfo.GradientVertical(colours.Green, colours.Green.Opacity(0)), (HitWindows.Good - HitWindows.Great) / (maxHitWindow * 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
};
private double floatingAverage;
public override void OnNewJudgement(JudgementResult judgement)
2019-08-20 01:44:06 +08:00
{
if (!judgement.IsHit)
2019-08-20 01:44:06 +08:00
return;
judgementsContainer.Add(new JudgementLine
{
Y = getRelativeJudgementPosition(judgement.TimeOffset),
Anchor = rightAligned ? Anchor.TopLeft : Anchor.TopRight,
Origin = rightAligned ? Anchor.TopLeft : Anchor.TopRight,
});
2019-08-20 01:44:06 +08:00
arrow.MoveToY(getRelativeJudgementPosition(floatingAverage = floatingAverage * 0.9 + judgement.TimeOffset * 0.1)
, arrow_move_duration, Easing.Out);
2019-08-20 01:44:06 +08:00
}
private float getRelativeJudgementPosition(double value) => (float)((value / maxHitWindow) + 1) / 2;
2019-08-20 01:44:06 +08:00
public class JudgementLine : CompositeDrawable
2019-08-20 01:44:06 +08:00
{
public JudgementLine()
{
RelativeSizeAxes = Axes.X;
RelativePositionAxes = Axes.Y;
Height = 2;
InternalChild = new CircularContainer
{
Masking = true,
RelativeSizeAxes = Axes.Both,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
}
};
}
2019-08-20 01:44:06 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
2019-08-20 01:44:06 +08:00
Width = 0;
this.ResizeWidthTo(1, 150, Easing.OutElasticHalf);
this.FadeTo(0.8f, 150).Then().FadeOut(judgement_fade_duration, Easing.OutQuint).Expire();
}
2019-08-20 01:44:06 +08:00
}
}
}