mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 12:25:04 +08:00
Add method for assigning arbitrary skins to player in test scenes
This commit is contained in:
parent
ef2c4fd0d8
commit
23d6c366ac
@ -10,6 +10,7 @@ using osu.Framework.Testing;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
@ -78,6 +79,8 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
Player = CreatePlayer(ruleset);
|
||||
Player.Skin = GetPlayerSkin();
|
||||
|
||||
LoadScreen(Player);
|
||||
}
|
||||
|
||||
@ -93,6 +96,11 @@ namespace osu.Game.Tests.Visual
|
||||
[NotNull]
|
||||
protected abstract Ruleset CreatePlayerRuleset();
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ISkin"/> to be put inside the <see cref="Player"/>'s ruleset skin providing container.
|
||||
/// </summary>
|
||||
protected virtual ISkin GetPlayerSkin() => null;
|
||||
|
||||
protected sealed override Ruleset CreateRuleset() => CreatePlayerRuleset();
|
||||
|
||||
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
|
||||
|
@ -3,13 +3,17 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
@ -18,6 +22,8 @@ namespace osu.Game.Tests.Visual
|
||||
/// </summary>
|
||||
public class TestPlayer : Player
|
||||
{
|
||||
public ISkin Skin { get; set; }
|
||||
|
||||
protected override bool PauseOnFocusLost { get; }
|
||||
|
||||
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
|
||||
@ -74,5 +80,27 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
ScoreProcessor.NewJudgement += r => Results.Add(r);
|
||||
}
|
||||
|
||||
protected override RulesetSkinProvidingContainer CreateRulesetSkinProvider(Ruleset ruleset, IBeatmap beatmap, ISkin beatmapSkin)
|
||||
=> new TestSkinProvidingContainer(Skin, ruleset, beatmap, beatmapSkin);
|
||||
|
||||
private class TestSkinProvidingContainer : RulesetSkinProvidingContainer
|
||||
{
|
||||
private readonly ISkin skin;
|
||||
|
||||
public TestSkinProvidingContainer(ISkin skin, Ruleset ruleset, IBeatmap beatmap, [CanBeNull] ISkin beatmapSkin)
|
||||
: base(ruleset, beatmap, beatmapSkin)
|
||||
{
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
protected override void UpdateSkins()
|
||||
{
|
||||
base.UpdateSkins();
|
||||
|
||||
if (skin != null)
|
||||
SkinSources.Insert(0, Ruleset.CreateLegacySkinProvider(skin, Beatmap));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user