Merge pull request #891 from EVAST9919/cancel-select-random

Add the ability to go back in random selection history
This commit is contained in:
Dan Balasescu 2017-06-26 18:03:36 +09:00 committed by GitHub
commit e6818a45be
2 changed files with 40 additions and 7 deletions

View File

@ -77,8 +77,9 @@ namespace osu.Game.Screens.Select
private readonly List<Panel> panels = new List<Panel>(); private readonly List<Panel> panels = new List<Panel>();
private BeatmapGroup selectedGroup; private readonly Stack<KeyValuePair<BeatmapGroup, BeatmapPanel>> randomSelectedBeatmaps = new Stack<KeyValuePair<BeatmapGroup, BeatmapPanel>>();
private BeatmapGroup selectedGroup;
private BeatmapPanel selectedPanel; private BeatmapPanel selectedPanel;
public BeatmapCarousel() public BeatmapCarousel()
@ -170,16 +171,21 @@ namespace osu.Game.Screens.Select
} while (index != startIndex); } while (index != startIndex);
} }
public void SelectRandom() private IEnumerable<BeatmapGroup> getVisibleGroups() => groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden);
public void SelectNextRandom()
{ {
IEnumerable<BeatmapGroup> visibleGroups = groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); randomSelectedBeatmaps.Push(new KeyValuePair<BeatmapGroup, BeatmapPanel>(selectedGroup, selectedGroup.SelectedPanel));
var visibleGroups = getVisibleGroups();
if (!visibleGroups.Any()) if (!visibleGroups.Any())
return; return;
BeatmapGroup group; BeatmapGroup group;
if (randomType == SelectionRandomType.RandomPermutation) if (randomType == SelectionRandomType.RandomPermutation)
{ {
IEnumerable<BeatmapGroup> notSeenGroups = visibleGroups.Except(seenGroups); var notSeenGroups = visibleGroups.Except(seenGroups);
if (!notSeenGroups.Any()) if (!notSeenGroups.Any())
{ {
seenGroups.Clear(); seenGroups.Clear();
@ -197,6 +203,27 @@ namespace osu.Game.Screens.Select
selectGroup(group, panel); selectGroup(group, panel);
} }
public void SelectPreviousRandom()
{
if (!randomSelectedBeatmaps.Any())
return;
var visibleGroups = getVisibleGroups();
if (!visibleGroups.Any())
return;
while (randomSelectedBeatmaps.Any())
{
var beatmapCoordinates = randomSelectedBeatmaps.Pop();
var group = beatmapCoordinates.Key;
if (visibleGroups.Contains(group))
{
selectGroup(group, beatmapCoordinates.Value);
break;
}
}
}
private FilterCriteria criteria = new FilterCriteria(); private FilterCriteria criteria = new FilterCriteria();
private ScheduledDelegate filterTask; private ScheduledDelegate filterTask;

View File

@ -154,11 +154,11 @@ namespace osu.Game.Screens.Select
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours) private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours, UserInputManager input)
{ {
if (Footer != null) if (Footer != null)
{ {
Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2); Footer.AddButton(@"random", colours.Green, () => triggerRandom(input), Key.F2);
Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3); Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3);
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue); BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue);
@ -209,7 +209,13 @@ namespace osu.Game.Screens.Select
OnSelected(); OnSelected();
} }
public void SelectRandom() => carousel.SelectRandom(); private void triggerRandom(UserInputManager input)
{
if (input.CurrentState.Keyboard.ShiftPressed)
carousel.SelectPreviousRandom();
else
carousel.SelectNextRandom();
}
protected abstract void OnSelected(); protected abstract void OnSelected();