mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 16:42:57 +08:00
Merge pull request #12670 from peppy/skin-components-bind-outwards
This commit is contained in:
commit
d5efab0648
@ -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);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
@ -17,6 +18,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
public class TestSceneSkinEditorMultipleSkins : SkinnableTestScene
|
||||
{
|
||||
[Cached]
|
||||
private readonly ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
@ -28,8 +32,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
var working = CreateWorkingBeatmap(ruleset.RulesetInfo);
|
||||
var beatmap = working.GetPlayableBeatmap(ruleset.RulesetInfo);
|
||||
|
||||
ScoreProcessor scoreProcessor = new ScoreProcessor();
|
||||
|
||||
var drawableRuleset = ruleset.CreateDrawableRulesetWith(beatmap);
|
||||
|
||||
var hudOverlay = new HUDOverlay(scoreProcessor, null, drawableRuleset, Array.Empty<Mod>())
|
||||
@ -40,7 +42,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
// 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;
|
||||
|
||||
return new Container
|
||||
{
|
||||
|
@ -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,11 +7,12 @@ 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
|
||||
{
|
||||
public class DefaultComboCounter : RollingCounter<int>, IComboCounter, ISkinnableComponent
|
||||
public class DefaultComboCounter : RollingCounter<int>, ISkinnableComponent
|
||||
{
|
||||
private readonly Vector2 offset = new Vector2(20, 5);
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
@ -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 combo counter.
|
||||
/// </summary>
|
||||
public interface IComboCounter : IDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The current combo to be displayed.
|
||||
/// </summary>
|
||||
Bindable<int> Current { get; }
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
@ -14,7 +15,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// <summary>
|
||||
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
|
||||
/// </summary>
|
||||
public class LegacyComboCounter : CompositeDrawable, IComboCounter, ISkinnableComponent
|
||||
public class LegacyComboCounter : CompositeDrawable, ISkinnableComponent
|
||||
{
|
||||
public Bindable<int> Current { get; } = new BindableInt { MinValue = 0, };
|
||||
|
||||
@ -79,7 +80,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(ScoreProcessor scoreProcessor)
|
||||
{
|
||||
InternalChildren = new[]
|
||||
{
|
||||
@ -95,7 +96,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
},
|
||||
};
|
||||
|
||||
Current.ValueChanged += combo => updateCount(combo.NewValue == 0);
|
||||
Current.BindTo(scoreProcessor.Combo);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -109,7 +110,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
popOutCount.Origin = Origin;
|
||||
popOutCount.Anchor = Anchor;
|
||||
|
||||
updateCount(false);
|
||||
Current.BindValueChanged(combo => updateCount(combo.NewValue == 0), true);
|
||||
}
|
||||
|
||||
private void updateCount(bool rolling)
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -203,6 +203,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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user