Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Feb 5, 2025
1 parent 6037d5d commit 0721e58
Show file tree
Hide file tree
Showing 20 changed files with 2,063 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
using osu.Game.Screens.SelectV2;
Expand All @@ -37,6 +38,9 @@ public abstract partial class BeatmapCarouselV2TestScene : OsuManualInputManager
[Cached(typeof(BeatmapStore))]
private BeatmapStore store;

[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);

private OsuTextFlowContainer stats = null!;

private int beatmapCount;
Expand Down Expand Up @@ -102,7 +106,7 @@ protected void CreateCarousel()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 500,
Width = 800,
RelativeSizeAxes = Axes.Y,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public void TestScrollPositionMaintainedOnAddSecondSelected()
WaitForDrawablePanels();

AddStep("select middle beatmap", () => Carousel.CurrentSelection = BeatmapSets.ElementAt(BeatmapSets.Count - 2));
AddStep("scroll to selected item", () => Scroll.ScrollTo(Scroll.ChildrenOfType<BeatmapPanel>().Single(p => p.Selected.Value)));
AddStep("scroll to selected item", () => Scroll.ScrollTo(Scroll.ChildrenOfType<BeatmapDifficultyPanel>().Single(p => p.Selected.Value)));

WaitForScrolling();

AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);
AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapDifficultyPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);

RemoveFirstBeatmap();
WaitForSorting();

AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
() => Is.EqualTo(positionBefore));
}

Expand All @@ -90,11 +90,11 @@ public void TestScrollPositionMaintainedOnAddLastSelected()

WaitForScrolling();

AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);
AddStep("save selected screen position", () => positionBefore = Carousel.ChildrenOfType<BeatmapDifficultyPanel>().FirstOrDefault(p => p.Selected.Value)!.ScreenSpaceDrawQuad);

RemoveFirstBeatmap();
WaitForSorting();
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
AddAssert("select screen position unchanged", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Single(p => p.Selected.Value).ScreenSpaceDrawQuad,
() => Is.EqualTo(positionBefore));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public void TestOpenCloseGroupWithNoSelectionMouse()
AddBeatmaps(10, 5);
WaitForDrawablePanels();

