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