mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 22:34:09 +08:00
Refactoor to avoid bindable usage
This commit is contained in:
parent
eb75c6c70f
commit
aded12af9e
@ -1,9 +1,7 @@
|
|||||||
// 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 System.Linq;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
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;
|
||||||
@ -16,11 +14,9 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
{
|
{
|
||||||
public class ColourHitErrorMeter : HitErrorMeter
|
public class ColourHitErrorMeter : HitErrorMeter
|
||||||
{
|
{
|
||||||
private const int max_available_judgements = 20;
|
|
||||||
private const int animation_duration = 200;
|
private const int animation_duration = 200;
|
||||||
|
|
||||||
private readonly JudgementFlow 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)
|
||||||
@ -29,69 +25,43 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
InternalChild = judgementsFlow = new JudgementFlow();
|
InternalChild = judgementsFlow = new JudgementFlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
public override void OnNewJudgement(JudgementResult judgement) => judgementsFlow.Push(GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)));
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
judgementsFlow.Judgements.BindTo(judgements);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnNewJudgement(JudgementResult judgement)
|
|
||||||
{
|
|
||||||
judgements.Add((GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)), judgement));
|
|
||||||
|
|
||||||
if (judgements.Count > max_available_judgements)
|
|
||||||
judgements.RemoveAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JudgementFlow : FillFlowContainer<DrawableResult>
|
private class JudgementFlow : FillFlowContainer<DrawableResult>
|
||||||
{
|
{
|
||||||
|
private const int max_available_judgements = 20;
|
||||||
private const int drawable_judgement_size = 8;
|
private const int drawable_judgement_size = 8;
|
||||||
private const int spacing = 2;
|
private const int spacing = 2;
|
||||||
|
|
||||||
public readonly BindableList<(Color4 colour, JudgementResult result)> Judgements = new BindableList<(Color4 colour, JudgementResult result)>();
|
|
||||||
|
|
||||||
private int runningDepth;
|
private int runningDepth;
|
||||||
|
|
||||||
public JudgementFlow()
|
public JudgementFlow()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.X;
|
AutoSizeAxes = Axes.X;
|
||||||
Height = max_available_judgements * (drawable_judgement_size + spacing);
|
Height = max_available_judgements * (drawable_judgement_size + spacing) - spacing;
|
||||||
Spacing = new Vector2(0, spacing);
|
Spacing = new Vector2(0, spacing);
|
||||||
Direction = FillDirection.Vertical;
|
Direction = FillDirection.Vertical;
|
||||||
LayoutDuration = animation_duration;
|
LayoutDuration = animation_duration;
|
||||||
LayoutEasing = Easing.OutQuint;
|
LayoutEasing = Easing.OutQuint;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
public void Push(Color4 colour)
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
Insert(runningDepth--, new DrawableResult(colour, drawable_judgement_size));
|
||||||
Judgements.ItemsAdded += push;
|
|
||||||
Judgements.ItemsRemoved += pop;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void push(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
|
if (Children.Count > max_available_judgements)
|
||||||
{
|
Children.FirstOrDefault(c => !c.IsRemoved).Remove();
|
||||||
var (colour, result) = judgements.Single();
|
|
||||||
Insert(runningDepth--, new DrawableResult(colour, result, drawable_judgement_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pop(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
|
|
||||||
{
|
|
||||||
var (colour, result) = judgements.Single();
|
|
||||||
Children.FirstOrDefault(c => c.Result == result).FadeOut(animation_duration, Easing.OutQuint).Expire();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DrawableResult : Container
|
private class DrawableResult : Container
|
||||||
{
|
{
|
||||||
public JudgementResult Result { get; private set; }
|
public bool IsRemoved { get; private set; }
|
||||||
|
|
||||||
private readonly CircularContainer content;
|
private readonly CircularContainer content;
|
||||||
|
|
||||||
public DrawableResult(Color4 colour, JudgementResult result, int size)
|
public DrawableResult(Color4 colour, int size)
|
||||||
{
|
{
|
||||||
Result = result;
|
|
||||||
|
|
||||||
Size = new Vector2(size);
|
Size = new Vector2(size);
|
||||||
Child = content = new CircularContainer
|
Child = content = new CircularContainer
|
||||||
{
|
{
|
||||||
@ -113,6 +83,12 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
content.MoveToY(-DrawSize.Y);
|
content.MoveToY(-DrawSize.Y);
|
||||||
content.MoveToY(0, animation_duration, Easing.OutQuint);
|
content.MoveToY(0, animation_duration, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Remove()
|
||||||
|
{
|
||||||
|
IsRemoved = true;
|
||||||
|
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user