1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 02:23:06 +08:00

Large code refactor, Implementation of shapes option drop down

This commit is contained in:
Mk-56spn 2022-09-04 17:24:12 +02:00
parent 1a11f7e8d4
commit 0c6d8efa28

View File

@ -1,8 +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.
#nullable disable using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -19,12 +18,12 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
public class ColourHitErrorMeter : HitErrorMeter public class ColourHitErrorMeter : HitErrorMeter
{ {
private const int default_shape_alpha = 0;
private const int animation_duration = 200; private const int animation_duration = 200;
private const int drawable_judgement_size = 8; private const int drawable_judgement_size = 8;
private readonly JudgementFlow judgementsFlow;
[SettingSource("Colour hit number", "number of coloured hits")] [SettingSource("Hit error amount", "Number of hit error shapes")]
public BindableNumber<int> HitCircleAmount { get; } = new BindableNumber<int>(20) public BindableNumber<int> HitShapeCount { get; } = new BindableNumber<int>(20)
{ {
MinValue = 1, MinValue = 1,
MaxValue = 30, MaxValue = 30,
@ -32,21 +31,26 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
}; };
[SettingSource("Opacity", "Visibility of object")] [SettingSource("Opacity", "Visibility of object")]
public BindableNumber<float> HitOpacity { get; } = new BindableNumber<float>(1) public BindableNumber<float> HitShapeOpacity { get; } = new BindableNumber<float>(1)
{ {
MinValue = 0.01f, MinValue = 0.01f,
MaxValue = 1, MaxValue = 1,
Precision = .01f Precision = .01f,
}; };
[SettingSource("Spacing", "space between hit colour circles")] [SettingSource("Spacing", "Space between hit error shapes")]
public BindableNumber<float> HitSpacing { get; } = new BindableNumber<float>(2) public BindableNumber<float> HitShapeSpacing { get; } = new BindableNumber<float>(2)
{ {
MinValue = 0, MinValue = 0,
MaxValue = 10, MaxValue = 10,
Precision = .1f Precision = .1f
}; };
[SettingSource("Shape", "What shape to use for hit errors")]
public Bindable<ShapeStyle> HitShape { get; } = new Bindable<ShapeStyle>();
private readonly JudgementFlow judgementsFlow;
public ColourHitErrorMeter() public ColourHitErrorMeter()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -58,24 +62,36 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
if (!judgement.Type.IsScorable() || judgement.Type.IsBonus()) if (!judgement.Type.IsScorable() || judgement.Type.IsBonus())
return; return;
judgementsFlow.Push(GetColourForHitResult(judgement.Type), HitCircleAmount.Value); judgementsFlow.Push(GetColourForHitResult(judgement.Type), HitShapeCount.Value);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
HitOpacity.BindValueChanged(_ => judgementsFlow.Alpha = HitOpacity.Value, true); HitShapeOpacity.BindValueChanged(_ => judgementsFlow.Alpha = HitShapeOpacity.Value, true);
HitSpacing.BindValueChanged(_ => judgementsFlow.Spacing = new Vector2(0, HitSpacing.Value), true); HitShapeSpacing.BindValueChanged(_ =>
HitSpacing.BindValueChanged(_ => judgementsFlow.Height = HitCircleAmount.Value * (drawable_judgement_size + HitSpacing.Value) - HitSpacing.Value, true); {
HitCircleAmount.BindValueChanged(_ => judgementsFlow.Height = HitCircleAmount.Value * (drawable_judgement_size + HitSpacing.Value) - HitSpacing.Value, true); judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value;
HitCircleAmount.BindValueChanged(_ => judgementsFlow.Clear(), true); judgementsFlow.Spacing = new Vector2(0, HitShapeSpacing.Value);
}, true);
HitShapeCount.BindValueChanged(_ =>
{
judgementsFlow.Clear();
judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value;
}, true);
HitShape.BindValueChanged(_ =>
{
judgementsFlow.ValueParser = getShapeStyle(HitShape.Value);
judgementsFlow.Clear();
}, true);
} }
public override void Clear() => judgementsFlow.Clear(); public override void Clear() => judgementsFlow.Clear();
private class JudgementFlow : FillFlowContainer<HitErrorCircle> private class JudgementFlow : FillFlowContainer<HitErrorShape>
{ {
public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse(); public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse();
internal string ValueParser = null!;
public JudgementFlow() public JudgementFlow()
{ {
@ -85,38 +101,52 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
LayoutEasing = Easing.OutQuint; LayoutEasing = Easing.OutQuint;
} }
public void Push(Color4 colour, int amount) public void Push(Color4 colour, int maxErrorShapeCount)
{ {
Add(new HitErrorCircle(colour, drawable_judgement_size)); Add(new HitErrorShape(colour, drawable_judgement_size, ValueParser));
if (Children.Count > amount) if (Children.Count > maxErrorShapeCount)
Children.FirstOrDefault(c => !c.IsRemoved)?.Remove(); Children.FirstOrDefault(c => !c.IsRemoved)?.Remove();
} }
} }
internal class HitErrorCircle : Container private class HitErrorShape : Container
{ {
public bool IsRemoved { get; private set; } public bool IsRemoved { get; private set; }
private readonly Circle circle;
public HitErrorCircle(Color4 colour, int size) public HitErrorShape(Color4 colour, int size, string shape)
{ {
Size = new Vector2(size); Size = new Vector2(size);
Child = circle = new Circle
switch (shape)
{ {
RelativeSizeAxes = Axes.Both, case "circle":
Alpha = 0, Child = new Circle
Colour = colour {
}; RelativeSizeAxes = Axes.Both,
Alpha = default_shape_alpha,
Colour = colour
};
break;
case "square":
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = default_shape_alpha,
Colour = colour
};
break;
}
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
circle.FadeInFromZero(animation_duration, Easing.OutQuint); Child.FadeInFromZero(animation_duration, Easing.OutQuint);
circle.MoveToY(-DrawSize.Y); Child.MoveToY(-DrawSize.Y);
circle.MoveToY(0, animation_duration, Easing.OutQuint); Child.MoveToY(0, animation_duration, Easing.OutQuint);
} }
public void Remove() public void Remove()
@ -126,5 +156,26 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
this.FadeOut(animation_duration, Easing.OutQuint).Expire(); this.FadeOut(animation_duration, Easing.OutQuint).Expire();
} }
} }
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,
Square
}
} }
} }