1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-28 16:52:57 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.1 KiB
C#
Raw Normal View History

2019-12-21 18:41:50 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-01-24 10:52:32 +08:00
using System.Collections.Generic;
2019-12-21 21:08:28 +08:00
using System.Linq;
2019-12-21 18:41:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
2019-12-21 18:41:50 +08:00
using osuTK;
2019-12-21 19:52:53 +08:00
using osuTK.Graphics;
2019-12-21 18:41:50 +08:00
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
public class ColourHitErrorMeter : HitErrorMeter
{
internal const int MAX_DISPLAYED_JUDGEMENTS = 20;
private const int animation_duration = 200;
private const int drawable_judgement_size = 8;
private const int spacing = 2;
2019-12-21 19:30:41 +08:00
2019-12-21 21:08:28 +08:00
private readonly JudgementFlow judgementsFlow;
2019-12-21 19:30:41 +08:00
public ColourHitErrorMeter()
2019-12-21 18:41:50 +08:00
{
2019-12-21 19:30:41 +08:00
AutoSizeAxes = Axes.Both;
2019-12-21 21:08:28 +08:00
InternalChild = judgementsFlow = new JudgementFlow();
}
protected override void OnNewJudgement(JudgementResult judgement)
{
if (!judgement.Type.IsScorable() || judgement.Type.IsBonus())
return;
judgementsFlow.Push(GetColourForHitResult(judgement.Type));
}
2019-12-21 21:08:28 +08:00
2021-09-20 22:22:36 +08:00
public override void Clear() => judgementsFlow.Clear();
2020-01-24 10:54:48 +08:00
private class JudgementFlow : FillFlowContainer<HitErrorCircle>
2019-12-21 21:08:28 +08:00
{
2020-01-24 10:52:32 +08:00
public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse();
2019-12-22 08:06:57 +08:00
2019-12-21 21:08:28 +08:00
public JudgementFlow()
{
AutoSizeAxes = Axes.X;
Height = MAX_DISPLAYED_JUDGEMENTS * (drawable_judgement_size + spacing) - spacing;
2019-12-22 08:06:57 +08:00
Spacing = new Vector2(0, spacing);
Direction = FillDirection.Vertical;
LayoutDuration = animation_duration;
LayoutEasing = Easing.OutQuint;
2019-12-21 21:08:28 +08:00
}
2019-12-22 08:30:17 +08:00
public void Push(Color4 colour)
2019-12-21 21:08:28 +08:00
{
Add(new HitErrorCircle(colour, drawable_judgement_size));
2019-12-21 21:08:28 +08:00
if (Children.Count > MAX_DISPLAYED_JUDGEMENTS)
2019-12-22 08:41:19 +08:00
Children.FirstOrDefault(c => !c.IsRemoved)?.Remove();
2019-12-21 21:08:28 +08:00
}
2019-12-21 19:30:41 +08:00
}
internal class HitErrorCircle : Container
2019-12-21 19:30:41 +08:00
{
2019-12-22 08:30:17 +08:00
public bool IsRemoved { get; private set; }
2019-12-21 21:08:28 +08:00
private readonly Circle circle;
public HitErrorCircle(Color4 colour, int size)
{
Size = new Vector2(size);
Child = circle = new Circle
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
}
protected override void LoadComplete()
{
base.LoadComplete();
circle.FadeInFromZero(animation_duration, Easing.OutQuint);
circle.MoveToY(-DrawSize.Y);
circle.MoveToY(0, animation_duration, Easing.OutQuint);
}
2019-12-22 08:30:17 +08:00
public void Remove()
{
IsRemoved = true;
2019-12-22 08:30:17 +08:00
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
}
2019-12-21 18:41:50 +08:00
}
}
}