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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
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;
|
2020-07-17 15:54:30 +08:00
|
|
|
using osu.Framework.Graphics.OpenGL.Textures;
|
2019-08-30 13:44:36 +08: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 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;
|
|
|
|
using osu.Game.Skinning;
|
2019-11-21 17:50:54 +08:00
|
|
|
using osu.Game.Storyboards;
|
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;
|
|
|
|
|
|
|
|
var skinnable = firstObject.ApproachCircle.Child as SkinnableDrawable;
|
|
|
|
|
|
|
|
if (skin == null && skinnable?.Drawable is Sprite)
|
|
|
|
// 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-10 21:36:27 +08:00
|
|
|
protected override ISkin GetPlayerSkin() => 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
|
|
|
}
|
|
|
|
|
|
|
|
public class TestSource : ISkinSource
|
|
|
|
{
|
|
|
|
private readonly string identifier;
|
|
|
|
|
|
|
|
public TestSource(string identifier)
|
|
|
|
{
|
|
|
|
this.identifier = identifier;
|
|
|
|
}
|
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
public Drawable GetDrawableComponent(ISkinComponent component)
|
2019-08-30 13:44:36 +08:00
|
|
|
{
|
|
|
|
if (!enabled) return null;
|
|
|
|
|
2020-11-12 16:58:39 +08:00
|
|
|
if (component is OsuSkinComponent osuComponent && osuComponent.Component == OsuSkinComponents.SliderBody)
|
|
|
|
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-05-31 16:25:21 +08:00
|
|
|
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => null;
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|