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

181 lines
6.5 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-12-12 08:12:01 +00:00
using System.Collections.Generic;
2019-11-04 16:56:09 +00:00
using System.Linq;
2019-12-12 08:12:01 +00:00
using NUnit.Framework;
2019-11-04 16:56:09 +00:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-12-12 08:12:01 +00:00
using osu.Game.Beatmaps;
using osu.Game.Configuration;
2019-11-04 16:56:09 +00:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
2019-12-12 08:12:01 +00:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
2019-11-04 16:56:09 +00:00
using osu.Game.Rulesets.Mods;
2019-12-12 08:12:01 +00:00
using osu.Game.Rulesets.UI;
2019-11-04 16:56:09 +00:00
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;
2019-12-12 08:36:37 +00:00
private readonly Mod testCustomisableMod = new TestModCustomisable1();
2019-11-04 16:56:09 +00:00
2020-01-21 14:32:53 +00:00
private readonly Mod testCustomisableAutoOpenMod = new TestModCustomisable2();
2020-01-21 10:26:51 +00:00
2020-01-30 10:55:25 +00:00
[SetUp]
public void SetUp() => Schedule(() =>
{
SelectedMods.Value = Array.Empty<Mod>();
Ruleset.Value = new TestRulesetInfo();
});
2019-12-12 08:12:01 +00:00
[Test]
public void TestButtonShowsOnCustomisableMod()
{
createModSelect();
2020-02-09 13:39:27 +00:00
openModSelect();
2019-11-04 16:56:09 +00:00
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-12-12 08:12:01 +00:00
AddStep("select mod", () => modSelect.SelectMod(testCustomisableMod));
2019-12-06 09:57:11 +00:00
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
2019-12-12 08:12:01 +00:00
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableMod));
2019-11-04 16:56:09 +00:00
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
}
2019-12-12 08:12:01 +00:00
[Test]
public void TestButtonShowsOnModAlreadyAdded()
{
2019-12-13 12:45:38 +00:00
AddStep("set active mods", () => SelectedMods.Value = new List<Mod> { testCustomisableMod });
2019-12-12 08:12:01 +00:00
createModSelect();
2019-12-13 12:45:38 +00:00
AddAssert("mods still active", () => SelectedMods.Value.Count == 1);
2019-12-12 08:12:01 +00:00
2020-02-09 13:39:27 +00:00
openModSelect();
2019-12-12 08:12:01 +00:00
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
}
2020-01-21 10:26:51 +00:00
[Test]
public void TestCustomisationMenuVisibility()
2020-01-21 10:26:51 +00:00
{
createModSelect();
2020-02-09 13:39:27 +00:00
openModSelect();
2020-01-21 10:26:51 +00:00
2020-01-21 14:32:53 +00:00
AddAssert("Customisation closed", () => modSelect.ModSettingsContainer.Alpha == 0);
2020-01-21 10:26:51 +00:00
AddStep("select mod", () => modSelect.SelectMod(testCustomisableAutoOpenMod));
AddAssert("Customisation opened", () => modSelect.ModSettingsContainer.Alpha == 1);
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableAutoOpenMod));
AddAssert("Customisation closed", () => modSelect.ModSettingsContainer.Alpha == 0);
2020-01-21 10:26:51 +00:00
}
2019-12-12 08:12:01 +00:00
private void createModSelect()
{
AddStep("create mod select", () =>
{
Child = modSelect = new TestModSelectOverlay
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
2020-01-30 10:55:25 +00:00
SelectedMods = { BindTarget = SelectedMods }
2019-12-12 08:12:01 +00:00
};
});
}
2020-02-09 13:39:27 +00:00
private void openModSelect()
{
AddStep("open", () => modSelect.Show());
AddUntilStep("wait for ready", () => modSelect.State.Value == Visibility.Visible && modSelect.ButtonsLoaded);
}
2019-11-04 16:56:09 +00:00
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-12-12 08:12:01 +00:00
}
2019-11-04 16:56:09 +00:00
2019-12-12 08:12:01 +00:00
public class TestRulesetInfo : RulesetInfo
{
public override Ruleset CreateInstance() => new TestCustomisableModRuleset();
2019-11-04 16:56:09 +00:00
2019-12-14 18:01:37 +00:00
public TestRulesetInfo()
{
Available = true;
}
2019-12-12 08:12:01 +00:00
public class TestCustomisableModRuleset : Ruleset
{
public override IEnumerable<Mod> GetModsFor(ModType type)
{
2019-12-12 08:12:01 +00:00
if (type == ModType.Conversion)
{
2019-12-12 08:12:01 +00:00
return new Mod[]
{
2019-12-06 09:57:11 +00:00
new TestModCustomisable1(),
2020-01-21 14:32:53 +00:00
new TestModCustomisable2()
};
}
2019-12-12 08:12:01 +00:00
return Array.Empty<Mod>();
}
2019-12-12 08:12:01 +00:00
2019-12-13 12:45:38 +00:00
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new NotImplementedException();
2019-12-12 08:12:01 +00:00
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException();
2019-12-12 08:36:37 +00:00
public override string Description { get; } = "test";
public override string ShortName { get; } = "tst";
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";
2020-01-21 10:26:51 +00:00
public override bool RequiresConfiguration => true;
}
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
}
}
}