mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Implement preset creation flow with test coverage
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
// 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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -10,16 +11,19 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Mods;
|
using osu.Game.Overlays.Mods;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mania.Mods;
|
using osu.Game.Rulesets.Mania.Mods;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneModPresetColumn : OsuTestScene
|
public class TestSceneModPresetColumn : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
protected override bool UseFreshStoragePerRun => true;
|
protected override bool UseFreshStoragePerRun => true;
|
||||||
|
|
||||||
@ -146,6 +150,61 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
|
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAddingFlow()
|
||||||
|
{
|
||||||
|
ModPresetColumn modPresetColumn = null!;
|
||||||
|
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("items loaded", () => modPresetColumn.IsLoaded && modPresetColumn.ItemsLoaded);
|
||||||
|
AddAssert("add preset button disabled", () => !this.ChildrenOfType<AddPresetButton>().Single().Enabled.Value);
|
||||||
|
|
||||||
|
AddStep("set mods", () => SelectedMods.Value = new Mod[] { new OsuModDaycore(), new OsuModClassic() });
|
||||||
|
AddAssert("add preset button enabled", () => this.ChildrenOfType<AddPresetButton>().Single().Enabled.Value);
|
||||||
|
|
||||||
|
AddStep("click add preset button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(this.ChildrenOfType<AddPresetButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
OsuPopover? popover = null;
|
||||||
|
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
|
||||||
|
AddStep("attempt preset creation", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddWaitStep("wait some", 3);
|
||||||
|
AddAssert("preset creation did not occur", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
|
||||||
|
AddUntilStep("popover is unchanged", () => this.ChildrenOfType<OsuPopover>().FirstOrDefault() == popover);
|
||||||
|
|
||||||
|
AddStep("fill preset name", () => popover.ChildrenOfType<LabelledTextBox>().First().Current.Value = "new preset");
|
||||||
|
AddStep("attempt preset creation", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
|
||||||
|
AddUntilStep("preset creation occurred", () => this.ChildrenOfType<ModPresetPanel>().Count() == 4);
|
||||||
|
|
||||||
|
AddStep("click add preset button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(this.ChildrenOfType<AddPresetButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
|
||||||
|
}
|
||||||
|
|
||||||
private ICollection<ModPreset> createTestPresets() => new[]
|
private ICollection<ModPreset> createTestPresets() => new[]
|
||||||
{
|
{
|
||||||
new ModPreset
|
new ModPreset
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// 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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
@ -8,9 +10,13 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
|
|
||||||
@ -21,6 +27,9 @@ namespace osu.Game.Overlays.Mods
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; } = null!;
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
||||||
|
|
||||||
public AddPresetButton()
|
public AddPresetButton()
|
||||||
: base(1)
|
: base(1)
|
||||||
{
|
{
|
||||||
@ -35,6 +44,18 @@ namespace osu.Game.Overlays.Mods
|
|||||||
TextSize = 30;
|
TextSize = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
selectedMods.BindValueChanged(val => Enabled.Value = val.NewValue.Any(), true);
|
||||||
|
Enabled.BindValueChanged(val =>
|
||||||
|
{
|
||||||
|
if (!val.NewValue)
|
||||||
|
Active.Value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected override void UpdateActiveState()
|
protected override void UpdateActiveState()
|
||||||
{
|
{
|
||||||
DarkerColour = Active.Value ? colours.Orange1 : ColourProvider.Background3;
|
DarkerColour = Active.Value ? colours.Orange1 : ColourProvider.Background3;
|
||||||
@ -57,6 +78,15 @@ namespace osu.Game.Overlays.Mods
|
|||||||
private readonly LabelledTextBox descriptionTextBox;
|
private readonly LabelledTextBox descriptionTextBox;
|
||||||
private readonly ShearedButton createButton;
|
private readonly ShearedButton createButton;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RealmAccess realm { get; set; } = null!;
|
||||||
|
|
||||||
public AddPresetPopover(AddPresetButton addPresetButton)
|
public AddPresetPopover(AddPresetButton addPresetButton)
|
||||||
{
|
{
|
||||||
button = addPresetButton;
|
button = addPresetButton;
|
||||||
@ -87,7 +117,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
Text = ModSelectOverlayStrings.AddPreset,
|
Text = ModSelectOverlayStrings.AddPreset,
|
||||||
Action = this.HidePopover
|
Action = tryCreatePreset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -104,6 +134,25 @@ namespace osu.Game.Overlays.Mods
|
|||||||
createButton.TextColour = colourProvider.Background6;
|
createButton.TextColour = colourProvider.Background6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tryCreatePreset()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value))
|
||||||
|
{
|
||||||
|
Body.Shake();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
realm.Write(r => r.Add(new ModPreset
|
||||||
|
{
|
||||||
|
Name = nameTextBox.Current.Value,
|
||||||
|
Description = descriptionTextBox.Current.Value,
|
||||||
|
Mods = selectedMods.Value.ToArray(),
|
||||||
|
Ruleset = r.Find<RulesetInfo>(ruleset.Value.ShortName)
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.HidePopover();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
||||||
{
|
{
|
||||||
base.UpdateState(state);
|
base.UpdateState(state);
|
||||||
|
Reference in New Issue
Block a user