1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

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.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -306,18 +307,18 @@ namespace osu.Game.Screens.Ranking
if (expandedPanel == null)
return base.OnKeyDown(e);
var expandedPanelIndex = flow.GetPanelIndex(expandedPanel.Score);
switch (e.Key)
{
case Key.Left:
if (expandedPanelIndex > 0)
SelectedScore.Value = flow.Children[expandedPanelIndex - 1].Panel.Score;
var previousScore = flow.GetPreviousScore(expandedPanel.Score);
if (previousScore != null)
SelectedScore.Value = previousScore;
return true;
case Key.Right:
if (expandedPanelIndex < flow.Count - 1)
SelectedScore.Value = flow.Children[expandedPanelIndex + 1].Panel.Score;
var nextScore = flow.GetNextScore(expandedPanel.Score);
if (nextScore != null)
SelectedScore.Value = nextScore;
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();
[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>()
.OrderByDescending(GetLayoutPosition)
.ThenBy(s => s.Panel.Score.OnlineScoreID);