mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 21:47:25 +08:00
Large code refactor, Implementation of shapes option drop down
This commit is contained in:
parent
1a11f7e8d4
commit
0c6d8efa28
@ -1,8 +1,7 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
@ -19,12 +18,12 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
{
|
||||
public class ColourHitErrorMeter : HitErrorMeter
|
||||
{
|
||||
private const int default_shape_alpha = 0;
|
||||
private const int animation_duration = 200;
|
||||
private const int drawable_judgement_size = 8;
|
||||
private readonly JudgementFlow judgementsFlow;
|
||||
|
||||
[SettingSource("Colour hit number", "number of coloured hits")]
|
||||
public BindableNumber<int> HitCircleAmount { get; } = new BindableNumber<int>(20)
|
||||
[SettingSource("Hit error amount", "Number of hit error shapes")]
|
||||
public BindableNumber<int> HitShapeCount { get; } = new BindableNumber<int>(20)
|
||||
{
|
||||
MinValue = 1,
|
||||
MaxValue = 30,
|
||||
@ -32,21 +31,26 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
};
|
||||
|
||||
[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,
|
||||
MaxValue = 1,
|
||||
Precision = .01f
|
||||
Precision = .01f,
|
||||
};
|
||||
|
||||
[SettingSource("Spacing", "space between hit colour circles")]
|
||||
public BindableNumber<float> HitSpacing { get; } = new BindableNumber<float>(2)
|
||||
[SettingSource("Spacing", "Space between hit error shapes")]
|
||||
public BindableNumber<float> HitShapeSpacing { get; } = new BindableNumber<float>(2)
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 10,
|
||||
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()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
@ -58,24 +62,36 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
if (!judgement.Type.IsScorable() || judgement.Type.IsBonus())
|
||||
return;
|
||||
|
||||
judgementsFlow.Push(GetColourForHitResult(judgement.Type), HitCircleAmount.Value);
|
||||
judgementsFlow.Push(GetColourForHitResult(judgement.Type), HitShapeCount.Value);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
HitOpacity.BindValueChanged(_ => judgementsFlow.Alpha = HitOpacity.Value, true);
|
||||
HitSpacing.BindValueChanged(_ => judgementsFlow.Spacing = new Vector2(0, HitSpacing.Value), true);
|
||||
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);
|
||||
HitCircleAmount.BindValueChanged(_ => judgementsFlow.Clear(), true);
|
||||
HitShapeOpacity.BindValueChanged(_ => judgementsFlow.Alpha = HitShapeOpacity.Value, true);
|
||||
HitShapeSpacing.BindValueChanged(_ =>
|
||||
{
|
||||
judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value;
|
||||
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();
|
||||
|
||||
private class JudgementFlow : FillFlowContainer<HitErrorCircle>
|
||||
private class JudgementFlow : FillFlowContainer<HitErrorShape>
|
||||
{
|
||||
public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse();
|
||||
internal string ValueParser = null!;
|
||||
|
||||
public JudgementFlow()
|
||||
{
|
||||
@ -85,38 +101,52 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
internal class HitErrorCircle : Container
|
||||
private class HitErrorShape : Container
|
||||
{
|
||||
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);
|
||||
Child = circle = new Circle
|
||||
|
||||
switch (shape)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
Colour = colour
|
||||
};
|
||||
case "circle":
|
||||
Child = new Circle
|
||||
{
|
||||
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()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
circle.FadeInFromZero(animation_duration, Easing.OutQuint);
|
||||
circle.MoveToY(-DrawSize.Y);
|
||||
circle.MoveToY(0, animation_duration, Easing.OutQuint);
|
||||
Child.FadeInFromZero(animation_duration, Easing.OutQuint);
|
||||
Child.MoveToY(-DrawSize.Y);
|
||||
Child.MoveToY(0, animation_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
@ -126,5 +156,26 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user