osu/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs

108 lines
3.8 KiB
C#
Raw Normal View History

2019-11-04 16:56:09 +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.
2019-12-06 11:14:56 +00:00
using System;
2019-11-04 16:56:09 +00:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
2019-11-04 16:56:09 +00:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Tests.Visual.UserInterface
{
2019-12-06 09:57:11 +00:00
public class TestSceneModSettings : OsuTestScene
2019-11-04 16:56:09 +00:00
{
private TestModSelectOverlay modSelect;
[BackgroundDependencyLoader]
private void load()
{
Add(modSelect = new TestModSelectOverlay
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
});
2019-12-06 09:57:11 +00:00
var testMod = new TestModCustomisable1();
2019-11-04 16:56:09 +00:00
AddStep("open", modSelect.Show);
2019-12-06 09:57:11 +00:00
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
2019-12-06 10:04:55 +00:00
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
2019-11-04 16:56:09 +00:00
AddStep("select mod", () => modSelect.SelectMod(testMod));
2019-12-06 09:57:11 +00:00
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
2019-11-04 16:56:09 +00:00
AddStep("deselect mod", () => modSelect.SelectMod(testMod));
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
}
private class TestModSelectOverlay : ModSelectOverlay
{
public new Container ModSettingsContainer => base.ModSettingsContainer;
2019-12-06 09:57:11 +00:00
public new TriangleButton CustomiseButton => base.CustomiseButton;
2019-11-04 16:56:09 +00:00
2019-12-06 10:04:55 +00:00
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
2019-11-04 16:56:09 +00:00
public void SelectMod(Mod mod) =>
ModSectionsContainer.Children.Single(s => s.ModType == mod.Type)
.ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1);
2019-11-04 16:56:09 +00:00
protected override void LoadComplete()
{
base.LoadComplete();
foreach (var section in ModSectionsContainer)
{
2019-11-04 16:56:09 +00:00
if (section.ModType == ModType.Conversion)
{
section.Mods = new Mod[]
{
2019-12-06 09:57:11 +00:00
new TestModCustomisable1(),
new TestModCustomisable2()
};
}
2019-11-04 16:56:09 +00:00
else
2019-12-06 11:14:56 +00:00
section.Mods = Array.Empty<Mod>();
}
2019-11-04 16:56:09 +00:00
}
}
2019-12-06 09:57:11 +00:00
private class TestModCustomisable1 : TestModCustomisable
2019-11-04 16:56:09 +00:00
{
2019-12-06 09:57:11 +00:00
public override string Name => "Customisable Mod 1";
2019-11-04 16:56:09 +00:00
public override string Acronym => "CM1";
}
2019-11-04 16:56:09 +00:00
2019-12-06 09:57:11 +00:00
private class TestModCustomisable2 : TestModCustomisable
{
2019-12-06 09:57:11 +00:00
public override string Name => "Customisable Mod 2";
public override string Acronym => "CM2";
}
2019-12-06 09:57:11 +00:00
private abstract class TestModCustomisable : Mod, IApplicableMod
{
2019-11-04 16:56:09 +00:00
public override double ScoreMultiplier => 1.0;
public override ModType Type => ModType.Conversion;
[SettingSource("Sample float", "Change something for a mod")]
public BindableFloat SliderBindable { get; } = new BindableFloat
2019-11-04 16:56:09 +00:00
{
MinValue = 0,
MaxValue = 10,
Default = 5,
Value = 7
2019-11-04 16:56:09 +00:00
};
[SettingSource("Sample bool", "Clicking this changes a setting")]
public BindableBool TickBindable { get; } = new BindableBool();
2019-11-04 16:56:09 +00:00
}
}
}