Merge pull request #20111 from mk56-spn/Colour_hit_meter_improved

Add customisation settings of colour hit error display
This commit is contained in:
Dean Herbert 2022-09-22 16:28:31 +09:00 committed by GitHub
commit a7eb9d8b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 246 additions and 51 deletions

View File

@ -0,0 +1,117 @@
// 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.
using System;
using System.Diagnostics;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD.HitErrorMeters;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneColourHitErrorMeter : OsuTestScene
{
private DependencyProvidingContainer dependencyContainer = null!;
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
private ScoreProcessor scoreProcessor = null!;
private int iteration;
private ColourHitErrorMeter colourHitErrorMeter = null!;
public TestSceneColourHitErrorMeter()
{
AddSliderStep("Judgement spacing", 0, 10, 2, spacing =>
{
if (colourHitErrorMeter.IsNotNull())
colourHitErrorMeter.JudgementSpacing.Value = spacing;
});
AddSliderStep("Judgement count", 1, 50, 5, spacing =>
{
if (colourHitErrorMeter.IsNotNull())
colourHitErrorMeter.JudgementCount.Value = spacing;
});
}
[SetUpSteps]
public void SetupSteps() => AddStep("Create components", () =>
{
var ruleset = CreateRuleset();
Debug.Assert(ruleset != null);
scoreProcessor = new ScoreProcessor(ruleset);
Child = dependencyContainer = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]
{
(typeof(ScoreProcessor), scoreProcessor)
}
};
dependencyContainer.Child = colourHitErrorMeter = new ColourHitErrorMeter
{
Margin = new MarginPadding
{
Top = 100
},
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Scale = new Vector2(2),
};
});
protected override Ruleset CreateRuleset() => new OsuRuleset();
[Test]
public void TestSpacingChange()
{
AddRepeatStep("Add judgement", applyOneJudgement, 5);
AddStep("Change spacing", () => colourHitErrorMeter.JudgementSpacing.Value = 10);
AddRepeatStep("Add judgement", applyOneJudgement, 5);
}
[Test]
public void TestJudgementAmountChange()
{
AddRepeatStep("Add judgement", applyOneJudgement, 10);
AddStep("Judgement count change to 4", () => colourHitErrorMeter.JudgementCount.Value = 4);
AddRepeatStep("Add judgement", applyOneJudgement, 8);
}
[Test]
public void TestHitErrorShapeChange()
{
AddRepeatStep("Add judgement", applyOneJudgement, 8);
AddStep("Change shape square", () => colourHitErrorMeter.JudgementShape.Value = ColourHitErrorMeter.ShapeStyle.Square);
AddRepeatStep("Add judgement", applyOneJudgement, 10);
AddStep("Change shape circle", () => colourHitErrorMeter.JudgementShape.Value = ColourHitErrorMeter.ShapeStyle.Circle);
}
private void applyOneJudgement()
{
lastJudgementResult.Value = new OsuJudgementResult(new HitObject
{
StartTime = iteration * 10000,
}, new OsuJudgement())
{
Type = HitResult.Great,
};
scoreProcessor.ApplyResult(lastJudgementResult.Value);
iteration++;
}
}
}

View File

