Fix incorrect keyboard navigation order in score panel list

This commit is contained in:
Bartłomiej Dach 2021-09-07 21:14:38 +02:00
parent 2097889ce1
commit 8cc444df5f
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

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);