mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Add testing for customisation panel show/hide logic
This commit is contained in:
parent
293ef44836
commit
e46c2df409
@ -1,28 +1,76 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.Mods;
|
using osu.Game.Overlays.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneModSelectScreen : OsuTestScene
|
public class TestSceneModSelectScreen : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
[Test]
|
private ModSelectScreen modSelectScreen;
|
||||||
public void TestModSelectScreen()
|
|
||||||
{
|
|
||||||
ModSelectScreen modSelectScreen = null;
|
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
AddStep("create screen", () => Child = modSelectScreen = new ModSelectScreen
|
AddStep("create screen", () => Child = modSelectScreen = new ModSelectScreen
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
State = { Value = Visibility.Visible }
|
State = { Value = Visibility.Visible },
|
||||||
|
SelectedMods = { BindTarget = SelectedMods }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestStateChange()
|
||||||
|
{
|
||||||
|
AddToggleStep("toggle state", visible => modSelectScreen.State.Value = visible ? Visibility.Visible : Visibility.Hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCustomisationToggleState()
|
||||||
|
{
|
||||||
|
assertCustomisationToggleState(disabled: true, active: false);
|
||||||
|
|
||||||
|
AddStep("select customisable mod", () => SelectedMods.Value = new[] { new OsuModDoubleTime() });
|
||||||
|
assertCustomisationToggleState(disabled: false, active: false);
|
||||||
|
|
||||||
|
AddStep("select mod requiring configuration", () => SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
|
||||||
|
assertCustomisationToggleState(disabled: false, active: true);
|
||||||
|
|
||||||
|
AddStep("dismiss mod customisation", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(modSelectScreen.ChildrenOfType<ShearedToggleButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddToggleStep("toggle state", visible => modSelectScreen.State.Value = visible ? Visibility.Visible : Visibility.Hidden);
|
AddStep("append another mod not requiring config", () => SelectedMods.Value = SelectedMods.Value.Append(new OsuModFlashlight()).ToArray());
|
||||||
|
assertCustomisationToggleState(disabled: false, active: false);
|
||||||
|
|
||||||
|
AddStep("select mod without configuration", () => SelectedMods.Value = new[] { new OsuModAutoplay() });
|
||||||
|
assertCustomisationToggleState(disabled: true, active: false);
|
||||||
|
|
||||||
|
AddStep("select mod requiring configuration", () => SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
|
||||||
|
assertCustomisationToggleState(disabled: false, active: true);
|
||||||
|
|
||||||
|
AddStep("select mod without configuration", () => SelectedMods.Value = new[] { new OsuModAutoplay() });
|
||||||
|
assertCustomisationToggleState(disabled: true, active: false); // config was dismissed without explicit user action.
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertCustomisationToggleState(bool disabled, bool active)
|
||||||
|
{
|
||||||
|
ShearedToggleButton getToggle() => modSelectScreen.ChildrenOfType<ShearedToggleButton>().Single();
|
||||||
|
|
||||||
|
AddAssert($"customisation toggle is {(disabled ? "" : "not ")}disabled", () => getToggle().Active.Disabled == disabled);
|
||||||
|
AddAssert($"customisation toggle is {(active ? "" : "not ")}active", () => getToggle().Active.Value == active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private Bindable<IReadOnlyList<Mod>> selectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
public Bindable<IReadOnlyList<Mod>> SelectedMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||||
|
|
||||||
private readonly BindableBool customisationVisible = new BindableBool();
|
private readonly BindableBool customisationVisible = new BindableBool();
|
||||||
|
|
||||||
@ -169,9 +169,9 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
foreach (var column in columnFlow)
|
foreach (var column in columnFlow)
|
||||||
{
|
{
|
||||||
column.ModStateChanged = (mod, active) => selectedMods.Value = active
|
column.ModStateChanged = (mod, active) => SelectedMods.Value = active
|
||||||
? selectedMods.Value.Append(mod).ToArray()
|
? SelectedMods.Value.Append(mod).ToArray()
|
||||||
: selectedMods.Value.Except(new[] { mod }).ToArray();
|
: SelectedMods.Value.Except(new[] { mod }).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
columnFlow.Shear = new Vector2(ModPanel.SHEAR_X, 0);
|
columnFlow.Shear = new Vector2(ModPanel.SHEAR_X, 0);
|
||||||
@ -181,8 +181,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
((IBindable<IReadOnlyList<Mod>>)modSettingsArea.SelectedMods).BindTo(selectedMods);
|
((IBindable<IReadOnlyList<Mod>>)modSettingsArea.SelectedMods).BindTo(SelectedMods);
|
||||||
selectedMods.BindValueChanged(val =>
|
SelectedMods.BindValueChanged(val =>
|
||||||
{
|
{
|
||||||
updateMultiplier();
|
updateMultiplier();
|
||||||
updateCustomisation(val);
|
updateCustomisation(val);
|
||||||
@ -196,7 +196,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
double multiplier = 1.0;
|
double multiplier = 1.0;
|
||||||
|
|
||||||
foreach (var mod in selectedMods.Value)
|
foreach (var mod in SelectedMods.Value)
|
||||||
multiplier *= mod.ScoreMultiplier;
|
multiplier *= mod.ScoreMultiplier;
|
||||||
|
|
||||||
multiplierDisplay.Current.Value = multiplier;
|
multiplierDisplay.Current.Value = multiplier;
|
||||||
@ -207,7 +207,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
bool anyCustomisableMod = false;
|
bool anyCustomisableMod = false;
|
||||||
bool anyModWithRequiredCustomisationAdded = false;
|
bool anyModWithRequiredCustomisationAdded = false;
|
||||||
|
|
||||||
foreach (var mod in selectedMods.Value)
|
foreach (var mod in SelectedMods.Value)
|
||||||
{
|
{
|
||||||
anyCustomisableMod |= mod.GetSettingsSourceProperties().Any();
|
anyCustomisableMod |= mod.GetSettingsSourceProperties().Any();
|
||||||
anyModWithRequiredCustomisationAdded |= !valueChangedEvent.OldValue.Contains(mod) && mod.RequiresConfiguration;
|
anyModWithRequiredCustomisationAdded |= !valueChangedEvent.OldValue.Contains(mod) && mod.RequiresConfiguration;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user