mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 22:47:26 +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.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Gameplay
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
{
|
{
|
||||||
public class TestSceneSkinnableAccuracyCounter : SkinnableTestScene
|
public class TestSceneSkinnableAccuracyCounter : SkinnableTestScene
|
||||||
{
|
{
|
||||||
private IEnumerable<SkinnableAccuracyCounter> accuracyCounters => CreatedDrawables.OfType<SkinnableAccuracyCounter>();
|
|
||||||
|
|
||||||
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
private ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||||
|
|
||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
public void SetUpSteps()
|
public void SetUpSteps()
|
||||||
{
|
{
|
||||||
AddStep("Create combo counters", () => SetContents(() =>
|
AddStep("Set initial accuracy", () => scoreProcessor.Accuracy.Value = 1);
|
||||||
{
|
AddStep("Create accuracy counters", () => SetContents(() => new SkinnableAccuracyCounter()));
|
||||||
var accuracyCounter = new SkinnableAccuracyCounter();
|
|
||||||
|
|
||||||
accuracyCounter.Current.Value = 1;
|
|
||||||
|
|
||||||
return accuracyCounter;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestChangingAccuracy()
|
public void TestChangingAccuracy()
|
||||||
{
|
{
|
||||||
AddStep(@"Reset all", delegate
|
AddStep(@"Reset all", () => scoreProcessor.Accuracy.Value = 1);
|
||||||
{
|
|
||||||
foreach (var s in accuracyCounters)
|
|
||||||
s.Current.Value = 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep(@"Hit! :D", delegate
|
AddStep(@"Miss :(", () => scoreProcessor.Accuracy.Value -= 0.023);
|
||||||
{
|
|
||||||
foreach (var s in accuracyCounters)
|
|
||||||
s.Current.Value -= 0.023f;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,11 @@
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
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);
|
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.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
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()
|
public SkinnableAccuracyCounter()
|
||||||
: base(new HUDSkinComponent(HUDSkinComponents.AccuracyCounter), _ => new DefaultAccuracyCounter())
|
: base(new HUDSkinComponent(HUDSkinComponents.AccuracyCounter), _ => new DefaultAccuracyCounter())
|
||||||
{
|
{
|
||||||
CentreComponent = false;
|
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)
|
protected virtual void BindScoreProcessor(ScoreProcessor processor)
|
||||||
{
|
{
|
||||||
AccuracyCounter?.Current.BindTo(processor.Accuracy);
|
|
||||||
|
|
||||||
if (HealthDisplay is IHealthDisplay shd)
|
if (HealthDisplay is IHealthDisplay shd)
|
||||||
{
|
{
|
||||||
processor.NewJudgement += judgement =>
|
processor.NewJudgement += judgement =>
|
||||||
|
@ -4,14 +4,13 @@
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
{
|
{
|
||||||
public class LegacyAccuracyCounter : PercentageCounter, IAccuracyCounter, ISkinnableComponent
|
public class LegacyAccuracyCounter : GameplayAccuracyCounter, ISkinnableComponent
|
||||||
{
|
{
|
||||||
private readonly ISkin skin;
|
private readonly ISkin skin;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user