@ -107,13 +107,13 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("circle added", () =>
this.ChildrenOfType<ColourHitErrorMeter>().All(
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() == 1));
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count() == 1));
AddStep("miss", () => newJudgement(50, HitResult.Miss));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("circle added", () =>
this.ChildrenOfType<ColourHitErrorMeter>().All(
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() == 2));
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count() == 2));
}
[Test]
@ -123,11 +123,11 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("small bonus", () => newJudgement(result: HitResult.SmallBonus));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Any());
AddStep("large bonus", () => newJudgement(result: HitResult.LargeBonus));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Any());
}
[Test]
@ -137,16 +137,17 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("ignore hit", () => newJudgement(result: HitResult.IgnoreHit));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Any());
AddStep("ignore miss", () => newJudgement(result: HitResult.IgnoreMiss));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Any());
}
[Test]
public void TestProcessingWhileHidden()
{
const int max_displayed_judgements = 20;
AddStep("OD 1", () => recreateDisplay(new OsuHitWindows(), 1));
AddStep("hide displays", () =>
@ -155,16 +156,16 @@ namespace osu.Game.Tests.Visual.Gameplay
hitErrorMeter.Hide();
});
AddRepeatStep("hit", () => newJudgement(), ColourHitErrorMeter.MAX_DISPLAYED_JUDGEMENTS * 2);
AddRepeatStep("hit", () => newJudgement(), max_displayed_judgements * 2);
AddAssert("bars added", () => this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("circle added", () => this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddAssert("circle added", () => this.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Any());
AddUntilStep("wait for bars to disappear", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddUntilStep("ensure max circles not exceeded", () =>
{
return this.ChildrenOfType<ColourHitErrorMeter>()
.All(m => m.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() <= ColourHitErrorMeter.MAX_DISPLAYED_JUDGEMENTS);
.All(m => m.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count() <= max_displayed_judgements);
});
AddStep("show displays", () =>
@ -183,12 +184,12 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("bar added", () => this.ChildrenOfType<BarHitErrorMeter>().All(
meter => meter.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Count() == 1));
AddAssert("circle added", () => this.ChildrenOfType<ColourHitErrorMeter>().All(
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() == 1));
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count() == 1));
AddStep("clear", () => this.ChildrenOfType<HitErrorMeter>().ForEach(meter => meter.Clear()));
AddAssert("bar cleared", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("colour cleared", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddAssert("colour cleared", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Any());
}
private void recreateDisplay(HitWindows hitWindows, float overallDifficulty)

View File

@ -1,13 +1,13 @@
// 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.
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK;
@ -17,18 +17,37 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
public class ColourHitErrorMeter : HitErrorMeter
{
internal const int MAX_DISPLAYED_JUDGEMENTS = 20;
private const int animation_duration = 200;
private const int drawable_judgement_size = 8;
private const int spacing = 2;
[SettingSource("Judgement count", "The number of displayed judgements")]
public BindableNumber<int> JudgementCount { get; } = new BindableNumber<int>(20)
{
MinValue = 1,
MaxValue = 50,
};
[SettingSource("Judgement spacing", "The space between each displayed judgement")]
public BindableNumber<float> JudgementSpacing { get; } = new BindableNumber<float>(2)
{
MinValue = 0,
MaxValue = 10,
};
[SettingSource("Judgement shape", "The shape of each displayed judgement")]
public Bindable<ShapeStyle> JudgementShape { get; } = new Bindable<ShapeStyle>();
private readonly JudgementFlow judgementsFlow;
public ColourHitErrorMeter()
{
AutoSizeAxes = Axes.Both;
InternalChild = judgementsFlow = new JudgementFlow();
InternalChild = judgementsFlow = new JudgementFlow
{
JudgementShape = { BindTarget = JudgementShape },
JudgementSpacing = { BindTarget = JudgementSpacing },
JudgementCount = { BindTarget = JudgementCount }
};
}
protected override void OnNewJudgement(JudgementResult judgement)
@ -41,53 +60,105 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
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 readonly Bindable<ShapeStyle> JudgementShape = new Bindable<ShapeStyle>();
public readonly Bindable<float> JudgementSpacing = new Bindable<float>();
public readonly Bindable<int> JudgementCount = new Bindable<int>();
public JudgementFlow()
{
AutoSizeAxes = Axes.X;
Height = MAX_DISPLAYED_JUDGEMENTS * (drawable_judgement_size + spacing) - spacing;
Spacing = new Vector2(0, spacing);
Width = drawable_judgement_size;
Direction = FillDirection.Vertical;
LayoutDuration = animation_duration;
LayoutEasing = Easing.OutQuint;
}
public void Push(Color4 colour)
{
Add(new HitErrorCircle(colour, drawable_judgement_size));
if (Children.Count > MAX_DISPLAYED_JUDGEMENTS)
Children.FirstOrDefault(c => !c.IsRemoved)?.Remove();
}
}
internal class HitErrorCircle : Container
{
public bool IsRemoved { get; private set; }
private readonly Circle circle;
public HitErrorCircle(Color4 colour, int size)
{
Size = new Vector2(size);
Child = circle = new Circle
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Colour = colour
};
}
protected override void LoadComplete()
{
base.LoadComplete();
circle.FadeInFromZero(animation_duration, Easing.OutQuint);
circle.MoveToY(-DrawSize.Y);
circle.MoveToY(0, animation_duration, Easing.OutQuint);
JudgementCount.BindValueChanged(count =>
{
removeExtraJudgements();
updateMetrics();
});
JudgementSpacing.BindValueChanged(_ => updateMetrics(), true);
}
public void Push(Color4 colour)
{
Add(new HitErrorShape(colour, drawable_judgement_size)
{
Shape = { BindTarget = JudgementShape },
});
removeExtraJudgements();
}
private void removeExtraJudgements()
{
var remainingChildren = Children.Where(c => !c.IsRemoved);
while (remainingChildren.Count() > JudgementCount.Value)
remainingChildren.First().Remove();
}
private void updateMetrics()
{
Height = JudgementCount.Value * (drawable_judgement_size + JudgementSpacing.Value) - JudgementSpacing.Value;
Spacing = new Vector2(0, JudgementSpacing.Value);
}
}
public class HitErrorShape : Container
{
public bool IsRemoved { get; private set; }
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
private readonly Color4 colour;
private Container content = null!;
public HitErrorShape(Color4 colour, int size)
{
this.colour = colour;
Size = new Vector2(size);
}
protected override void LoadComplete()
{
base.LoadComplete();
Child = content = new Container
{
RelativeSizeAxes = Axes.Both,
Colour = colour
};
Shape.BindValueChanged(shape =>
{
switch (shape.NewValue)
{
case ShapeStyle.Circle:
content.Child = new Circle { RelativeSizeAxes = Axes.Both };
break;
case ShapeStyle.Square:
content.Child = new Box { RelativeSizeAxes = Axes.Both };
break;
}
}, true);
content.FadeInFromZero(animation_duration, Easing.OutQuint);
content.MoveToY(-DrawSize.Y);
content.MoveToY(0, animation_duration, Easing.OutQuint);
}
public void Remove()
@ -97,5 +168,11 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
}
}
public enum ShapeStyle
{
Circle,
Square
}
}
}