mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Merge pull request #24475 from nanashi-1/add-rank-display
Add skinnable rank display
This commit is contained in:
commit
030acb153a
BIN
osu.Game.Tests/Resources/Archives/modified-classic-20230809.osk
Normal file
BIN
osu.Game.Tests/Resources/Archives/modified-classic-20230809.osk
Normal file
Binary file not shown.
BIN
osu.Game.Tests/Resources/Archives/modified-default-20230809.osk
Normal file
BIN
osu.Game.Tests/Resources/Archives/modified-default-20230809.osk
Normal file
Binary file not shown.
@ -62,6 +62,10 @@ namespace osu.Game.Tests.Skins
|
|||||||
"Archives/modified-argon-20231108.osk",
|
"Archives/modified-argon-20231108.osk",
|
||||||
// Covers "Argon" performance points counter
|
// Covers "Argon" performance points counter
|
||||||
"Archives/modified-argon-20240305.osk",
|
"Archives/modified-argon-20240305.osk",
|
||||||
|
// Covers default rank display
|
||||||
|
"Archives/modified-default-20230809.osk",
|
||||||
|
// Covers legacy rank display
|
||||||
|
"Archives/modified-classic-20230809.osk"
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
using osu.Game.Scoring;
|
||||||
|
using osu.Game.Screens.Play.HUD;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
|
{
|
||||||
|
public partial class TestSceneSkinnableRankDisplay : SkinnableHUDComponentTestScene
|
||||||
|
{
|
||||||
|
[Cached]
|
||||||
|
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
||||||
|
|
||||||
|
private Bindable<ScoreRank> rank => (Bindable<ScoreRank>)scoreProcessor.Rank;
|
||||||
|
|
||||||
|
protected override Drawable CreateDefaultImplementation() => new DefaultRankDisplay();
|
||||||
|
|
||||||
|
protected override Drawable CreateLegacyImplementation() => new LegacyRankDisplay();
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestChangingRank()
|
||||||
|
{
|
||||||
|
AddStep("Set rank to SS Hidden", () => rank.Value = ScoreRank.XH);
|
||||||
|
AddStep("Set rank to SS", () => rank.Value = ScoreRank.X);
|
||||||
|
AddStep("Set rank to S Hidden", () => rank.Value = ScoreRank.SH);
|
||||||
|
AddStep("Set rank to S", () => rank.Value = ScoreRank.S);
|
||||||
|
AddStep("Set rank to A", () => rank.Value = ScoreRank.A);
|
||||||
|
AddStep("Set rank to B", () => rank.Value = ScoreRank.B);
|
||||||
|
AddStep("Set rank to C", () => rank.Value = ScoreRank.C);
|
||||||
|
AddStep("Set rank to D", () => rank.Value = ScoreRank.D);
|
||||||
|
AddStep("Set rank to F", () => rank.Value = ScoreRank.F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,19 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
#nullable disable
|
using System;
|
||||||
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Transforms;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
namespace osu.Game.Online.Leaderboards
|
namespace osu.Game.Online.Leaderboards
|
||||||
{
|
{
|
||||||
public partial class UpdateableRank : ModelBackedDrawable<ScoreRank?>
|
public partial class UpdateableRank : ModelBackedDrawable<ScoreRank?>
|
||||||
{
|
{
|
||||||
|
protected override double TransformDuration => 600;
|
||||||
|
protected override bool TransformImmediately => true;
|
||||||
|
|
||||||
public ScoreRank? Rank
|
public ScoreRank? Rank
|
||||||
{
|
{
|
||||||
get => Model;
|
get => Model;
|
||||||
@ -22,7 +25,17 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
Rank = rank;
|
Rank = rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateDrawable(ScoreRank? rank)
|
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad)
|
||||||
|
{
|
||||||
|
return base.CreateDelayedLoadWrapper(createContentFunc, timeBeforeLoad)
|
||||||
|
.With(w =>
|
||||||
|
{
|
||||||
|
w.Anchor = Anchor.Centre;
|
||||||
|
w.Origin = Anchor.Centre;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable? CreateDrawable(ScoreRank? rank)
|
||||||
{
|
{
|
||||||
if (rank.HasValue)
|
if (rank.HasValue)
|
||||||
{
|
{
|
||||||
@ -35,5 +48,18 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override TransformSequence<Drawable> ApplyShowTransforms(Drawable drawable)
|
||||||
|
{
|
||||||
|
drawable.ScaleTo(1);
|
||||||
|
return base.ApplyShowTransforms(drawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override TransformSequence<Drawable> ApplyHideTransforms(Drawable drawable)
|
||||||
|
{
|
||||||
|
drawable.ScaleTo(1.8f, TransformDuration, Easing.Out);
|
||||||
|
|
||||||
|
return base.ApplyHideTransforms(drawable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
osu.Game/Screens/Play/HUD/DefaultRankDisplay.cs
Normal file
45
osu.Game/Screens/Play/HUD/DefaultRankDisplay.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// 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.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Online.Leaderboards;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Play.HUD
|
||||||
|
{
|
||||||
|
public partial class DefaultRankDisplay : Container, ISerialisableDrawable
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
||||||
|
|
||||||
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
|
||||||
|
private readonly UpdateableRank rank;
|
||||||
|
|
||||||
|
public DefaultRankDisplay()
|
||||||
|
{
|
||||||
|
Size = new Vector2(70, 35);
|
||||||
|
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
rank = new UpdateableRank(Scoring.ScoreRank.X)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
rank.Rank = scoreProcessor.Rank.Value;
|
||||||
|
|
||||||
|
scoreProcessor.Rank.BindValueChanged(v => rank.Rank = v.NewValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
osu.Game/Skinning/LegacyRankDisplay.cs
Normal file
63
osu.Game/Skinning/LegacyRankDisplay.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// 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.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
public partial class LegacyRankDisplay : CompositeDrawable, ISerialisableDrawable
|
||||||
|
{
|
||||||
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private ISkinSource source { get; set; } = null!;
|
||||||
|
|
||||||
|
private readonly Sprite rank;
|
||||||
|
|
||||||
|
public LegacyRankDisplay()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
AddInternal(rank = new Sprite
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
scoreProcessor.Rank.BindValueChanged(v =>
|
||||||
|
{
|
||||||
|
var texture = source.GetTexture($"ranking-{v.NewValue}-small");
|
||||||
|
|
||||||
|
rank.Texture = texture;
|
||||||
|
|
||||||
|
if (texture != null)
|
||||||
|
{
|
||||||
|
var transientRank = new Sprite
|
||||||
|
{
|
||||||
|
Texture = texture,
|
||||||
|
Blending = BlendingParameters.Additive,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
BypassAutoSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
AddInternal(transientRank);
|
||||||
|
transientRank.FadeOutFromOne(500, Easing.Out)
|
||||||
|
.ScaleTo(new Vector2(1.625f), 500, Easing.Out)
|
||||||
|
.Expire();
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
FinishTransforms(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user