mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Update ComboCounter
components to use DI to attach data source
This commit is contained in:
@ -4,9 +4,11 @@
|
||||
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
|
||||
@ -17,31 +19,21 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
||||
|
||||
[Cached]
|
||||
private ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("Create combo counters", () => SetContents(() =>
|
||||
{
|
||||
var comboCounter = new SkinnableComboCounter();
|
||||
comboCounter.Current.Value = 1;
|
||||
return comboCounter;
|
||||
}));
|
||||
AddStep("Create combo counters", () => SetContents(() => new SkinnableComboCounter()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestComboCounterIncrementing()
|
||||
{
|
||||
AddRepeatStep("increase combo", () =>
|
||||
{
|
||||
foreach (var counter in comboCounters)
|
||||
counter.Current.Value++;
|
||||
}, 10);
|
||||
AddRepeatStep("increase combo", () => scoreProcessor.Combo.Value++, 10);
|
||||
|
||||
AddStep("reset combo", () =>
|
||||
{
|
||||
foreach (var counter in comboCounters)
|
||||
counter.Current.Value = 0;
|
||||
});
|
||||
AddStep("reset combo", () => scoreProcessor.Combo.Value = 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK.Input;
|
||||
|
||||
@ -19,6 +20,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
private HUDOverlay hudOverlay;
|
||||
|
||||
[Cached]
|
||||
private ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||
|
||||
// best way to check without exposing.
|
||||
private Drawable hideTarget => hudOverlay.KeyCounter;
|
||||
private FillFlowContainer<KeyCounter> keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<KeyCounter>>().First();
|
||||
@ -31,9 +35,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
createNew();
|
||||
|
||||
AddRepeatStep("increase combo", () => { hudOverlay.ComboCounter.Current.Value++; }, 10);
|
||||
AddRepeatStep("increase combo", () => { scoreProcessor.Combo.Value++; }, 10);
|
||||
|
||||
AddStep("reset combo", () => { hudOverlay.ComboCounter.Current.Value = 0; });
|
||||
AddStep("reset combo", () => { scoreProcessor.Combo.Value = 0; });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -139,12 +143,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
AddStep("create overlay", () =>
|
||||
{
|
||||
hudOverlay = new HUDOverlay(null, null, null, Array.Empty<Mod>());
|
||||
hudOverlay = new HUDOverlay(scoreProcessor, null, null, Array.Empty<Mod>());
|
||||
|
||||
// Add any key just to display the key counter visually.
|
||||
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
|
||||
|
||||
hudOverlay.ComboCounter.Current.Value = 1;
|
||||
scoreProcessor.Combo.Value = 1;
|
||||
|
||||
action?.Invoke(hudOverlay);
|
||||
|
||||
|
@ -14,6 +14,7 @@ using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK.Input;
|
||||
|
||||
@ -23,6 +24,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
private HUDOverlay hudOverlay;
|
||||
|
||||
[Cached]
|
||||
private ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||
|
||||
private IEnumerable<HUDOverlay> hudOverlays => CreatedDrawables.OfType<HUDOverlay>();
|
||||
|
||||
// best way to check without exposing.
|
||||
@ -37,17 +41,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
createNew();
|
||||
|
||||
AddRepeatStep("increase combo", () =>
|
||||
{
|
||||
foreach (var hud in hudOverlays)
|
||||
hud.ComboCounter.Current.Value++;
|
||||
}, 10);
|
||||
AddRepeatStep("increase combo", () => scoreProcessor.Combo.Value++, 10);
|
||||
|
||||
AddStep("reset combo", () =>
|
||||
{
|
||||
foreach (var hud in hudOverlays)
|
||||
hud.ComboCounter.Current.Value = 0;
|
||||
});
|
||||
AddStep("reset combo", () => scoreProcessor.Combo.Value = 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -80,13 +76,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
SetContents(() =>
|
||||
{
|
||||
hudOverlay = new HUDOverlay(null, null, null, Array.Empty<Mod>());
|
||||
hudOverlay = new HUDOverlay(scoreProcessor, null, null, Array.Empty<Mod>());
|
||||
|
||||
// Add any key just to display the key counter visually.
|
||||
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
|
||||
|
||||
hudOverlay.ComboCounter.Current.Value = 1;
|
||||
|
||||
action?.Invoke(hudOverlay);
|
||||
|
||||
return hudOverlay;
|
||||
|
@ -7,6 +7,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
@ -24,7 +25,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours) => Colour = colours.BlueLighter;
|
||||
private void load(OsuColour colours, ScoreProcessor scoreProcessor)
|
||||
{
|
||||
Colour = colours.BlueLighter;
|
||||
Current.BindTo(scoreProcessor.Combo);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
|
||||
@ -79,7 +80,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(ScoreProcessor scoreProcessor)
|
||||
{
|
||||
InternalChildren = new[]
|
||||
{
|
||||
@ -95,7 +96,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
},
|
||||
};
|
||||
|
||||
Current.ValueChanged += combo => updateCount(combo.NewValue == 0);
|
||||
Current.BindTo(scoreProcessor.Combo);
|
||||
Current.BindValueChanged(combo => updateCount(combo.NewValue == 0), true);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
@ -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 SkinnableComboCounter : SkinnableDrawable, IComboCounter
|
||||
public class SkinnableComboCounter : SkinnableDrawable
|
||||
{
|
||||
public Bindable<int> Current { get; } = new Bindable<int>();
|
||||
|
||||
public SkinnableComboCounter()
|
||||
: base(new HUDSkinComponent(HUDSkinComponents.ComboCounter), skinComponent => new DefaultComboCounter())
|
||||
{
|
||||
CentreComponent = false;
|
||||
}
|
||||
|
||||
private IComboCounter skinnedCounter;
|
||||
|
||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||
{
|
||||
base.SkinChanged(skin, allowFallback);
|
||||
|
||||
skinnedCounter = Drawable as IComboCounter;
|
||||
skinnedCounter?.Current.BindTo(Current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ namespace osu.Game.Screens.Play
|
||||
public float TopScoringElementsHeight { get; private set; }
|
||||
|
||||
public readonly KeyCounterDisplay KeyCounter;
|
||||
public readonly SkinnableComboCounter ComboCounter;
|
||||
public readonly SkinnableScoreCounter ScoreCounter;
|
||||
public readonly SkinnableAccuracyCounter AccuracyCounter;
|
||||
public readonly SkinnableHealthDisplay HealthDisplay;
|
||||
@ -106,7 +105,7 @@ namespace osu.Game.Screens.Play
|
||||
HealthDisplay = CreateHealthDisplay(),
|
||||
AccuracyCounter = CreateAccuracyCounter(),
|
||||
ScoreCounter = CreateScoreCounter(),
|
||||
ComboCounter = CreateComboCounter(),
|
||||
CreateComboCounter(),
|
||||
HitErrorDisplay = CreateHitErrorDisplayOverlay(),
|
||||
}
|
||||
},
|
||||
@ -276,13 +275,13 @@ namespace osu.Game.Screens.Play
|
||||
Progress.BindDrawableRuleset(drawableRuleset);
|
||||
}
|
||||
|
||||
protected virtual SkinnableAccuracyCounter CreateAccuracyCounter() => new SkinnableAccuracyCounter();
|
||||
protected SkinnableAccuracyCounter CreateAccuracyCounter() => new SkinnableAccuracyCounter();
|
||||
|
||||
protected virtual SkinnableScoreCounter CreateScoreCounter() => new SkinnableScoreCounter();
|
||||
protected SkinnableScoreCounter CreateScoreCounter() => new SkinnableScoreCounter();
|
||||
|
||||
protected virtual SkinnableComboCounter CreateComboCounter() => new SkinnableComboCounter();
|
||||
protected SkinnableComboCounter CreateComboCounter() => new SkinnableComboCounter();
|
||||
|
||||
protected virtual SkinnableHealthDisplay CreateHealthDisplay() => new SkinnableHealthDisplay();
|
||||
protected SkinnableHealthDisplay CreateHealthDisplay() => new SkinnableHealthDisplay();
|
||||
|
||||
protected virtual FailingLayer CreateFailingLayer() => new FailingLayer
|
||||
{
|
||||
@ -323,7 +322,6 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
ScoreCounter?.Current.BindTo(processor.TotalScore);
|
||||
AccuracyCounter?.Current.BindTo(processor.Accuracy);
|
||||
ComboCounter?.Current.BindTo(processor.Combo);
|
||||
|
||||
if (HealthDisplay is IHealthDisplay shd)
|
||||
{
|
||||
|
@ -202,6 +202,8 @@ namespace osu.Game.Screens.Play
|
||||
ScoreProcessor.ApplyBeatmap(playableBeatmap);
|
||||
ScoreProcessor.Mods.BindTo(Mods);
|
||||
|
||||
dependencies.CacheAs(ScoreProcessor);
|
||||
|
||||
HealthProcessor = ruleset.CreateHealthProcessor(playableBeatmap.HitObjects[0].StartTime);
|
||||
HealthProcessor.ApplyBeatmap(playableBeatmap);
|
||||
|
||||
|
Reference in New Issue
Block a user