mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Improve animations
This commit is contained in:
parent
b61aa660c6
commit
14a77a8f16
@ -1,6 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
@ -13,35 +17,86 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
{
|
{
|
||||||
public class ColourHitErrorMeter : HitErrorMeter
|
public class ColourHitErrorMeter : HitErrorMeter
|
||||||
{
|
{
|
||||||
private const int bar_height = 200;
|
private const int max_available_judgements = 20;
|
||||||
|
|
||||||
private readonly FillFlowContainer judgementsFlow;
|
private readonly JudgementFlow judgementsFlow;
|
||||||
|
private readonly BindableList<(Color4 colour, JudgementResult result)> judgements = new BindableList<(Color4 colour, JudgementResult result)>();
|
||||||
|
|
||||||
public ColourHitErrorMeter(HitWindows hitWindows)
|
public ColourHitErrorMeter(HitWindows hitWindows)
|
||||||
: base(hitWindows)
|
: base(hitWindows)
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
InternalChild = judgementsFlow = new FillFlowContainer
|
InternalChild = judgementsFlow = new JudgementFlow();
|
||||||
{
|
}
|
||||||
AutoSizeAxes = Axes.X,
|
|
||||||
Height = bar_height,
|
protected override void LoadComplete()
|
||||||
Direction = FillDirection.Vertical,
|
{
|
||||||
Spacing = new Vector2(0, 2),
|
base.LoadComplete();
|
||||||
Masking = true,
|
judgementsFlow.Judgements.BindTo(judgements);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnNewJudgement(JudgementResult judgement)
|
public override void OnNewJudgement(JudgementResult judgement)
|
||||||
{
|
{
|
||||||
judgementsFlow.Add(new DrawableJudgement(GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset))));
|
judgements.Add((GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)), judgement));
|
||||||
|
|
||||||
|
if (judgements.Count > max_available_judgements)
|
||||||
|
judgements.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DrawableJudgement : CircularContainer
|
private class JudgementFlow : Container<DrawableResult>
|
||||||
{
|
{
|
||||||
public DrawableJudgement(Color4 colour)
|
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)>();
|
||||||
|
|
||||||
|
public JudgementFlow()
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.X;
|
||||||
|
Height = max_available_judgements * (drawable_judgement_size + spacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Judgements.ItemsAdded += push;
|
||||||
|
Judgements.ItemsRemoved += pop;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void push(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
|
||||||
|
{
|
||||||
|
Children.ForEach(c => c.FinishTransforms());
|
||||||
|
|
||||||
|
var (colour, result) = judgements.Single();
|
||||||
|
var drawableJudgement = new DrawableResult(colour, result, drawable_judgement_size)
|
||||||
|
{
|
||||||
|
Alpha = 0,
|
||||||
|
Y = -(drawable_judgement_size + spacing)
|
||||||
|
};
|
||||||
|
|
||||||
|
Add(drawableJudgement);
|
||||||
|
drawableJudgement.FadeInFromZero(animation_duration, Easing.OutQuint);
|
||||||
|
|
||||||
|
Children.ForEach(c => c.MoveToOffset(new Vector2(0, drawable_judgement_size + spacing), animation_duration, Easing.OutQuint));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pop(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
|
||||||
|
{
|
||||||
|
Children.FirstOrDefault(c => c.Result == judgements.Single().result).FadeOut(animation_duration, Easing.OutQuint).Expire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DrawableResult : CircularContainer
|
||||||
|
{
|
||||||
|
public JudgementResult Result { get; private set; }
|
||||||
|
|
||||||
|
public DrawableResult(Color4 colour, JudgementResult result, int size)
|
||||||
|
{
|
||||||
|
Result = result;
|
||||||
|
|
||||||
Masking = true;
|
Masking = true;
|
||||||
Size = new Vector2(8);
|
Size = new Vector2(size);
|
||||||
Child = new Box
|
Child = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Loading…
Reference in New Issue
Block a user