mirror of https://github.com/ppy/osu
148 lines
5.6 KiB
C#
148 lines
5.6 KiB
C#
|
// 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.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using osu.Framework.Allocation;
|
|||
|
using osu.Framework.Audio;
|
|||
|
using osu.Framework.Bindables;
|
|||
|
using osu.Framework.IO.Stores;
|
|||
|
using osu.Framework.Testing;
|
|||
|
using osu.Game.Beatmaps;
|
|||
|
using osu.Game.Screens.Play;
|
|||
|
using osu.Game.Skinning;
|
|||
|
using osu.Game.Tests.Visual;
|
|||
|
using osuTK.Graphics;
|
|||
|
|
|||
|
namespace osu.Game.Tests.Beatmaps
|
|||
|
{
|
|||
|
public class LegacyBeatmapSkinColourTest : ScreenTestScene
|
|||
|
{
|
|||
|
protected readonly Bindable<bool> BeatmapSkins = new Bindable<bool>();
|
|||
|
protected readonly Bindable<bool> BeatmapColours = new Bindable<bool>();
|
|||
|
protected ExposedPlayer TestPlayer;
|
|||
|
protected WorkingBeatmap TestBeatmap;
|
|||
|
|
|||
|
public virtual void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin) => ConfigureTest(useBeatmapSkin, true, userHasCustomColours);
|
|||
|
|
|||
|
public virtual void TestBeatmapComboColoursOverride(bool useBeatmapSkin) => ConfigureTest(useBeatmapSkin, false, true);
|
|||
|
|
|||
|
public virtual void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin) => ConfigureTest(useBeatmapSkin, false, false);
|
|||
|
|
|||
|
public virtual void TestBeatmapNoComboColours(bool useBeatmapSkin, bool useBeatmapColour) => ConfigureTest(useBeatmapSkin, useBeatmapColour, false);
|
|||
|
|
|||
|
public virtual void TestBeatmapNoComboColoursSkinOverride(bool useBeatmapSkin, bool useBeatmapColour) => ConfigureTest(useBeatmapSkin, useBeatmapColour, true);
|
|||
|
|
|||
|
protected virtual void ConfigureTest(bool useBeatmapSkin, bool useBeatmapColours, bool userHasCustomColours)
|
|||
|
{
|
|||
|
configureSettings(useBeatmapSkin, useBeatmapColours);
|
|||
|
AddStep($"load {(((CustomSkinWorkingBeatmap)TestBeatmap).HasColours ? "coloured " : "")} beatmap", () => TestPlayer = LoadBeatmap(userHasCustomColours));
|
|||
|
AddUntilStep("wait for player load", () => TestPlayer.IsLoaded);
|
|||
|
}
|
|||
|
|
|||
|
private void configureSettings(bool beatmapSkins, bool beatmapColours)
|
|||
|
{
|
|||
|
AddStep($"{(beatmapSkins ? "enable" : "disable")} beatmap skins", () =>
|
|||
|
{
|
|||
|
BeatmapSkins.Value = beatmapSkins;
|
|||
|
});
|
|||
|
AddStep($"{(beatmapColours ? "enable" : "disable")} beatmap colours", () =>
|
|||
|
{
|
|||
|
BeatmapColours.Value = beatmapColours;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
protected virtual ExposedPlayer LoadBeatmap(bool userHasCustomColours)
|
|||
|
{
|
|||
|
ExposedPlayer player;
|
|||
|
|
|||
|
Beatmap.Value = TestBeatmap;
|
|||
|
|
|||
|
LoadScreen(player = CreateTestPlayer(userHasCustomColours));
|
|||
|
|
|||
|
return player;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual ExposedPlayer CreateTestPlayer(bool userHasCustomColours) => new ExposedPlayer(userHasCustomColours);
|
|||
|
|
|||
|
protected class ExposedPlayer : Player
|
|||
|
{
|
|||
|
protected readonly bool UserHasCustomColours;
|
|||
|
|
|||
|
public ExposedPlayer(bool userHasCustomColours)
|
|||
|
: base(new PlayerConfiguration
|
|||
|
{
|
|||
|
AllowPause = false,
|
|||
|
ShowResults = false,
|
|||
|
})
|
|||
|
{
|
|||
|
UserHasCustomColours = userHasCustomColours;
|
|||
|
}
|
|||
|
|
|||
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|||
|
{
|
|||
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|||
|
dependencies.CacheAs<ISkinSource>(new TestSkin(UserHasCustomColours));
|
|||
|
return dependencies;
|
|||
|
}
|
|||
|
|
|||
|
public IReadOnlyList<Color4> UsableComboColours =>
|
|||
|
GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>()
|
|||
|
.First()
|
|||
|
.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
|
|||
|
}
|
|||
|
|
|||
|
protected class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
|
|||
|
{
|
|||
|
public readonly bool HasColours;
|
|||
|
|
|||
|
public CustomSkinWorkingBeatmap(IBeatmap beatmap, AudioManager audio, bool hasColours)
|
|||
|
: base(beatmap, null, null, audio)
|
|||
|
{
|
|||
|
HasColours = hasColours;
|
|||
|
}
|
|||
|
|
|||
|
protected override ISkin GetSkin() => new TestBeatmapSkin(BeatmapInfo, HasColours);
|
|||
|
}
|
|||
|
|
|||
|
protected class TestBeatmapSkin : LegacyBeatmapSkin
|
|||
|
{
|
|||
|
public static Color4[] Colours { get; } =
|
|||
|
{
|
|||
|
new Color4(50, 100, 150, 255),
|
|||
|
new Color4(40, 80, 120, 255),
|
|||
|
};
|
|||
|
|
|||
|
public TestBeatmapSkin(BeatmapInfo beatmap, bool hasColours)
|
|||
|
: base(beatmap, new ResourceStore<byte[]>(), null)
|
|||
|
{
|
|||
|
if (hasColours)
|
|||
|
Configuration.AddComboColours(Colours);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected class TestSkin : LegacySkin, ISkinSource
|
|||
|
{
|
|||
|
public static Color4[] Colours { get; } =
|
|||
|
{
|
|||
|
new Color4(150, 100, 50, 255),
|
|||
|
new Color4(20, 20, 20, 255),
|
|||
|
};
|
|||
|
|
|||
|
public TestSkin(bool hasCustomColours)
|
|||
|
: base(new SkinInfo(), new ResourceStore<byte[]>(), null, string.Empty)
|
|||
|
{
|
|||
|
if (hasCustomColours)
|
|||
|
Configuration.AddComboColours(Colours);
|
|||
|
}
|
|||
|
|
|||
|
public event Action SourceChanged
|
|||
|
{
|
|||
|
add { }
|
|||
|
remove { }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|