1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:17:44 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

465 lines
20 KiB
C#
Raw Normal View History

// 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;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2022-07-24 00:01:11 +08:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
2022-07-24 04:03:31 +08:00
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Overlays.Mods;
2022-07-24 00:01:11 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneModPresetColumn : OsuManualInputManagerTestScene
{
2022-07-24 00:01:11 +08:00
protected override bool UseFreshStoragePerRun => true;
private Container<Drawable> content = null!;
protected override Container<Drawable> Content => content;
private RulesetStore rulesets = null!;
2022-07-24 00:01:11 +08:00
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
2022-07-24 04:03:31 +08:00
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
2022-07-24 00:01:11 +08:00
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
2022-07-24 00:01:11 +08:00
Dependencies.Cache(Realm);
2022-07-24 04:03:31 +08:00
base.Content.AddRange(new Drawable[]
{
2022-07-24 04:03:31 +08:00
new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = content = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30),
}
},
dialogOverlay
});
2022-07-24 00:01:11 +08:00
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("clear contents", Clear);
2022-07-24 00:01:11 +08:00
AddStep("reset storage", () =>
{
Realm.Write(realm =>
{
realm.RemoveAll<ModPreset>();
var testPresets = createTestPresets();
foreach (var preset in testPresets)
2023-07-06 12:37:42 +08:00
preset.Ruleset = realm.Find<RulesetInfo>(preset.Ruleset.ShortName)!;
realm.Add(testPresets);
2022-07-24 00:01:11 +08:00
});
});
}
[Test]
public void TestBasicOperation()
{
2022-07-24 00:01:11 +08:00
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddStep("create content", () => Child = new ModPresetColumn
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
2022-07-24 00:01:11 +08:00
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
AddStep("change ruleset to mania", () => Ruleset.Value = rulesets.GetRuleset(3));
AddUntilStep("1 panel visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 1);
AddStep("add another mania preset", () => Realm.Write(r => r.Add(new ModPreset
{
Name = "and another one",
Mods = new Mod[]
{
new ManiaModMirror(),
new ManiaModNightcore(),
new ManiaModHardRock()
},
2023-07-06 12:37:42 +08:00
Ruleset = r.Find<RulesetInfo>("mania")!
})));
AddUntilStep("2 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddStep("add another osu! preset", () => Realm.Write(r => r.Add(new ModPreset
{
Name = "hdhr",
Mods = new Mod[]
{
new OsuModHidden(),
new OsuModHardRock()
},
2023-07-06 12:37:42 +08:00
Ruleset = r.Find<RulesetInfo>("osu")!
})));
AddUntilStep("2 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddStep("remove mania preset", () => Realm.Write(r =>
{
var toRemove = r.All<ModPreset>().Single(preset => preset.Name == "Different ruleset");
r.Remove(toRemove);
}));
AddUntilStep("1 panel visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 1);
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddUntilStep("4 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 4);
}
[Test]
public void TestSoftDeleteSupport()
{
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
AddStep("create content", () => Child = new ModPresetColumn
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
AddStep("soft delete preset", () => Realm.Write(r =>
{
var toSoftDelete = r.All<ModPreset>().Single(preset => preset.Name == "AR0");
toSoftDelete.DeletePending = true;
}));
AddUntilStep("2 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddStep("soft delete all presets", () => Realm.Write(r =>
{
foreach (var preset in r.All<ModPreset>())
preset.DeletePending = true;
}));
AddUntilStep("no panels visible", () => !this.ChildrenOfType<ModPresetPanel>().Any());
AddStep("select mods from first preset", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime(), new OsuModHardRock() });
AddStep("undelete presets", () => Realm.Write(r =>
{
foreach (var preset in r.All<ModPreset>())
preset.DeletePending = false;
}));
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());
}
[Test]
public void TestDeleteFlow()
{
ModPresetColumn modPresetColumn = null!;
AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
AddUntilStep("items loaded", () => modPresetColumn.IsLoaded && modPresetColumn.ItemsLoaded);
AddStep("right click first panel", () =>
{
var panel = this.ChildrenOfType<ModPresetPanel>().First();
InputManager.MoveMouseTo(panel);
InputManager.Click(MouseButton.Right);
});
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
AddStep("click delete", () =>
{
2023-03-07 01:00:40 +08:00
var deleteItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(1);
InputManager.MoveMouseTo(deleteItem);
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for dialog", () => dialogOverlay.CurrentDialog is DeleteModPresetDialog);
AddStep("hold confirm", () =>
{
var confirmButton = this.ChildrenOfType<PopupDialogDangerousButton>().Single();
InputManager.MoveMouseTo(confirmButton);
InputManager.PressButton(MouseButton.Left);
});
AddUntilStep("wait for dialog to close", () => dialogOverlay.CurrentDialog == null);
AddStep("release mouse", () => InputManager.ReleaseButton(MouseButton.Left));
AddUntilStep("preset deletion occurred", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddAssert("preset soft-deleted", () => Realm.Run(r => r.All<ModPreset>().Count(preset => preset.DeletePending) == 1));
}
2023-03-07 01:00:40 +08:00
[Test]
2023-05-05 00:46:36 +08:00
public void TestEditPresetName()
2023-03-07 01:00:40 +08:00
{
ModPresetColumn modPresetColumn = null!;
string presetName = null!;
2023-03-09 23:56:22 +08:00
ModPresetPanel panel = null!;
2023-03-07 01:00:40 +08:00
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);
AddStep("right click first panel", () =>
{
2023-03-09 23:56:22 +08:00
panel = this.ChildrenOfType<ModPresetPanel>().First();
2023-03-07 01:00:40 +08:00
presetName = panel.Preset.Value.Name;
InputManager.MoveMouseTo(panel);
InputManager.Click(MouseButton.Right);
});
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
AddStep("click edit", () =>
{
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
InputManager.MoveMouseTo(editItem);
InputManager.Click(MouseButton.Left);
});
OsuPopover? popover = null;
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
AddStep("clear preset name", () => popover.ChildrenOfType<LabelledTextBox>().First().Current.Value = "");
AddStep("attempt preset edit", () =>
{
2023-03-07 20:13:35 +08:00
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(1));
2023-03-07 01:00:40 +08:00
InputManager.Click(MouseButton.Left);
});
2023-05-05 00:46:36 +08:00
AddAssert("preset is not changed", () => panel.Preset.Value.Name == presetName);
2023-03-07 01:00:40 +08:00
AddUntilStep("popover is unchanged", () => this.ChildrenOfType<OsuPopover>().FirstOrDefault() == popover);
AddStep("edit preset name", () => popover.ChildrenOfType<LabelledTextBox>().First().Current.Value = "something new");
AddStep("commit changes to textbox", () => InputManager.Key(Key.Enter));
AddStep("attempt preset edit via select binding", () => InputManager.Key(Key.Enter));
2023-03-07 01:00:40 +08:00
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
2023-05-05 00:46:36 +08:00
AddAssert("preset is changed", () => panel.Preset.Value.Name != presetName);
2023-03-07 01:00:40 +08:00
}
[Test]
public void TestEditPresetMod()
{
ModPresetColumn modPresetColumn = null!;
var mods = new Mod[] { new OsuModHidden(), new OsuModHardRock() };
List<Mod> previousMod = null!;
2023-03-07 01:00:40 +08:00
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);
2023-03-09 21:45:33 +08:00
2023-03-07 01:00:40 +08:00
AddStep("right click first panel", () =>
{
var panel = this.ChildrenOfType<ModPresetPanel>().First();
previousMod = panel.Preset.Value.Mods.ToList();
2023-03-07 01:00:40 +08:00
InputManager.MoveMouseTo(panel);
InputManager.Click(MouseButton.Right);
});
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
AddStep("click edit", () =>
{
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
InputManager.MoveMouseTo(editItem);
InputManager.Click(MouseButton.Left);
});
OsuPopover? popover = null;
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
2023-03-07 20:13:35 +08:00
AddStep("click use current mods", () =>
2023-03-07 01:00:40 +08:00
{
2023-03-07 20:13:35 +08:00
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(0));
2023-03-07 01:00:40 +08:00
InputManager.Click(MouseButton.Left);
});
AddStep("attempt preset edit", () =>
{
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
2023-05-03 21:56:47 +08:00
2023-05-05 00:46:36 +08:00
AddUntilStep("preset mod not changed", () =>
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(previousMod));
2023-03-09 21:45:33 +08:00
AddStep("select mods", () => SelectedMods.Value = mods);
AddStep("right click first panel", () =>
{
var panel = this.ChildrenOfType<ModPresetPanel>().First();
InputManager.MoveMouseTo(panel);
InputManager.Click(MouseButton.Right);
});
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
AddStep("click edit", () =>
{
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
InputManager.MoveMouseTo(editItem);
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
AddStep("click use current mods", () =>
{
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(0));
InputManager.Click(MouseButton.Left);
});
AddStep("attempt preset edit", () =>
{
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
2023-05-03 21:56:47 +08:00
2023-05-05 00:46:36 +08:00
AddUntilStep("preset mod is changed", () =>
2023-03-09 23:56:22 +08:00
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(mods));
2023-03-09 21:45:33 +08:00
}
[Test]
public void TestTextFiltering()
{
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);
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddStep("set text filter", () => modPresetColumn.SearchTerm = "First");
AddUntilStep("one panel visible", () => modPresetColumn.ChildrenOfType<ModPresetPanel>().Count(panel => panel.IsPresent), () => Is.EqualTo(1));
AddStep("set mania ruleset", () => Ruleset.Value = rulesets.GetRuleset(3));
AddUntilStep("no panels visible", () => modPresetColumn.ChildrenOfType<ModPresetPanel>().Count(panel => panel.IsPresent), () => Is.EqualTo(0));
}
private ICollection<ModPreset> createTestPresets() => new[]
{
new ModPreset
{
Name = "First preset",
Description = "Please ignore",
Mods = new Mod[]
{
new OsuModHardRock(),
new OsuModDoubleTime()
2022-07-24 00:01:11 +08:00
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
},
new ModPreset
{
Name = "AR0",
Description = "For good readers",
Mods = new Mod[]
{
new OsuModDifficultyAdjust
{
ApproachRate = { Value = 0 }
}
2022-07-24 00:01:11 +08:00
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
},
new ModPreset
{
Name = "This preset is going to have an extraordinarily long name",
Description = "This is done so that the capability to truncate overlong texts may be demonstrated",
Mods = new Mod[]
{
new OsuModFlashlight(),
new OsuModSpinIn()
2022-07-24 00:01:11 +08:00
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
},
new ModPreset
{
Name = "Different ruleset",
Description = "Just to shake things up",
Mods = new Mod[]
{
new ManiaModKey4(),
new ManiaModFadeIn()
},
Ruleset = rulesets.GetRuleset(3).AsNonNull()
}
};
}
}