2019-08-30 13:44:36 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-08-30 13:44:36 +08:00
|
|
|
using System;
|
2021-06-22 15:19:55 +08:00
|
|
|
using System.Collections.Generic;
|
2019-08-30 13:44:36 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-09-03 16:57:34 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-08-30 13:44:36 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Graphics;
|
2019-11-25 10:30:55 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-08-30 13:44:36 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2021-09-16 18:35:15 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2019-08-30 13:44:36 +08:00
|
|
|
using osu.Game.Skinning;
|
2019-11-21 17:50:54 +08:00
|
|
|
using osu.Game.Storyboards;
|
2021-06-22 15:48:03 +08:00
|
|
|
using osu.Game.Tests.Visual;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2020-04-17 15:32:12 +08:00
|
|
|
public class TestSceneSkinFallbacks : TestSceneOsuPlayer
|
2019-08-30 13:44:36 +08:00
|
|
|
{
|
|
|
|
private readonly TestSource testUserSkin;
|
2020-09-01 00:29:46 +08:00
|
|
|
private readonly TestSource testBeatmapSkin;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
|
|
|
public TestSceneSkinFallbacks()
|
|
|
|
{
|
|
|
|
testUserSkin = new TestSource("user");
|
2020-09-01 00:29:46 +08:00
|
|
|
testBeatmapSkin = new TestSource("beatmap");
|
2019-08-30 13:44:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBeatmapSkinDefault()
|
|
|
|
{
|
|
|
|
AddStep("enable user provider", () => testUserSkin.Enabled = true);
|
|
|
|
|
2021-03-17 15:10:16 +08:00
|
|
|
AddStep("enable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, true));
|
2019-08-30 13:44:36 +08:00
|
|
|
checkNextHitObject("beatmap");
|
|
|
|
|
2021-03-17 15:10:16 +08:00
|
|
|
AddStep("disable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, false));
|
2019-08-30 13:44:36 +08:00
|
|
|
checkNextHitObject("user");
|
|
|
|
|
|
|
|
AddStep("disable user provider", () => testUserSkin.Enabled = false);
|
|
|
|
checkNextHitObject(null);
|
|
|
|
}
|
|
|
|
|
2021-01-13 13:09:22 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapColourDefault()
|
|
|
|
{
|
|
|
|
AddStep("enable user provider", () => testUserSkin.Enabled = true);
|
|
|
|
|
2021-03-17 15:10:16 +08:00
|
|
|
AddStep("enable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, true));
|
|
|
|
AddStep("enable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, true));
|
2021-01-13 13:09:22 +08:00
|
|
|
checkNextHitObject("beatmap");
|
|
|
|
|
2021-03-17 15:10:16 +08:00
|
|
|
AddStep("enable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, true));
|
|
|
|
AddStep("disable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, false));
|
2021-01-13 13:09:22 +08:00
|
|
|
checkNextHitObject("beatmap");
|
|
|
|
|
2021-03-17 15:10:16 +08:00
|
|
|
AddStep("disable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, false));
|
|
|
|
AddStep("enable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, true));
|
2021-01-13 13:09:22 +08:00
|
|
|
checkNextHitObject("user");
|
|
|
|
|
2021-03-17 15:10:16 +08:00
|
|
|
AddStep("disable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, false));
|
|
|
|
AddStep("disable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, false));
|
2021-01-13 13:09:22 +08:00
|
|
|
checkNextHitObject("user");
|
|
|
|
|
|
|
|
AddStep("disable user provider", () => testUserSkin.Enabled = false);
|
|
|
|
checkNextHitObject(null);
|
|
|
|
}
|
|
|
|
|
2019-08-30 13:44:36 +08:00
|
|
|
private void checkNextHitObject(string skin) =>
|
|
|
|
AddUntilStep($"check skin from {skin}", () =>
|
|
|
|
{
|
2020-03-05 10:25:07 +08:00
|
|
|
var firstObject = Player.DrawableRuleset.Playfield.HitObjectContainer.AliveObjects.OfType<DrawableHitCircle>().FirstOrDefault();
|
2019-08-30 13:44:36 +08:00
|
|
|
|
|
|
|
if (firstObject == null)
|
|
|
|
return false;
|
|
|
|
|
2021-09-16 18:35:15 +08:00
|
|
|
var skinnable = firstObject.ApproachCircle;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
2021-09-16 18:35:15 +08:00
|
|
|
if (skin == null && skinnable?.Drawable is DefaultApproachCircle)
|
2019-08-30 13:44:36 +08:00
|
|
|
// check for default skin provider
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var text = skinnable?.Drawable as SpriteText;
|
|
|
|
|
|
|
|
return text?.Text == skin;
|
|
|
|
});
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private AudioManager audio { get; set; }
|
|
|
|
|
2021-06-22 15:48:03 +08:00
|
|
|
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new SkinProvidingPlayer(testUserSkin);
|
2019-08-30 13:44:36 +08:00
|
|
|
|
2019-11-21 17:50:54 +08:00
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, audio, testBeatmapSkin);
|
2019-08-30 13:44:36 +08:00
|
|
|
|
|
|
|
public class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
|
|
|
|
{
|
2020-09-01 00:29:46 +08:00
|
|
|
private readonly ISkinSource skin;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
2020-09-01 00:29:46 +08:00
|
|
|
public CustomSkinWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard, IFrameBasedClock frameBasedClock, AudioManager audio, ISkinSource skin)
|
2019-11-21 17:50:54 +08:00
|
|
|
: base(beatmap, storyboard, frameBasedClock, audio)
|
2019-08-30 13:44:36 +08:00
|
|
|
{
|
2020-08-29 20:47:26 +08:00
|
|
|
this.skin = skin;
|
2019-08-30 13:44:36 +08:00
|
|
|
}
|
|
|
|
|
2020-09-01 00:29:46 +08:00
|
|
|
protected override ISkin GetSkin() => skin;
|
2019-08-30 13:44:36 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 15:48:03 +08:00
|
|
|
public class SkinProvidingPlayer : TestPlayer
|
|
|
|
{
|
|
|
|
private readonly TestSource userSkin;
|
|
|
|
|
|
|
|
public SkinProvidingPlayer(TestSource userSkin)
|
|
|
|
{
|
|
|
|
this.userSkin = userSkin;
|
|
|
|
}
|
|
|
|
|
|
|
|
private DependencyContainer dependencies;
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
|
|
|
|
dependencies.CacheAs<ISkinSource>(userSkin);
|
|
|
|
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 13:44:36 +08:00
|
|
|
public class TestSource : ISkinSource
|
|
|
|
{
|
|
|
|
private readonly string identifier;
|
|
|
|
|
|
|
|
public TestSource(string identifier)
|
|
|
|
{
|
|
|
|
this.identifier = identifier;
|
|
|
|
}
|
|
|
|
|
2022-11-09 15:04:56 +08:00
|
|
|
public Drawable GetDrawableComponent(ISkinComponentLookup lookup)
|
2019-08-30 13:44:36 +08:00
|
|
|
{
|
|
|
|
if (!enabled) return null;
|
|
|
|
|
2022-11-09 15:04:56 +08:00
|
|
|
if (lookup is OsuSkinComponentLookup osuComponent && osuComponent.Component == OsuSkinComponents.SliderBody)
|
2020-11-12 16:58:39 +08:00
|
|
|
return null;
|
|
|
|
|
2019-11-25 10:30:55 +08:00
|
|
|
return new OsuSpriteText
|
2019-08-30 13:44:36 +08:00
|
|
|
{
|
|
|
|
Text = identifier,
|
|
|
|
Font = OsuFont.Default.With(size: 30),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-17 15:54:30 +08:00
|
|
|
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => null;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
2021-02-18 17:32:28 +08:00
|
|
|
public ISample GetSample(ISampleInfo sampleInfo) => null;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
2019-09-03 16:57:34 +08:00
|
|
|
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => null;
|
2021-06-10 21:36:27 +08:00
|
|
|
|
2021-06-22 17:02:21 +08:00
|
|
|
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : null;
|
2019-08-30 13:44:36 +08:00
|
|
|
|
2021-06-22 17:02:21 +08:00
|
|
|
public IEnumerable<ISkin> AllSources => new[] { this };
|
2021-06-22 15:19:55 +08:00
|
|
|
|
2019-08-30 13:44:36 +08:00
|
|
|
public event Action SourceChanged;
|
|
|
|
|
|
|
|
private bool enabled = true;
|
|
|
|
|
|
|
|
public bool Enabled
|
|
|
|
{
|
|
|
|
get => enabled;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
enabled = value;
|
|
|
|
SourceChanged?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|