1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 04:02:57 +08:00

Merge pull request #26540 from peppy/fix-double-counters

De-dupe displayed hits in judgement counter
This commit is contained in:
Bartłomiej Dach 2024-01-15 14:02:11 +01:00 committed by GitHub
commit d206acac63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 15 deletions

View File

@ -147,6 +147,16 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("Assert max judgement hidden", () => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().First().Alpha == 0);
}
[Test]
public void TestNoDuplicates()
{
AddStep("create counter", () => Child = counterDisplay = new TestJudgementCounterDisplay());
AddStep("Show all judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.All);
AddAssert("Check no duplicates",
() => counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().Count(),
() => Is.EqualTo(counterDisplay.CounterFlow.ChildrenOfType<JudgementCounter>().Select(c => c.ResultName.Text).Distinct().Count()));
}
[Test]
public void TestCycleDisplayModes()
{
@ -163,7 +173,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private int hiddenCount()
{
var num = counterDisplay.CounterFlow.Children.First(child => child.Result.Type == HitResult.LargeTickHit);
var num = counterDisplay.CounterFlow.Children.First(child => child.Result.Types.Contains(HitResult.LargeTickHit));
return num.Result.ResultCount.Value;
}

View File

@ -6,6 +6,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
@ -21,18 +22,30 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
[Resolved]
private ScoreProcessor scoreProcessor { get; set; } = null!;
public List<JudgementCount> Results = new List<JudgementCount>();
private readonly Dictionary<HitResult, JudgementCount> results = new Dictionary<HitResult, JudgementCount>();
public IEnumerable<JudgementCount> Counters => counters;
private readonly List<JudgementCount> counters = new List<JudgementCount>();
[BackgroundDependencyLoader]
private void load(IBindable<RulesetInfo> ruleset)
{
foreach (var result in ruleset.Value.CreateInstance().GetHitResults())
// Due to weirdness in judgements, some results have the same name and should be aggregated for display purposes.
// There's only one case of this right now ("slider end").
foreach (var group in ruleset.Value.CreateInstance().GetHitResults().GroupBy(r => r.displayName))
{
Results.Add(new JudgementCount
var judgementCount = new JudgementCount
{
Type = result.result,
DisplayName = group.Key,
Types = group.Select(r => r.result).ToArray(),
ResultCount = new BindableInt()
});
};
counters.Add(judgementCount);
foreach (var r in group)
results[r.result] = judgementCount;
}
}
@ -46,13 +59,20 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
private void updateCount(JudgementResult judgement, bool revert)
{
foreach (JudgementCount result in Results.Where(result => result.Type == judgement.Type))
result.ResultCount.Value = revert ? result.ResultCount.Value - 1 : result.ResultCount.Value + 1;
if (!results.TryGetValue(judgement.Type, out var count))
return;
if (revert)
count.ResultCount.Value--;
else
count.ResultCount.Value++;
}
public struct JudgementCount
{
public HitResult Type { get; set; }
public LocalisableString DisplayName { get; set; }
public HitResult[] Types { get; set; }
public BindableInt ResultCount { get; set; }
}

View File

@ -1,6 +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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -44,14 +45,14 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
{
Alpha = 0,
Font = OsuFont.Numeric.With(size: 8),
Text = ruleset.Value.CreateInstance().GetDisplayNameForHitResult(Result.Type)
Text = Result.DisplayName,
}
}
};
var result = Result.Type;
var result = Result.Types.First();
Colour = result.IsBasic() ? colours.ForHitResult(Result.Type) : !result.IsBonus() ? colours.PurpleLight : colours.PurpleLighter;
Colour = result.IsBasic() ? colours.ForHitResult(result) : !result.IsBonus() ? colours.PurpleLight : colours.PurpleLighter;
}
protected override void LoadComplete()

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -49,7 +50,7 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
AutoSizeAxes = Axes.Both
};
foreach (var result in judgementCountController.Results)
foreach (var result in judgementCountController.Counters)
CounterFlow.Add(createCounter(result));
}
@ -88,7 +89,9 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
if (index == 0 && !ShowMaxJudgement.Value)
return false;
if (counter.Result.Type.IsBasic())
var hitResult = counter.Result.Types.First();
if (hitResult.IsBasic())
return true;
switch (Mode.Value)
@ -97,7 +100,7 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
return false;
case DisplayMode.Normal:
return !counter.Result.Type.IsBonus();
return !hitResult.IsBonus();
case DisplayMode.All:
return true;