mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 21:47:25 +08:00
Merge pull request #12706 from peppy/skin-components-bind-outwards-accuracy
Update `AccuracyCounter` components to use DI to attach data source
This commit is contained in:
commit
a480e530fb
@ -1,49 +1,36 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
public class TestSceneSkinnableAccuracyCounter : SkinnableTestScene
|
||||
{
|
||||
private IEnumerable<SkinnableAccuracyCounter> accuracyCounters => CreatedDrawables.OfType<SkinnableAccuracyCounter>();
|
||||
|
||||
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
||||
|
||||
[Cached]
|
||||
private ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("Create combo counters", () => SetContents(() =>
|
||||
{
|
||||
var accuracyCounter = new SkinnableAccuracyCounter();
|
||||
|
||||
accuracyCounter.Current.Value = 1;
|
||||
|
||||
return accuracyCounter;
|
||||
}));
|
||||
AddStep("Set initial accuracy", () => scoreProcessor.Accuracy.Value = 1);
|
||||
AddStep("Create accuracy counters", () => SetContents(() => new SkinnableAccuracyCounter()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestChangingAccuracy()
|
||||
{
|
||||
AddStep(@"Reset all", delegate
|
||||
{
|
||||
foreach (var s in accuracyCounters)
|
||||
s.Current.Value = 1;
|
||||
});
|
||||
AddStep(@"Reset all", () => scoreProcessor.Accuracy.Value = 1);
|
||||
|
||||
AddStep(@"Hit! :D", delegate
|
||||
{
|
||||
foreach (var s in accuracyCounters)
|
||||
s.Current.Value -= 0.023f;
|
||||
});
|
||||
AddStep(@"Miss :(", () => scoreProcessor.Accuracy.Value -= 0.023);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,11 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public class DefaultAccuracyCounter : PercentageCounter, IAccuracyCounter, ISkinnableComponent
|
||||
public class DefaultAccuracyCounter : GameplayAccuracyCounter, ISkinnableComponent
|
||||
{
|
||||
private readonly Vector2 offset = new Vector2(-20, 5);
|
||||
|
||||
|
18
osu.Game/Screens/Play/HUD/GameplayAccuracyCounter.cs
Normal file
18
osu.Game/Screens/Play/HUD/GameplayAccuracyCounter.cs
Normal file
@ -0,0 +1,18 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public abstract class GameplayAccuracyCounter : PercentageCounter
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ScoreProcessor scoreProcessor)
|
||||
{
|
||||
Current.BindTo(scoreProcessor.Accuracy);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// 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 osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface providing a set of methods to update a accuracy counter.
|
||||
/// </summary>
|
||||
public interface IAccuracyCounter : IDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The current accuracy to be displayed.
|
||||
/// </summary>
|
||||
Bindable<double> Current { get; }
|
||||
}
|
||||
}
|
@ -1,29 +1,16 @@
|
||||
// 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 osu.Framework.Bindables;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public class SkinnableAccuracyCounter : SkinnableDrawable, IAccuracyCounter
|
||||
public class SkinnableAccuracyCounter : SkinnableDrawable
|
||||
{
|
||||
public Bindable<double> Current { get; } = new Bindable<double>();
|
||||
|
||||
public SkinnableAccuracyCounter()
|
||||
: base(new HUDSkinComponent(HUDSkinComponents.AccuracyCounter), _ => new DefaultAccuracyCounter())
|
||||
{
|
||||
CentreComponent = false;
|
||||
}
|
||||
|
||||
private IAccuracyCounter skinnedCounter;
|
||||
|
||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||
{
|
||||
base.SkinChanged(skin, allowFallback);
|
||||
|
||||
skinnedCounter = Drawable as IAccuracyCounter;
|
||||
skinnedCounter?.Current.BindTo(Current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -320,8 +320,6 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected virtual void BindScoreProcessor(ScoreProcessor processor)
|
||||
{
|
||||
AccuracyCounter?.Current.BindTo(processor.Accuracy);
|
||||
|
||||
if (HealthDisplay is IHealthDisplay shd)
|
||||
{
|
||||
processor.NewJudgement += judgement =>
|
||||
|
@ -4,14 +4,13 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class LegacyAccuracyCounter : PercentageCounter, IAccuracyCounter, ISkinnableComponent
|
||||
public class LegacyAccuracyCounter : GameplayAccuracyCounter, ISkinnableComponent
|
||||
{
|
||||
private readonly ISkin skin;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user