Merge branch 'master' into modicon-imod-support

This commit is contained in:
Dan Balasescu
2021-09-10 13:30:05 +09:00
committed by GitHub
7 changed files with 191 additions and 39 deletions

View File

@ -5,10 +5,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -17,10 +17,11 @@ using osu.Game.Overlays.BeatmapListing;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users; using osu.Game.Users;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
public class TestSceneBeatmapListingOverlay : OsuTestScene public class TestSceneBeatmapListingOverlay : OsuManualInputManagerTestScene
{ {
private readonly List<APIBeatmapSet> setsForResponse = new List<APIBeatmapSet>(); private readonly List<APIBeatmapSet> setsForResponse = new List<APIBeatmapSet>();
@ -28,27 +29,33 @@ namespace osu.Game.Tests.Visual.Online
private BeatmapListingSearchControl searchControl => overlay.ChildrenOfType<BeatmapListingSearchControl>().Single(); private BeatmapListingSearchControl searchControl => overlay.ChildrenOfType<BeatmapListingSearchControl>().Single();
[BackgroundDependencyLoader] [SetUpSteps]
private void load() public void SetUpSteps()
{ {
Child = overlay = new BeatmapListingOverlay { State = { Value = Visibility.Visible } }; AddStep("setup overlay", () =>
((DummyAPIAccess)API).HandleRequest = req =>
{ {
if (!(req is SearchBeatmapSetsRequest searchBeatmapSetsRequest)) return false; Child = overlay = new BeatmapListingOverlay { State = { Value = Visibility.Visible } };
setsForResponse.Clear();
searchBeatmapSetsRequest.TriggerSuccess(new SearchBeatmapSetsResponse });
{
BeatmapSets = setsForResponse,
});
return true;
};
AddStep("initialize dummy", () => AddStep("initialize dummy", () =>
{ {
var api = (DummyAPIAccess)API;
api.HandleRequest = req =>
{
if (!(req is SearchBeatmapSetsRequest searchBeatmapSetsRequest)) return false;
searchBeatmapSetsRequest.TriggerSuccess(new SearchBeatmapSetsResponse
{
BeatmapSets = setsForResponse,
});
return true;
};
// non-supporter user // non-supporter user
((DummyAPIAccess)API).LocalUser.Value = new User api.LocalUser.Value = new User
{ {
Username = "TestBot", Username = "TestBot",
Id = API.LocalUser.Value.Id + 1, Id = API.LocalUser.Value.Id + 1,
@ -56,6 +63,51 @@ namespace osu.Game.Tests.Visual.Online
}); });
} }
[Test]
public void TestHideViaBack()
{
AddAssert("is visible", () => overlay.State.Value == Visibility.Visible);
AddStep("hide", () => InputManager.Key(Key.Escape));
AddUntilStep("is hidden", () => overlay.State.Value == Visibility.Hidden);
}
[Test]
public void TestHideViaBackWithSearch()
{
AddAssert("is visible", () => overlay.State.Value == Visibility.Visible);
AddStep("search something", () => overlay.ChildrenOfType<SearchTextBox>().First().Text = "search");
AddStep("kill search", () => InputManager.Key(Key.Escape));
AddAssert("search textbox empty", () => string.IsNullOrEmpty(overlay.ChildrenOfType<SearchTextBox>().First().Text));
AddAssert("is visible", () => overlay.State.Value == Visibility.Visible);
AddStep("hide", () => InputManager.Key(Key.Escape));
AddUntilStep("is hidden", () => overlay.State.Value == Visibility.Hidden);
}
[Test]
public void TestHideViaBackWithScrolledSearch()
{
AddAssert("is visible", () => overlay.State.Value == Visibility.Visible);
AddStep("show many results", () => fetchFor(Enumerable.Repeat(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet, 100).ToArray()));
AddUntilStep("placeholder hidden", () => !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any(d => d.IsPresent));
AddStep("scroll to bottom", () => overlay.ChildrenOfType<OverlayScrollContainer>().First().ScrollToEnd());
AddStep("kill search", () => InputManager.Key(Key.Escape));
AddUntilStep("search textbox empty", () => string.IsNullOrEmpty(overlay.ChildrenOfType<SearchTextBox>().First().Text));
AddUntilStep("is scrolled to top", () => overlay.ChildrenOfType<OverlayScrollContainer>().First().Current == 0);
AddAssert("is visible", () => overlay.State.Value == Visibility.Visible);
AddStep("hide", () => InputManager.Key(Key.Escape));
AddUntilStep("is hidden", () => overlay.State.Value == Visibility.Hidden);
}
[Test] [Test]
public void TestNoBeatmapsPlaceholder() public void TestNoBeatmapsPlaceholder()
{ {
@ -63,7 +115,7 @@ namespace osu.Game.Tests.Visual.Online
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true); AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet)); AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
AddUntilStep("placeholder hidden", () => !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any()); AddUntilStep("placeholder hidden", () => !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any(d => d.IsPresent));
AddStep("fetch for 0 beatmaps", () => fetchFor()); AddStep("fetch for 0 beatmaps", () => fetchFor());
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true); AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
@ -193,13 +245,15 @@ namespace osu.Game.Tests.Visual.Online
noPlaceholderShown(); noPlaceholderShown();
} }
private static int searchCount;
private void fetchFor(params BeatmapSetInfo[] beatmaps) private void fetchFor(params BeatmapSetInfo[] beatmaps)
{ {
setsForResponse.Clear(); setsForResponse.Clear();
setsForResponse.AddRange(beatmaps.Select(b => new TestAPIBeatmapSet(b))); setsForResponse.AddRange(beatmaps.Select(b => new TestAPIBeatmapSet(b)));
// trigger arbitrary change for fetching. // trigger arbitrary change for fetching.
searchControl.Query.TriggerChange(); searchControl.Query.Value = $"search {searchCount++}";
} }
private void setRankAchievedFilter(ScoreRank[] ranks) private void setRankAchievedFilter(ScoreRank[] ranks)
@ -229,8 +283,8 @@ namespace osu.Game.Tests.Visual.Online
private void noPlaceholderShown() private void noPlaceholderShown()
{ {
AddUntilStep("no placeholder shown", () => AddUntilStep("no placeholder shown", () =>
!overlay.ChildrenOfType<BeatmapListingOverlay.SupporterRequiredDrawable>().Any() !overlay.ChildrenOfType<BeatmapListingOverlay.SupporterRequiredDrawable>().Any(d => d.IsPresent)
&& !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any()); && !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any(d => d.IsPresent));
} }
private class TestAPIBeatmapSet : APIBeatmapSet private class TestAPIBeatmapSet : APIBeatmapSet

