From 05797cb9e55447823b72c4a56e61a4d152472284 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 9 Sep 2022 16:30:08 +0900 Subject: [PATCH] Fix enum to STRING????????? conversion (and use bindable flow) --- .../HUD/HitErrorMeters/ColourHitErrorMeter.cs | 81 +++++++++---------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs b/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs index 0713469e10..c218ff11e9 100644 --- a/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs +++ b/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; @@ -78,11 +77,6 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters judgementsFlow.Clear(); judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value; }, true); - HitShape.BindValueChanged(_ => - { - judgementsFlow.Shape = getShapeStyle(HitShape.Value); - judgementsFlow.Clear(); - }, true); } public override void Clear() => judgementsFlow.Clear(); @@ -90,7 +84,8 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters private class JudgementFlow : FillFlowContainer { public override IEnumerable FlowingChildren => base.FlowingChildren.Reverse(); - internal string Shape = null!; + + public readonly Bindable Shape = new Bindable(); public JudgementFlow() { @@ -102,7 +97,10 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters 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) Children.FirstOrDefault(c => !c.IsRemoved)?.Remove(); @@ -113,36 +111,44 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters { public bool IsRemoved { get; private set; } - public HitErrorShape(Color4 colour, int size, string shape) + public readonly Bindable Shape = new Bindable(); + + private readonly Color4 colour; + + public HitErrorShape(Color4 colour, int size) { + this.colour = colour; 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() { 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.MoveToY(-DrawSize.Y); 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 { Circle,