mirror of
https://github.com/osukey/osukey.git
synced 2025-05-24 15:07:20 +09:00
Merge branch 'master' into cached-all-mods
This commit is contained in:
commit
80f49ec5fd
@ -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 =>
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user