mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +08:00
Add and consume skinnable score counter
This commit is contained in:
parent
219cbec6bd
commit
e1da64398e
@ -16,7 +16,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
int numerator = 0, denominator = 0;
|
int numerator = 0, denominator = 0;
|
||||||
|
|
||||||
ScoreCounter score = new DefaultScoreCounter()
|
ScoreCounter score = new DefaultScoreCounter
|
||||||
{
|
{
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
// 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.Testing;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Screens.Play.HUD;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
|
{
|
||||||
|
public class TestSceneSkinnableScoreCounter : SkinnableTestScene
|
||||||
|
{
|
||||||
|
private IEnumerable<SkinnableScoreCounter> scoreCounters => CreatedDrawables.OfType<SkinnableScoreCounter>();
|
||||||
|
|
||||||
|
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("Create combo counters", () => SetContents(() =>
|
||||||
|
{
|
||||||
|
var comboCounter = new SkinnableScoreCounter();
|
||||||
|
comboCounter.Current.Value = 1;
|
||||||
|
return comboCounter;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestScoreCounterIncrementing()
|
||||||
|
{
|
||||||
|
AddStep(@"Reset all", delegate
|
||||||
|
{
|
||||||
|
foreach (var s in scoreCounters)
|
||||||
|
s.Current.Value = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep(@"Hit! :D", delegate
|
||||||
|
{
|
||||||
|
foreach (var s in scoreCounters)
|
||||||
|
s.Current.Value += 300;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
osu.Game/Screens/Play/HUD/IScoreCounter.cs
Normal file
19
osu.Game/Screens/Play/HUD/IScoreCounter.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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 score counter.
|
||||||
|
/// </summary>
|
||||||
|
public interface IScoreCounter : IDrawable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The current score to be displayed.
|
||||||
|
/// </summary>
|
||||||
|
Bindable<double> Current { get; }
|
||||||
|
}
|
||||||
|
}
|
29
osu.Game/Screens/Play/HUD/SkinnableScoreCounter.cs
Normal file
29
osu.Game/Screens/Play/HUD/SkinnableScoreCounter.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 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 SkinnableScoreCounter : SkinnableDrawable, IScoreCounter
|
||||||
|
{
|
||||||
|
public Bindable<double> Current { get; } = new Bindable<double>();
|
||||||
|
|
||||||
|
public SkinnableScoreCounter()
|
||||||
|
: base(new HUDSkinComponent(HUDSkinComponents.ScoreCounter), _ => new DefaultScoreCounter())
|
||||||
|
{
|
||||||
|
CentreComponent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IScoreCounter skinnedCounter;
|
||||||
|
|
||||||
|
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||||
|
{
|
||||||
|
base.SkinChanged(skin, allowFallback);
|
||||||
|
|
||||||
|
skinnedCounter = Drawable as IScoreCounter;
|
||||||
|
skinnedCounter?.Current.BindTo(Current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public readonly KeyCounterDisplay KeyCounter;
|
public readonly KeyCounterDisplay KeyCounter;
|
||||||
public readonly SkinnableComboCounter ComboCounter;
|
public readonly SkinnableComboCounter ComboCounter;
|
||||||
public readonly ScoreCounter ScoreCounter;
|
public readonly SkinnableScoreCounter ScoreCounter;
|
||||||
public readonly RollingCounter<double> AccuracyCounter;
|
public readonly RollingCounter<double> AccuracyCounter;
|
||||||
public readonly HealthDisplay HealthDisplay;
|
public readonly HealthDisplay HealthDisplay;
|
||||||
public readonly SongProgress Progress;
|
public readonly SongProgress Progress;
|
||||||
@ -269,11 +269,7 @@ namespace osu.Game.Screens.Play
|
|||||||
Margin = new MarginPadding { Top = 5, Right = 20 },
|
Margin = new MarginPadding { Top = 5, Right = 20 },
|
||||||
};
|
};
|
||||||
|
|
||||||
protected virtual ScoreCounter CreateScoreCounter() => new ScoreCounter(6)
|
protected virtual SkinnableScoreCounter CreateScoreCounter() => new SkinnableScoreCounter();
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
};
|
|
||||||
|
|
||||||
protected virtual SkinnableComboCounter CreateComboCounter() => new SkinnableComboCounter();
|
protected virtual SkinnableComboCounter CreateComboCounter() => new SkinnableComboCounter();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ namespace osu.Game.Skinning
|
|||||||
public enum HUDSkinComponents
|
public enum HUDSkinComponents
|
||||||
{
|
{
|
||||||
ComboCounter,
|
ComboCounter,
|
||||||
ScoreText
|
ScoreText,
|
||||||
|
ScoreCounter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
osu.Game/Skinning/LegacyScoreCounter.cs
Normal file
42
osu.Game/Skinning/LegacyScoreCounter.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
public class LegacyScoreCounter : ScoreCounter
|
||||||
|
{
|
||||||
|
private readonly ISkin skin;
|
||||||
|
|
||||||
|
protected override double RollingDuration => 1000;
|
||||||
|
protected override Easing RollingEasing => Easing.Out;
|
||||||
|
|
||||||
|
public new Bindable<double> Current { get; } = new Bindable<double>();
|
||||||
|
|
||||||
|
public LegacyScoreCounter(ISkin skin)
|
||||||
|
: base(6)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight;
|
||||||
|
Origin = Anchor.TopRight;
|
||||||
|
|
||||||
|
this.skin = skin;
|
||||||
|
|
||||||
|
// base class uses int for display, but externally we bind to ScoreProcesssor as a double for now.
|
||||||
|
Current.BindValueChanged(v => base.Current.Value = (int)v.NewValue);
|
||||||
|
|
||||||
|
Margin = new MarginPadding { Bottom = 10, Left = 10 };
|
||||||
|
Scale = new Vector2(1.2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected sealed override OsuSpriteText CreateSpriteText() =>
|
||||||
|
new LegacySpriteText(skin, "score" /*, true*/)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -335,6 +335,9 @@ namespace osu.Game.Skinning
|
|||||||
case HUDSkinComponents.ComboCounter:
|
case HUDSkinComponents.ComboCounter:
|
||||||
return new LegacyComboCounter();
|
return new LegacyComboCounter();
|
||||||
|
|
||||||
|
case HUDSkinComponents.ScoreCounter:
|
||||||
|
return new LegacyScoreCounter(this);
|
||||||
|
|
||||||
case HUDSkinComponents.ScoreText:
|
case HUDSkinComponents.ScoreText:
|
||||||
const string font = "score";
|
const string font = "score";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user