AddAssert("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
AddAssert("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
CheckNoSelection();

ClickVisiblePanel<GroupPanel>(0);
AddUntilStep("some beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.GreaterThan(0));
AddUntilStep("some beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.GreaterThan(0));
CheckNoSelection();

ClickVisiblePanel<GroupPanel>(0);
AddUntilStep("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
AddUntilStep("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
CheckNoSelection();
}

Expand All @@ -50,17 +50,17 @@ public void TestOpenCloseGroupWithNoSelectionKeyboard()
AddBeatmaps(10, 5);
WaitForDrawablePanels();

AddAssert("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
AddAssert("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
CheckNoSelection();

SelectNextPanel();
Select();
AddUntilStep("some beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.GreaterThan(0));
AddUntilStep("some beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.GreaterThan(0));
AddAssert("keyboard selected is expanded", () => getKeyboardSelectedPanel()?.Expanded.Value, () => Is.True);
CheckNoSelection();

Select();
AddUntilStep("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
AddUntilStep("no beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.Zero);
AddAssert("keyboard selected is collapsed", () => getKeyboardSelectedPanel()?.Expanded.Value, () => Is.False);
CheckNoSelection();

Expand Down Expand Up @@ -104,7 +104,7 @@ public void TestCarouselRemembersSelection()
ClickVisiblePanel<GroupPanel>(0);
AddUntilStep("carousel item is visible", () => getSelectedPanel()?.Item?.IsVisible, () => Is.True);

BeatmapPanel? getSelectedPanel() => Carousel.ChildrenOfType<BeatmapPanel>().SingleOrDefault(p => p.Selected.Value);
BeatmapDifficultyPanel? getSelectedPanel() => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().SingleOrDefault(p => p.Selected.Value);
}

[Test]
Expand Down Expand Up @@ -136,7 +136,7 @@ public void TestKeyboardSelection()
// open first group
Select();
CheckNoSelection();
AddUntilStep("some beatmaps visible", () => Carousel.ChildrenOfType<BeatmapPanel>().Count(p => p.Alpha > 0), () => Is.GreaterThan(0));
AddUntilStep("some beatmaps visible", () => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().Count(p => p.Alpha > 0), () => Is.GreaterThan(0));

SelectNextPanel();
Select();
Expand Down Expand Up @@ -201,7 +201,7 @@ private void clickOnGroup(int group, Func<GroupPanel, Vector2> pos)
});
}

private void clickOnPanel(int group, int panel, Func<BeatmapPanel, Vector2> pos)
private void clickOnPanel(int group, int panel, Func<BeatmapDifficultyPanel, Vector2> pos)
{
AddStep($"click on group{group} panel{panel}", () =>
{
Expand All @@ -211,7 +211,7 @@ private void clickOnPanel(int group, int panel, Func<BeatmapPanel, Vector2> pos)
// offset by one because the group itself is included in the items list.
object model = groupingFilter.GroupItems[g].ElementAt(panel + 1).Model;

var p = this.ChildrenOfType<BeatmapPanel>().Single(b => ReferenceEquals(b.Item!.Model, model));
var p = this.ChildrenOfType<BeatmapDifficultyPanel>().Single(b => ReferenceEquals(b.Item!.Model, model));
InputManager.MoveMouseTo(p.ToScreenSpace(pos(p)));
InputManager.Click(MouseButton.Left);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void TestCarouselRemembersSelection()
AddUntilStep("drawable selection restored", () => getSelectedPanel()?.Item?.Model, () => Is.EqualTo(selection));
AddAssert("drawable selection matches carousel selection", () => selection, () => Is.EqualTo(Carousel.CurrentSelection));

BeatmapPanel? getSelectedPanel() => Carousel.ChildrenOfType<BeatmapPanel>().SingleOrDefault(p => p.Selected.Value);
BeatmapDifficultyPanel? getSelectedPanel() => Carousel.ChildrenOfType<BeatmapDifficultyPanel>().SingleOrDefault(p => p.Selected.Value);
}

[Test]
Expand Down Expand Up @@ -233,12 +233,12 @@ private void clickOnSet(int set, Func<BeatmapSetPanel, Vector2> pos)
});
}

private void clickOnDifficulty(int set, int diff, Func<BeatmapPanel, Vector2> pos)
private void clickOnDifficulty(int set, int diff, Func<BeatmapDifficultyPanel, Vector2> pos)
{
AddStep($"click on set{set} diff{diff}", () =>
{
var model = BeatmapSets[set].Beatmaps[diff];
var panel = this.ChildrenOfType<BeatmapPanel>().Single(b => ReferenceEquals(b.Item!.Model, model));
var panel = this.ChildrenOfType<BeatmapDifficultyPanel>().Single(b => ReferenceEquals(b.Item!.Model, model));
InputManager.MoveMouseTo(panel.ToScreenSpace(pos(panel)));
InputManager.Click(MouseButton.Left);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.SelectV2;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;

namespace osu.Game.Tests.Visual.SongSelectV2
{
public partial class TestSceneBeatmapCarouselDifficultyPanel : ThemeComparisonTestScene
{
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;

private BeatmapInfo beatmap = null!;

public TestSceneBeatmapCarouselDifficultyPanel()
: base(false)
{
}

[Test]
public void TestDisplay()
{
AddStep("set beatmap", () =>
{
var beatmapSet = beatmaps.GetAllUsableBeatmapSets().FirstOrDefault(b => b.OnlineID == 241526)
?? beatmaps.GetAllUsableBeatmapSets().FirstOrDefault(b => !b.Protected)
?? TestResources.CreateTestBeatmapSetInfo();

beatmap = beatmapSet.Beatmaps.First();
CreateThemedContent(OverlayColourScheme.Aquamarine);
});
}

[Test]
public void TestRandomBeatmap()
{
AddStep("random beatmap", () =>
{
beatmap = beatmaps.GetAllUsableBeatmapSets().OrderBy(_ => RNG.Next())
.First().Beatmaps.OrderBy(_ => RNG.Next()).First();
CreateThemedContent(OverlayColourScheme.Aquamarine);
});
}

[Test]
public void TestManiaRuleset()
{
AddToggleStep("mania ruleset", v => Ruleset.Value = v ? new ManiaRuleset().RulesetInfo : new OsuRuleset().RulesetInfo);
}

protected override Drawable CreateContent()
{
return new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0f, 5f),
Children = new Drawable[]
{
new BeatmapDifficultyPanel
{
Item = new CarouselItem(beatmap)
},
new BeatmapDifficultyPanel
{
Item = new CarouselItem(beatmap),
KeyboardSelected = { Value = true }
},
new BeatmapDifficultyPanel
{
Item = new CarouselItem(beatmap),
Selected = { Value = true }
},
new BeatmapDifficultyPanel
{
Item = new CarouselItem(beatmap),
KeyboardSelected = { Value = true },
Selected = { Value = true }
},
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Screens.SelectV2;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;

namespace osu.Game.Tests.Visual.SongSelectV2
{
public partial class TestSceneBeatmapCarouselSetPanel : ThemeComparisonTestScene
{
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;

private BeatmapSetInfo beatmapSet = null!;

public TestSceneBeatmapCarouselSetPanel()
: base(false)
{
}

[Test]
public void TestDisplay()
{
AddStep("set beatmap", () =>
{
beatmapSet = beatmaps.GetAllUsableBeatmapSets().FirstOrDefault(b => b.OnlineID == 241526)
?? beatmaps.GetAllUsableBeatmapSets().FirstOrDefault(b => !b.Protected)
?? TestResources.CreateTestBeatmapSetInfo();
CreateThemedContent(OverlayColourScheme.Aquamarine);
});
}

[Test]
public void TestRandomBeatmap()
{
AddStep("random beatmap", () =>
{
beatmapSet = beatmaps.GetAllUsableBeatmapSets().OrderBy(_ => RNG.Next()).First();
CreateThemedContent(OverlayColourScheme.Aquamarine);
});
}

protected override Drawable CreateContent()
{
return new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0f, 5f),
Children = new Drawable[]
{
new BeatmapSetPanel
{
Item = new CarouselItem(beatmapSet)
},
new BeatmapSetPanel
{
Item = new CarouselItem(beatmapSet),
KeyboardSelected = { Value = true }
},
new BeatmapSetPanel
{
Item = new CarouselItem(beatmapSet),
Expanded = { Value = true }
},
new BeatmapSetPanel
{
Item = new CarouselItem(beatmapSet),
KeyboardSelected = { Value = true },
Expanded = { Value = true }
},
}
};
}
}
}
Loading

0 comments on commit 0721e58

Please sign in to comment.