osu/osu.Game.Tests/Visual/UserInterface/TestSceneModCustomizationSe...

118 lines
4.1 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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneModCustomizationSettings : OsuTestScene
{
private TestModSelectOverlay modSelect;
[BackgroundDependencyLoader]
private void load()
{
Add(modSelect = new TestModSelectOverlay
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
});
var testMod = new TestModCustomizable1();
2019-11-04 16:56:09 +00:00
AddStep("open", modSelect.Show);
AddAssert("button disabled", () => !modSelect.CustomizeButton.Enabled.Value);
AddStep("select mod", () => modSelect.SelectMod(testMod));
AddAssert("button enabled", () => modSelect.CustomizeButton.Enabled.Value);
AddStep("open customization", () => modSelect.CustomizeButton.Click());
AddStep("deselect mod", () => modSelect.SelectMod(testMod));
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
}
private class TestModSelectOverlay : ModSelectOverlay
{
public new Container ModSettingsContainer => base.ModSettingsContainer;
public new TriangleButton CustomizeButton => base.CustomizeButton;
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
public ModControlSection GetControlSection(Mod mod) =>
ModSettingsContent.Children.FirstOrDefault(s => s.Mod == mod);
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[]
{
new TestModCustomizable1(),
new TestModCustomizable2()
};
}
2019-11-04 16:56:09 +00:00
else
section.Mods = new Mod[] { };
}
2019-11-04 16:56:09 +00:00
}
}
private class TestModCustomizable1 : TestModCustomizable
2019-11-04 16:56:09 +00:00
{
public override string Name => "Customizable Mod 1";
2019-11-04 16:56:09 +00:00
public override string Acronym => "CM1";
}
2019-11-04 16:56:09 +00:00
private class TestModCustomizable2 : TestModCustomizable
{
public override string Name => "Customizable Mod 2";
public override string Acronym => "CM2";
}
private abstract class TestModCustomizable : Mod, IModHasSettings
{
2019-11-04 16:56:09 +00:00
public override double ScoreMultiplier => 1.0;
public override ModType Type => ModType.Conversion;
public readonly BindableFloat SliderBindable = new BindableFloat
2019-11-04 16:56:09 +00:00
{
MinValue = 0,
MaxValue = 10,
};
public readonly BindableBool TickBindable = new BindableBool();
2019-11-04 16:56:09 +00:00
public Drawable[] CreateControls() =>
new Drawable[]
2019-11-04 16:56:09 +00:00
{
new SettingsSlider<float>
{
LabelText = "Slider",
Bindable = SliderBindable
2019-11-04 16:56:09 +00:00
},
new SettingsCheckbox
{
LabelText = "Checkbox",
Bindable = TickBindable
2019-11-04 16:56:09 +00:00
}
};
}
}
}