mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:02:55 +08:00
Apply pooling support to ColourHitErrorMeter
This commit is contained in:
parent
a86b50d62a
commit
aef6ee23eb
@ -3,9 +3,11 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Pooling;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
@ -15,6 +17,7 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
{
|
||||
[Cached]
|
||||
public class ColourHitErrorMeter : HitErrorMeter
|
||||
{
|
||||
private const int animation_duration = 200;
|
||||
@ -82,7 +85,7 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
JudgementCount.BindValueChanged(count =>
|
||||
JudgementCount.BindValueChanged(_ =>
|
||||
{
|
||||
removeExtraJudgements();
|
||||
updateMetrics();
|
||||
@ -91,11 +94,14 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
JudgementSpacing.BindValueChanged(_ => updateMetrics(), true);
|
||||
}
|
||||
|
||||
private readonly DrawablePool<HitErrorShape> judgementLinePool = new DrawablePool<HitErrorShape>(50);
|
||||
|
||||
public void Push(Color4 colour)
|
||||
{
|
||||
Add(new HitErrorShape(colour, drawable_judgement_size)
|
||||
judgementLinePool.Get(shape =>
|
||||
{
|
||||
Shape = { BindTarget = JudgementShape },
|
||||
shape.Colour = colour;
|
||||
Add(shape);
|
||||
});
|
||||
|
||||
removeExtraJudgements();
|
||||
@ -116,32 +122,32 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
}
|
||||
}
|
||||
|
||||
public class HitErrorShape : Container
|
||||
public class HitErrorShape : PoolableDrawable
|
||||
{
|
||||
public bool IsRemoved { get; private set; }
|
||||
|
||||
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
|
||||
|
||||
private readonly Color4 colour;
|
||||
[Resolved]
|
||||
private ColourHitErrorMeter hitErrorMeter { get; set; } = null!;
|
||||
|
||||
private Container content = null!;
|
||||
|
||||
public HitErrorShape(Color4 colour, int size)
|
||||
public HitErrorShape()
|
||||
{
|
||||
this.colour = colour;
|
||||
Size = new Vector2(size);
|
||||
Size = new Vector2(drawable_judgement_size);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Child = content = new Container
|
||||
InternalChild = content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colour
|
||||
};
|
||||
|
||||
Shape.BindTo(hitErrorMeter.JudgementShape);
|
||||
Shape.BindValueChanged(shape =>
|
||||
{
|
||||
switch (shape.NewValue)
|
||||
@ -155,17 +161,27 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
break;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
content.FadeInFromZero(animation_duration, Easing.OutQuint);
|
||||
content.MoveToY(-DrawSize.Y);
|
||||
content.MoveToY(0, animation_duration, Easing.OutQuint);
|
||||
protected override void PrepareForUse()
|
||||
{
|
||||
base.PrepareForUse();
|
||||
|
||||
IsRemoved = false;
|
||||
|
||||
this.FadeIn();
|
||||
|
||||
content.FadeInFromZero(animation_duration, Easing.OutQuint)
|
||||
.MoveToY(-DrawSize.Y)
|
||||
.MoveToY(0, animation_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
IsRemoved = true;
|
||||
|
||||
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
|
||||
this.FadeOut(animation_duration, Easing.OutQuint)
|
||||
.Expire();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user