View File

@ -203,6 +203,71 @@ namespace osu.Game.Tests.Visual.Ranking
assertExpandedPanelCentred(); assertExpandedPanelCentred();
} }
[Test]
public void TestKeyboardNavigation()
{
var lowestScore = new TestScoreInfo(new OsuRuleset().RulesetInfo) { MaxCombo = 100 };
var middleScore = new TestScoreInfo(new OsuRuleset().RulesetInfo) { MaxCombo = 200 };
var highestScore = new TestScoreInfo(new OsuRuleset().RulesetInfo) { MaxCombo = 300 };
createListStep(() => new ScorePanelList());
AddStep("add scores and select middle", () =>
{
// order of addition purposefully scrambled.
list.AddScore(middleScore);
list.AddScore(lowestScore);
list.AddScore(highestScore);
list.SelectedScore.Value = middleScore;
});
assertScoreState(highestScore, false);
assertScoreState(middleScore, true);
assertScoreState(lowestScore, false);
AddStep("press left", () => InputManager.Key(Key.Left));
assertScoreState(highestScore, true);
assertScoreState(middleScore, false);
assertScoreState(lowestScore, false);
assertExpandedPanelCentred();
AddStep("press left at start of list", () => InputManager.Key(Key.Left));
assertScoreState(highestScore, true);
assertScoreState(middleScore, false);
assertScoreState(lowestScore, false);
assertExpandedPanelCentred();
AddStep("press right", () => InputManager.Key(Key.Right));
assertScoreState(highestScore, false);
assertScoreState(middleScore, true);
assertScoreState(lowestScore, false);
assertExpandedPanelCentred();
AddStep("press right again", () => InputManager.Key(Key.Right));
assertScoreState(highestScore, false);
assertScoreState(middleScore, false);
assertScoreState(lowestScore, true);
assertExpandedPanelCentred();
AddStep("press right at end of list", () => InputManager.Key(Key.Right));
assertScoreState(highestScore, false);
assertScoreState(middleScore, false);
assertScoreState(lowestScore, true);
assertExpandedPanelCentred();
AddStep("press left", () => InputManager.Key(Key.Left));
assertScoreState(highestScore, false);
assertScoreState(middleScore, true);
assertScoreState(lowestScore, false);
assertExpandedPanelCentred();
}
private void createListStep(Func<ScorePanelList> creationFunc) private void createListStep(Func<ScorePanelList> creationFunc)
{ {
AddStep("create list", () => Child = list = creationFunc().With(d => AddStep("create list", () => Child = list = creationFunc().With(d =>

View File

@ -70,7 +70,7 @@ namespace osu.Game.Graphics.UserInterface
return base.OnKeyDown(e); return base.OnKeyDown(e);
} }
public bool OnPressed(GlobalAction action) public virtual bool OnPressed(GlobalAction action)
{ {
if (!HasFocus) return false; if (!HasFocus) return false;

View File

@ -3,21 +3,22 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osuTK;
using osu.Framework.Bindables;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osuTK.Graphics;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring; using osu.Game.Scoring;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.BeatmapListing namespace osu.Game.Overlays.BeatmapListing
{ {
@ -117,7 +118,7 @@ namespace osu.Game.Overlays.BeatmapListing
textBox = new BeatmapSearchTextBox textBox = new BeatmapSearchTextBox
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
TypingStarted = () => TypingStarted?.Invoke(), TextChanged = () => TypingStarted?.Invoke(),
}, },
new ReverseChildIDFillFlowContainer<Drawable> new ReverseChildIDFillFlowContainer<Drawable>
{ {
@ -167,7 +168,7 @@ namespace osu.Game.Overlays.BeatmapListing
/// <summary> /// <summary>
/// Any time the text box receives key events (even while masked). /// Any time the text box receives key events (even while masked).
/// </summary> /// </summary>
public Action TypingStarted; public Action TextChanged;
protected override Color4 SelectionColour => Color4.Gray; protected override Color4 SelectionColour => Color4.Gray;
@ -181,7 +182,16 @@ namespace osu.Game.Overlays.BeatmapListing
if (!base.OnKeyDown(e)) if (!base.OnKeyDown(e))
return false; return false;
TypingStarted?.Invoke(); TextChanged?.Invoke();
return true;
}
public override bool OnPressed(GlobalAction action)
{
if (!base.OnPressed(action))
return false;
TextChanged?.Invoke();
return true; return true;
} }
} }

View File

@ -115,7 +115,9 @@ namespace osu.Game.Screens.Menu
if (setInfo == null) if (setInfo == null)
return false; return false;
return (initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0])) != null; initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
return UsingThemedIntro = initialBeatmap != null;
} }
} }
@ -165,7 +167,7 @@ namespace osu.Game.Screens.Menu
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack(); protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
protected void StartTrack() protected virtual void StartTrack()
{ {
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu. // Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu.
if (UsingThemedIntro) if (UsingThemedIntro)
@ -184,7 +186,6 @@ namespace osu.Game.Screens.Menu
{ {
beatmap.Value = initialBeatmap; beatmap.Value = initialBeatmap;
Track = initialBeatmap.Track; Track = initialBeatmap.Track;
UsingThemedIntro = !initialBeatmap.Track.IsDummyDevice;
// ensure the track starts at maximum volume // ensure the track starts at maximum volume
musicController.CurrentTrack.FinishTransforms(); musicController.CurrentTrack.FinishTransforms();

View File

@ -41,6 +41,8 @@ namespace osu.Game.Screens.Menu
private Sample welcome; private Sample welcome;
private DecoupleableInterpolatingFramedClock decoupledClock;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -56,10 +58,18 @@ namespace osu.Game.Screens.Menu
{ {
PrepareMenuLoad(); PrepareMenuLoad();
decoupledClock = new DecoupleableInterpolatingFramedClock
{
IsCoupled = false
};
if (UsingThemedIntro)
decoupledClock.ChangeSource(Track);
LoadComponentAsync(new TrianglesIntroSequence(logo, background) LoadComponentAsync(new TrianglesIntroSequence(logo, background)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Clock = new FramedClock(UsingThemedIntro ? Track : null), Clock = decoupledClock,
LoadMenu = LoadMenu LoadMenu = LoadMenu
}, t => }, t =>
{ {
@ -78,6 +88,11 @@ namespace osu.Game.Screens.Menu
background.FadeOut(100); background.FadeOut(100);
} }
protected override void StartTrack()
{
decoupledClock.Start();
}
private class TrianglesIntroSequence : CompositeDrawable private class TrianglesIntroSequence : CompositeDrawable
{ {
private readonly OsuLogo logo; private readonly OsuLogo logo;

View File

@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -306,18 +307,18 @@ namespace osu.Game.Screens.Ranking
if (expandedPanel == null) if (expandedPanel == null)
return base.OnKeyDown(e); return base.OnKeyDown(e);
var expandedPanelIndex = flow.GetPanelIndex(expandedPanel.Score);
switch (e.Key) switch (e.Key)
{ {
case Key.Left: case Key.Left:
if (expandedPanelIndex > 0) var previousScore = flow.GetPreviousScore(expandedPanel.Score);
SelectedScore.Value = flow.Children[expandedPanelIndex - 1].Panel.Score; if (previousScore != null)
SelectedScore.Value = previousScore;
return true; return true;
case Key.Right: case Key.Right:
if (expandedPanelIndex < flow.Count - 1) var nextScore = flow.GetNextScore(expandedPanel.Score);
SelectedScore.Value = flow.Children[expandedPanelIndex + 1].Panel.Score; if (nextScore != null)
SelectedScore.Value = nextScore;
return true; return true;
} }
@ -336,6 +337,12 @@ namespace osu.Game.Screens.Ranking
public int GetPanelIndex(ScoreInfo score) => applySorting(Children).TakeWhile(s => s.Panel.Score != score).Count(); public int GetPanelIndex(ScoreInfo score) => applySorting(Children).TakeWhile(s => s.Panel.Score != score).Count();
[CanBeNull]
public ScoreInfo GetPreviousScore(ScoreInfo score) => applySorting(Children).TakeWhile(s => s.Panel.Score != score).LastOrDefault()?.Panel.Score;
[CanBeNull]
public ScoreInfo GetNextScore(ScoreInfo score) => applySorting(Children).SkipWhile(s => s.Panel.Score != score).ElementAtOrDefault(1)?.Panel.Score;
private IEnumerable<ScorePanelTrackingContainer> applySorting(IEnumerable<Drawable> drawables) => drawables.OfType<ScorePanelTrackingContainer>() private IEnumerable<ScorePanelTrackingContainer> applySorting(IEnumerable<Drawable> drawables) => drawables.OfType<ScorePanelTrackingContainer>()
.OrderByDescending(GetLayoutPosition) .OrderByDescending(GetLayoutPosition)
.ThenBy(s => s.Panel.Score.OnlineScoreID); .ThenBy(s => s.Panel.Score.OnlineScoreID);