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

110 lines
3.8 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.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
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
{
2019-12-21 21:08:28 +08:00
private const int max_available_judgements = 20;
2019-12-21 19:30:41 +08:00
2019-12-21 21:08:28 +08:00
private readonly JudgementFlow judgementsFlow;
private readonly BindableList<(Color4 colour, JudgementResult result)> judgements = new BindableList<(Color4 colour, JudgementResult result)>();
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();
}
protected override void LoadComplete()
{
base.LoadComplete();
judgementsFlow.Judgements.BindTo(judgements);
2019-12-21 18:41:50 +08:00
}
public override void OnNewJudgement(JudgementResult judgement)
{
2019-12-21 21:08:28 +08:00
judgements.Add((GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)), judgement));
if (judgements.Count > max_available_judgements)
judgements.RemoveAt(0);
}
2019-12-22 08:06:57 +08:00
private class JudgementFlow : FillFlowContainer<DrawableResult>
2019-12-21 21:08:28 +08:00
{
private const int drawable_judgement_size = 8;
private const int spacing = 2;
private const int animation_duration = 200;
public readonly BindableList<(Color4 colour, JudgementResult result)> Judgements = new BindableList<(Color4 colour, JudgementResult result)>();
2019-12-22 08:06:57 +08:00
private int runningDepth;
2019-12-21 21:08:28 +08:00
public JudgementFlow()
{
AutoSizeAxes = Axes.X;
Height = max_available_judgements * (drawable_judgement_size + 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
}
protected override void LoadComplete()
{
base.LoadComplete();
Judgements.ItemsAdded += push;
Judgements.ItemsRemoved += pop;
}
private void push(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
{
var (colour, result) = judgements.Single();
var drawableJudgement = new DrawableResult(colour, result, drawable_judgement_size)
{
Alpha = 0,
};
2019-12-22 08:06:57 +08:00
Insert(runningDepth--, drawableJudgement);
2019-12-21 21:08:28 +08:00
drawableJudgement.FadeInFromZero(animation_duration, Easing.OutQuint);
}
private void pop(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
{
2019-12-22 08:06:57 +08:00
var (colour, result) = judgements.Single();
Children.FirstOrDefault(c => c.Result == result).FadeOut(animation_duration, Easing.OutQuint).Expire();
2019-12-21 21:08:28 +08:00
}
2019-12-21 19:30:41 +08:00
}
2019-12-21 21:08:28 +08:00
private class DrawableResult : CircularContainer
2019-12-21 19:30:41 +08:00
{
2019-12-21 21:08:28 +08:00
public JudgementResult Result { get; private set; }
public DrawableResult(Color4 colour, JudgementResult result, int size)
2019-12-21 19:30:41 +08:00
{
2019-12-21 21:08:28 +08:00
Result = result;
2019-12-21 19:30:41 +08:00
Masking = true;
2019-12-21 21:08:28 +08:00
Size = new Vector2(size);
2019-12-21 19:52:53 +08:00
Child = new Box
2019-12-21 19:30:41 +08:00
{
RelativeSizeAxes = Axes.Both,
2019-12-21 19:52:53 +08:00
Colour = colour
2019-12-21 19:30:41 +08:00
};
}
2019-12-21 18:41:50 +08:00
}
}
}