2022-12-11 22:47:17 +00:00
|
|
|
// 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 System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
using osu.Game.Rulesets.Mania;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.Judgements;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Screens.Play.HUD.JudgementCounter;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
public partial class TestSceneJudgementCounter : OsuTestScene
|
|
|
|
{
|
|
|
|
private ScoreProcessor scoreProcessor = null!;
|
2023-06-26 17:30:04 +00:00
|
|
|
private JudgementCountController judgementCountController = null!;
|
2022-12-15 15:12:34 +00:00
|
|
|
private TestJudgementCounterDisplay counterDisplay = null!;
|
2022-12-11 22:47:17 +00:00
|
|
|
|
2023-01-18 20:41:00 +00:00
|
|
|
private DependencyProvidingContainer content = null!;
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
2022-12-11 22:47:17 +00:00
|
|
|
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
|
|
|
|
|
|
|
|
private int iteration;
|
|
|
|
|
|
|
|
[SetUpSteps]
|
2023-01-18 20:41:00 +00:00
|
|
|
public void SetUpSteps() => AddStep("Create components", () =>
|
2022-12-11 22:47:17 +00:00
|
|
|
{
|
|
|
|
var ruleset = CreateRuleset();
|
|
|
|
|
|
|
|
Debug.Assert(ruleset != null);
|
|
|
|
|
2022-12-12 14:10:10 +00:00
|
|
|
scoreProcessor = new ScoreProcessor(ruleset);
|
2023-01-18 20:41:00 +00:00
|
|
|
base.Content.Child = new DependencyProvidingContainer
|
2022-12-11 22:47:17 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-12-12 14:10:10 +00:00
|
|
|
CachedDependencies = new (Type, object)[] { (typeof(ScoreProcessor), scoreProcessor), (typeof(Ruleset), ruleset) },
|
2022-12-11 22:47:17 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-06-26 17:30:04 +00:00
|
|
|
judgementCountController = new JudgementCountController(),
|
2023-01-18 20:41:00 +00:00
|
|
|
content = new DependencyProvidingContainer
|
2022-12-11 22:47:17 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-06-26 17:30:04 +00:00
|
|
|
CachedDependencies = new (Type, object)[] { (typeof(JudgementCountController), judgementCountController) },
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
protected override Ruleset CreateRuleset() => new ManiaRuleset();
|
|
|
|
|
|
|
|
private void applyOneJudgement(HitResult result)
|
|
|
|
{
|
|
|
|
lastJudgementResult.Value = new OsuJudgementResult(new HitObject
|
|
|
|
{
|
|
|
|
StartTime = iteration * 10000
|
|
|
|
}, new OsuJudgement())
|
|
|
|
{
|
|
|
|
Type = result,
|
|
|
|
};
|
|
|
|
scoreProcessor.ApplyResult(lastJudgementResult.Value);
|
|
|
|
|
|
|
|
iteration++;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddJudgementsToCounters()
|
|
|
|
{
|
2023-01-18 20:41:00 +00:00
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
2022-12-11 22:47:17 +00:00
|
|
|
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.Great), 2);
|
|
|
|
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.Miss), 2);
|
|
|
|
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.Meh), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddWhilstHidden()
|
|
|
|
{
|
2023-01-18 20:41:00 +00:00
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
2022-12-11 22:47:17 +00:00
|
|
|
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.LargeTickHit), 2);
|
|
|
|
AddAssert("Check value added whilst hidden", () => hiddenCount() == 2);
|
2022-12-15 15:12:34 +00:00
|
|
|
AddStep("Show all judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.All);
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestChangeFlowDirection()
|
|
|
|
{
|
2023-01-18 20:41:00 +00:00
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
2023-01-17 09:21:30 +00:00
|
|
|
AddStep("Set direction vertical", () => counterDisplay.FlowDirection.Value = Direction.Vertical);
|
|
|
|
AddStep("Set direction horizontal", () => counterDisplay.FlowDirection.Value = Direction.Horizontal);
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-12-11 22:58:10 +00:00
|
|
|
public void TestToggleJudgementNames()
|
2022-12-11 22:47:17 +00:00
|
|
|
{
|
2023-01-18 20:41:00 +00:00
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
2023-01-17 09:24:55 +00:00
|
|
|
AddStep("Hide judgement names", () => counterDisplay.ShowJudgementNames.Value = false);
|
2022-12-16 16:40:39 +00:00
|
|
|
AddWaitStep("wait some", 2);
|
2023-01-17 09:28:08 +00:00
|
|
|
AddAssert("Assert hidden", () => counterDisplay.CounterFlow.Children.First().ResultName.Alpha == 0);
|
2023-01-17 09:24:55 +00:00
|
|
|
AddStep("Hide judgement names", () => counterDisplay.ShowJudgementNames.Value = true);
|
2022-12-16 16:40:39 +00:00
|
|
|
AddWaitStep("wait some", 2);
|
2023-01-17 09:28:08 +00:00
|
|
|
AddAssert("Assert shown", () => counterDisplay.CounterFlow.Children.First().ResultName.Alpha == 1);
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestHideMaxValue()
|
|
|
|
{
|
2023-01-18 20:41:00 +00:00
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
2023-01-17 09:24:55 +00:00
|
|
|
AddStep("Hide max judgement", () => counterDisplay.ShowMaxJudgement.Value = false);
|
2022-12-15 15:12:34 +00:00
|
|
|
AddWaitStep("wait some", 2);
|
2023-01-17 09:28:08 +00:00
|
|
|
AddAssert("Check max hidden", () => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().First().Alpha == 0);
|
2023-01-17 09:24:55 +00:00
|
|
|
AddStep("Show max judgement", () => counterDisplay.ShowMaxJudgement.Value = true);
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
|
2023-01-18 20:42:22 +00:00
|
|
|
[Test]
|
|
|
|
public void TestMaxValueStartsHidden()
|
|
|
|
{
|
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay
|
|
|
|
{
|
|
|
|
ShowMaxJudgement = { Value = false }
|
|
|
|
});
|
|
|
|
AddAssert("Check max hidden", () => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().First().Alpha == 0);
|
|
|
|
}
|
|
|
|
|
2023-01-19 09:31:02 +00:00
|
|
|
[Test]
|
|
|
|
public void TestMaxValueHiddenOnModeChange()
|
|
|
|
{
|
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
|
|
|
AddStep("Set max judgement to hide itself", () => counterDisplay.ShowMaxJudgement.Value = false);
|
|
|
|
AddStep("Show all judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.All);
|
|
|
|
AddWaitStep("wait some", 2);
|
|
|
|
AddAssert("Assert max judgement hidden", () => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().First().Alpha == 0);
|
|
|
|
}
|
|
|
|
|
2022-12-11 22:47:17 +00:00
|
|
|
[Test]
|
|
|
|
public void TestCycleDisplayModes()
|
|
|
|
{
|
2023-01-18 20:41:00 +00:00
|
|
|
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
|
|
|
|
|
2022-12-15 15:12:34 +00:00
|
|
|
AddStep("Show basic judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.Simple);
|
|
|
|
AddWaitStep("wait some", 2);
|
2023-01-17 09:28:08 +00:00
|
|
|
AddAssert("Check only basic", () => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().Last().Alpha == 0);
|
2022-12-15 15:12:34 +00:00
|
|
|
AddStep("Show normal judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.Normal);
|
|
|
|
AddStep("Show all judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.All);
|
|
|
|
AddWaitStep("wait some", 2);
|
2023-01-17 09:28:08 +00:00
|
|
|
AddAssert("Check all visible", () => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().Last().Alpha == 1);
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private int hiddenCount()
|
|
|
|
{
|
2023-01-17 09:28:08 +00:00
|
|
|
var num = counterDisplay.CounterFlow.Children.First(child => child.Result.Type == HitResult.LargeTickHit);
|
2022-12-11 22:47:17 +00:00
|
|
|
return num.Result.ResultCount.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class TestJudgementCounterDisplay : JudgementCounterDisplay
|
|
|
|
{
|
2023-01-17 09:28:08 +00:00
|
|
|
public new FillFlowContainer<JudgementCounter> CounterFlow => base.CounterFlow;
|
2023-01-18 20:41:00 +00:00
|
|
|
|
|
|
|
public TestJudgementCounterDisplay()
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding { Top = 100 };
|
|
|
|
Anchor = Anchor.TopCentre;
|
|
|
|
Origin = Anchor.TopCentre;
|
|
|
|
}
|
2022-12-11 22:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|