1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 07:27:25 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs

153 lines
5.5 KiB
C#
Raw Normal View History

2019-11-05 00:56:09 +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.
2019-12-06 19:14:56 +08:00
using System;
2019-12-12 16:12:01 +08:00
using System.Collections.Generic;
2019-11-05 00:56:09 +08:00
using System.Linq;
2019-12-12 16:12:01 +08:00
using NUnit.Framework;
2019-11-05 00:56:09 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-12-12 16:12:01 +08:00
using osu.Game.Beatmaps;
using osu.Game.Configuration;
2019-11-05 00:56:09 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
2019-12-12 16:12:01 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
2019-11-05 00:56:09 +08:00
using osu.Game.Rulesets.Mods;
2019-12-12 16:12:01 +08:00
using osu.Game.Rulesets.UI;
2019-11-05 00:56:09 +08:00
namespace osu.Game.Tests.Visual.UserInterface
{
2019-12-06 17:57:11 +08:00
public class TestSceneModSettings : OsuTestScene
2019-11-05 00:56:09 +08:00
{
private TestModSelectOverlay modSelect;
2019-12-12 16:36:37 +08:00
private readonly Mod testCustomisableMod = new TestModCustomisable1();
2019-11-05 00:56:09 +08:00
2019-12-12 16:12:01 +08:00
[Test]
public void TestButtonShowsOnCustomisableMod()
{
createModSelect();
2019-11-05 00:56:09 +08:00
2019-12-12 16:12:01 +08:00
AddStep("open", () => modSelect.Show());
2019-12-06 17:57:11 +08:00
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
2019-12-06 18:04:55 +08:00
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
2019-12-12 16:12:01 +08:00
AddStep("select mod", () => modSelect.SelectMod(testCustomisableMod));
2019-12-06 17:57:11 +08:00
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
2019-12-12 16:12:01 +08:00
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableMod));
2019-11-05 00:56:09 +08:00
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
}
2019-12-12 16:12:01 +08:00
[Test]
public void TestButtonShowsOnModAlreadyAdded()
{
2019-12-13 20:45:38 +08:00
AddStep("set active mods", () => SelectedMods.Value = new List<Mod> { testCustomisableMod });
2019-12-12 16:12:01 +08:00
createModSelect();
2019-12-13 20:45:38 +08:00
AddAssert("mods still active", () => SelectedMods.Value.Count == 1);
2019-12-12 16:12:01 +08:00
AddStep("open", () => modSelect.Show());
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
}
private void createModSelect()
{
AddStep("create mod select", () =>
{
Ruleset.Value = new TestRulesetInfo();
Child = modSelect = new TestModSelectOverlay
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
};
});
}
2019-11-05 00:56:09 +08:00
private class TestModSelectOverlay : ModSelectOverlay
{
public new Container ModSettingsContainer => base.ModSettingsContainer;
2019-12-06 17:57:11 +08:00
public new TriangleButton CustomiseButton => base.CustomiseButton;
2019-11-05 00:56:09 +08:00
2019-12-06 18:04:55 +08:00
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
2019-11-05 00:56:09 +08: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 16:12:01 +08:00
}
2019-11-05 00:56:09 +08:00
2019-12-12 16:12:01 +08:00
public class TestRulesetInfo : RulesetInfo
{
public override Ruleset CreateInstance() => new TestCustomisableModRuleset();
2019-11-05 00:56:09 +08:00
2019-12-15 02:01:37 +08:00
public TestRulesetInfo()
{
Available = true;
}
2019-12-12 16:12:01 +08:00
public class TestCustomisableModRuleset : Ruleset
{
public override IEnumerable<Mod> GetModsFor(ModType type)
{
2019-12-12 16:12:01 +08:00
if (type == ModType.Conversion)
{
2019-12-12 16:12:01 +08:00
return new Mod[]
{
2019-12-06 17:57:11 +08:00
new TestModCustomisable1(),
new TestModCustomisable2()
};
}
2019-12-12 16:12:01 +08:00
return Array.Empty<Mod>();
}
2019-12-12 16:12:01 +08:00
2019-12-13 20:45:38 +08:00
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new NotImplementedException();
2019-12-12 16:12:01 +08:00
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException();
2019-12-12 16:36:37 +08:00
public override string Description { get; } = "test";
public override string ShortName { get; } = "tst";
2019-11-05 00:56:09 +08:00
}
}
2019-12-06 17:57:11 +08:00
private class TestModCustomisable1 : TestModCustomisable
2019-11-05 00:56:09 +08:00
{
2019-12-06 17:57:11 +08:00
public override string Name => "Customisable Mod 1";
2019-11-05 00:56:09 +08:00
public override string Acronym => "CM1";
}
2019-11-05 00:56:09 +08:00
2019-12-06 17:57:11 +08:00
private class TestModCustomisable2 : TestModCustomisable
{
2019-12-06 17:57:11 +08:00
public override string Name => "Customisable Mod 2";
public override string Acronym => "CM2";
}
2019-12-06 17:57:11 +08:00
private abstract class TestModCustomisable : Mod, IApplicableMod
{
2019-11-05 00:56:09 +08: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-05 00:56:09 +08:00
{
MinValue = 0,
MaxValue = 10,
Default = 5,
Value = 7
2019-11-05 00:56:09 +08:00
};
[SettingSource("Sample bool", "Clicking this changes a setting")]
public BindableBool TickBindable { get; } = new BindableBool();
2019-11-05 00:56:09 +08:00
}
}
}