1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 05:27:26 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs

95 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.
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;
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
{
private const int animation_duration = 200;
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
2019-12-21 18:41:50 +08:00
public ColourHitErrorMeter(HitWindows hitWindows)
: base(hitWindows)
{
2019-12-21 19:30:41 +08:00
AutoSizeAxes = Axes.Both;
2019-12-21 21:08:28 +08:00
InternalChild = judgementsFlow = new JudgementFlow();
}
2019-12-22 08:30:17 +08:00
public override void OnNewJudgement(JudgementResult judgement) => judgementsFlow.Push(GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)));
2019-12-21 21:08:28 +08:00
2019-12-22 08:06:57 +08:00
private class JudgementFlow : FillFlowContainer<DrawableResult>
2019-12-21 21:08:28 +08:00
{
2019-12-22 08:30:17 +08:00
private const int max_available_judgements = 20;
2019-12-21 21:08:28 +08:00
private const int drawable_judgement_size = 8;
private const int spacing = 2;
2019-12-22 08:06:57 +08:00
private int runningDepth;
2019-12-21 21:08:28 +08:00
public JudgementFlow()
{
AutoSizeAxes = Axes.X;
2019-12-22 08:30:17 +08:00
Height = max_available_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
{
2019-12-22 08:30:17 +08:00
Insert(runningDepth--, new DrawableResult(colour, drawable_judgement_size));
2019-12-21 21:08:28 +08:00
2019-12-22 08:30:17 +08:00
if (Children.Count > max_available_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
}
private class DrawableResult : 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 CircularContainer content;
2019-12-22 08:30:17 +08:00
public DrawableResult(Color4 colour, int size)
2019-12-21 19:30:41 +08:00
{
2019-12-21 21:08:28 +08:00
Size = new Vector2(size);
Child = content = new CircularContainer
2019-12-21 19:30:41 +08:00
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Alpha = 0,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colour
},
2019-12-21 19:30:41 +08:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
content.FadeInFromZero(animation_duration, Easing.OutQuint);
content.MoveToY(-DrawSize.Y);
content.MoveToY(0, animation_duration, Easing.OutQuint);
}
2019-12-22 08:30:17 +08:00
public void Remove()
{
IsRemoved = true;
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
}
2019-12-21 18:41:50 +08:00
}
}
}