1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 18:07:24 +08:00

Fix enum to STRING????????? conversion (and use bindable flow)

This commit is contained in:
Dean Herbert 2022-09-09 16:30:08 +09:00
parent 5852a09003
commit 05797cb9e5

View File

@ -1,7 +1,6 @@
// 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -78,11 +77,6 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
judgementsFlow.Clear(); judgementsFlow.Clear();
judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value; judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value;
}, true); }, true);
HitShape.BindValueChanged(_ =>
{
judgementsFlow.Shape = getShapeStyle(HitShape.Value);
judgementsFlow.Clear();
}, true);
} }
public override void Clear() => judgementsFlow.Clear(); public override void Clear() => judgementsFlow.Clear();
@ -90,7 +84,8 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
private class JudgementFlow : FillFlowContainer<HitErrorShape> private class JudgementFlow : FillFlowContainer<HitErrorShape>
{ {
public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse(); public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse();
internal string Shape = null!;
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
public JudgementFlow() public JudgementFlow()
{ {
@ -102,7 +97,10 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
public void Push(Color4 colour, int maxErrorShapeCount) public void Push(Color4 colour, int maxErrorShapeCount)
{ {
Add(new HitErrorShape(colour, drawable_judgement_size, Shape)); Add(new HitErrorShape(colour, drawable_judgement_size)
{
Shape = { BindTarget = Shape },
});
if (Children.Count > maxErrorShapeCount) if (Children.Count > maxErrorShapeCount)
Children.FirstOrDefault(c => !c.IsRemoved)?.Remove(); Children.FirstOrDefault(c => !c.IsRemoved)?.Remove();
@ -113,36 +111,44 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
public bool IsRemoved { get; private set; } public bool IsRemoved { get; private set; }
public HitErrorShape(Color4 colour, int size, string shape) public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
private readonly Color4 colour;
public HitErrorShape(Color4 colour, int size)
{ {
this.colour = colour;
Size = new Vector2(size); Size = new Vector2(size);
switch (shape)
{
case "circle":
Child = new Circle
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
break;
case "square":
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
break;
}
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Shape.BindValueChanged(shape =>
{
switch (shape.NewValue)
{
case ShapeStyle.Circle:
Child = new Circle
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
break;
case ShapeStyle.Square:
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
break;
}
}, true);
Child.FadeInFromZero(animation_duration, Easing.OutQuint); Child.FadeInFromZero(animation_duration, Easing.OutQuint);
Child.MoveToY(-DrawSize.Y); Child.MoveToY(-DrawSize.Y);
Child.MoveToY(0, animation_duration, Easing.OutQuint); Child.MoveToY(0, animation_duration, Easing.OutQuint);
@ -156,21 +162,6 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
} }
} }
private string getShapeStyle(ShapeStyle shape)
{
switch (shape)
{
case ShapeStyle.Circle:
return "circle";
case ShapeStyle.Square:
return "square";
default:
throw new ArgumentOutOfRangeException(nameof(shape), shape, @"Unsupported animation style");
}
}
public enum ShapeStyle public enum ShapeStyle
{ {
Circle, Circle,