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.
|
|
|
|
|
|
2020-03-08 22:51:57 +08:00
|
|
|
|
using System;
|
2019-08-30 17:35:06 +08:00
|
|
|
|
using System.Linq;
|
2019-08-30 17:46:42 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2019-08-20 01:44:06 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-08-30 17:46:42 +08:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2019-08-20 01:44:06 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
2019-08-30 17:46:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2019-08-30 17:35:06 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-08-30 17:46:42 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2019-08-30 17:46:42 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2021-05-07 18:13:38 +08:00
|
|
|
|
public class BarHitErrorMeter : HitErrorMeter
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2019-08-30 15:40:39 +08:00
|
|
|
|
private const int arrow_move_duration = 400;
|
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
private const int judgement_line_width = 6;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-20 01:44:06 +08:00
|
|
|
|
private const int bar_height = 200;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
private const int bar_width = 2;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
private const int spacing = 2;
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2019-08-30 17:50:38 +08:00
|
|
|
|
private const float chevron_size = 8;
|
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
private SpriteIcon arrow;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-30 17:35:06 +08:00
|
|
|
|
private Container colourBarsEarly;
|
|
|
|
|
private Container colourBarsLate;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
private Container judgementsContainer;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-30 17:35:06 +08:00
|
|
|
|
private double maxHitWindow;
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2021-05-17 18:46:50 +08:00
|
|
|
|
public BarHitErrorMeter()
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2019-08-20 03:45:27 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2019-08-30 16:06:23 +08:00
|
|
|
|
}
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
InternalChild = new FillFlowContainer
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Height = bar_height,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(spacing, 0),
|
2019-08-30 16:06:23 +08:00
|
|
|
|
Margin = new MarginPadding(2),
|
2019-08-20 01:44:06 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-05-18 13:50:10 +08:00
|
|
|
|
new Container
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Width = chevron_size,
|
2019-08-20 01:44:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Child = arrow = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Y = 0.5f,
|
|
|
|
|
Icon = FontAwesome.Solid.ChevronRight,
|
|
|
|
|
Size = new Vector2(chevron_size),
|
|
|
|
|
}
|
2019-08-20 01:44:06 +08:00
|
|
|
|
},
|
2019-08-30 17:35:06 +08:00
|
|
|
|
colourBars = new Container
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
|
|
|
|
Width = bar_width,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2019-08-30 17:35:06 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
colourBarsEarly = new Container
|
|
|
|
|
{
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2021-05-20 00:53:24 +08:00
|
|
|
|
Origin = Anchor.TopRight,
|
2019-08-30 17:35:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0.5f,
|
|
|
|
|
Scale = new Vector2(1, -1),
|
|
|
|
|
},
|
|
|
|
|
colourBarsLate = new Container
|
|
|
|
|
{
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2021-05-20 00:53:24 +08:00
|
|
|
|
Origin = Anchor.TopRight,
|
2019-08-30 17:35:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0.5f,
|
|
|
|
|
},
|
2019-08-30 18:14:07 +08:00
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Y = -10,
|
|
|
|
|
Size = new Vector2(10),
|
|
|
|
|
Icon = FontAwesome.Solid.ShippingFast,
|
2019-08-30 18:34:28 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
2020-10-15 18:11:40 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
// undo any layout rotation to display the icon the correct orientation
|
|
|
|
|
Rotation = -Rotation,
|
2019-08-30 18:14:07 +08:00
|
|
|
|
},
|
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Y = 10,
|
|
|
|
|
Size = new Vector2(10),
|
|
|
|
|
Icon = FontAwesome.Solid.Bicycle,
|
2019-08-30 18:34:28 +08:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2020-10-15 18:11:40 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
// undo any layout rotation to display the icon the correct orientation
|
|
|
|
|
Rotation = -Rotation,
|
2019-08-30 18:14:07 +08:00
|
|
|
|
}
|
2019-08-30 17:35:06 +08:00
|
|
|
|
}
|
2019-08-20 01:44:06 +08:00
|
|
|
|
},
|
2021-05-18 13:50:10 +08:00
|
|
|
|
judgementsContainer = new Container
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Width = judgement_line_width,
|
2019-08-20 01:44:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
}
|
2019-08-30 16:06:23 +08:00
|
|
|
|
};
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2019-08-30 17:35:06 +08:00
|
|
|
|
createColourBars(colours);
|
2019-08-20 01:44:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 16:06:23 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2019-08-30 17:35:06 +08:00
|
|
|
|
colourBars.Height = 0;
|
|
|
|
|
colourBars.ResizeHeightTo(1, 800, Easing.OutQuint);
|
2019-08-30 16:06:23 +08:00
|
|
|
|
|
2019-08-30 17:50:38 +08:00
|
|
|
|
arrow.Alpha = 0;
|
2019-08-30 17:35:06 +08:00
|
|
|
|
arrow.Delay(200).FadeInFromZero(600);
|
2019-08-30 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 17:35:06 +08:00
|
|
|
|
private void createColourBars(OsuColour colours)
|
2019-08-20 13:00:09 +08:00
|
|
|
|
{
|
2019-09-06 14:24:00 +08:00
|
|
|
|
var windows = HitWindows.GetAllAvailableWindows().ToArray();
|
2019-08-30 17:35:06 +08:00
|
|
|
|
|
2021-05-17 18:46:50 +08:00
|
|
|
|
// max to avoid div-by-zero.
|
|
|
|
|
maxHitWindow = Math.Max(1, windows.First().length);
|
2019-08-30 17:35:06 +08:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < windows.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var (result, length) = windows[i];
|
|
|
|
|
|
2021-05-17 18:46:50 +08:00
|
|
|
|
var hitWindow = (float)(length / maxHitWindow);
|
|
|
|
|
|
|
|
|
|
colourBarsEarly.Add(createColourBar(result, hitWindow, i == 0));
|
|
|
|
|
colourBarsLate.Add(createColourBar(result, hitWindow, i == 0));
|
2019-08-30 17:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// a little nub to mark the centre point.
|
|
|
|
|
var centre = createColourBar(windows.Last().result, 0.01f);
|
2021-05-18 13:50:10 +08:00
|
|
|
|
centre.Anchor = centre.Origin = Anchor.CentreLeft;
|
2019-08-30 18:14:07 +08:00
|
|
|
|
centre.Width = 2.5f;
|
2019-08-30 17:35:06 +08:00
|
|
|
|
colourBars.Add(centre);
|
|
|
|
|
|
|
|
|
|
Drawable createColourBar(HitResult result, float height, bool first = false)
|
|
|
|
|
{
|
2019-12-21 19:52:53 +08:00
|
|
|
|
var colour = GetColourForHitResult(result);
|
2019-08-30 17:35:06 +08:00
|
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
|
{
|
|
|
|
|
// the first bar needs gradient rendering.
|
|
|
|
|
const float gradient_start = 0.8f;
|
|
|
|
|
|
|
|
|
|
return new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-12-21 19:52:53 +08:00
|
|
|
|
Colour = colour,
|
2019-08-30 17:35:06 +08:00
|
|
|
|
Height = height * gradient_start
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
|
Colour = ColourInfo.GradientVertical(colour, colour.Opacity(0)),
|
|
|
|
|
Y = gradient_start,
|
|
|
|
|
Height = height * (1 - gradient_start)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colour,
|
|
|
|
|
Height = height
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-20 13:00:09 +08:00
|
|
|
|
|
2019-08-30 15:40:39 +08:00
|
|
|
|
private double floatingAverage;
|
2019-08-30 17:35:06 +08:00
|
|
|
|
private Container colourBars;
|
2019-08-30 15:40:39 +08:00
|
|
|
|
|
2020-02-23 02:39:12 +08:00
|
|
|
|
private const int max_concurrent_judgements = 50;
|
|
|
|
|
|
2021-05-10 14:19:27 +08:00
|
|
|
|
protected override void OnNewJudgement(JudgementResult judgement)
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2021-06-07 18:31:24 +08:00
|
|
|
|
if (!judgement.IsHit || judgement.HitObject.HitWindows?.WindowFor(HitResult.Miss) == 0)
|
2019-08-20 01:44:06 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-06-08 22:09:18 +08:00
|
|
|
|
if (!judgement.Type.IsScorable() || judgement.Type.IsBonus())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-02-23 04:28:59 +08:00
|
|
|
|
if (judgementsContainer.Count > max_concurrent_judgements)
|
2020-02-23 02:53:51 +08:00
|
|
|
|
{
|
|
|
|
|
const double quick_fade_time = 100;
|
|
|
|
|
|
2020-02-23 04:28:59 +08:00
|
|
|
|
// check with a bit of lenience to avoid precision error in comparison.
|
|
|
|
|
var old = judgementsContainer.FirstOrDefault(j => j.LifetimeEnd > Clock.CurrentTime + quick_fade_time * 1.1);
|
2020-02-23 02:53:51 +08:00
|
|
|
|
|
|
|
|
|
if (old != null)
|
|
|
|
|
{
|
|
|
|
|
old.ClearTransforms();
|
|
|
|
|
old.FadeOut(quick_fade_time).Expire();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-23 02:39:12 +08:00
|
|
|
|
|
2019-08-30 15:40:39 +08:00
|
|
|
|
judgementsContainer.Add(new JudgementLine
|
|
|
|
|
{
|
|
|
|
|
Y = getRelativeJudgementPosition(judgement.TimeOffset),
|
2021-05-18 13:50:10 +08:00
|
|
|
|
Origin = Anchor.CentreLeft,
|
2019-08-30 15:40:39 +08:00
|
|
|
|
});
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2019-08-30 17:35:06 +08:00
|
|
|
|
arrow.MoveToY(
|
|
|
|
|
getRelativeJudgementPosition(floatingAverage = floatingAverage * 0.9 + judgement.TimeOffset * 0.1)
|
2019-08-30 15:40:39 +08:00
|
|
|
|
, arrow_move_duration, Easing.Out);
|
2019-08-20 01:44:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 22:51:57 +08:00
|
|
|
|
private float getRelativeJudgementPosition(double value) => Math.Clamp((float)((value / maxHitWindow) + 1) / 2, 0, 1);
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2021-06-07 18:25:48 +08:00
|
|
|
|
internal class JudgementLine : CompositeDrawable
|
2019-08-20 01:44:06 +08:00
|
|
|
|
{
|
2020-02-23 02:36:15 +08:00
|
|
|
|
private const int judgement_fade_duration = 5000;
|
2019-08-30 17:50:38 +08:00
|
|
|
|
|
2019-08-30 15:40:39 +08:00
|
|
|
|
public JudgementLine()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
RelativePositionAxes = Axes.Y;
|
2019-08-30 17:50:38 +08:00
|
|
|
|
Height = 3;
|
2019-08-21 14:40:15 +08:00
|
|
|
|
|
2019-08-30 15:40:39 +08:00
|
|
|
|
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
|
|
|
|
|
2019-08-30 15:40:39 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-08-20 01:44:06 +08:00
|
|
|
|
|
2019-08-30 15:40:39 +08:00
|
|
|
|
Width = 0;
|
2019-08-30 17:35:06 +08:00
|
|
|
|
|
2019-08-30 17:50:38 +08:00
|
|
|
|
this.ResizeWidthTo(1, 200, Easing.OutElasticHalf);
|
2020-02-23 02:36:15 +08:00
|
|
|
|
this.FadeTo(0.8f, 150).Then().FadeOut(judgement_fade_duration).Expire();
|
2019-08-30 15:40:39 +08:00
|
|
|
|
}
|
2019-08-20 01:44:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|