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

93 lines
3.0 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.
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;
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
2020-01-24 10:54:48 +08:00
private class JudgementFlow : FillFlowContainer<HitErrorCircle>
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;
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;
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
{
2020-01-24 10:54:48 +08:00
Add(new HitErrorCircle(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
}
2020-01-24 10:54:48 +08:00
private 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
2020-01-24 10:54:48 +08:00
private readonly Circle circle;
2020-01-24 10:54:48 +08:00
public HitErrorCircle(Color4 colour, int size)
2019-12-21 19:30:41 +08:00
{
2019-12-21 21:08:28 +08:00
Size = new Vector2(size);
2020-01-24 10:54:48 +08:00
Child = circle = new Circle
2019-12-21 19:30:41 +08:00
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
2020-01-24 10:54:48 +08:00
Colour = colour
2019-12-21 19:30:41 +08:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-01-24 10:54:48 +08:00
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;
2020-01-24 10:54:48 +08:00
2019-12-22 08:30:17 +08:00
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
}
2019-12-21 18:41:50 +08:00
}
}
}