From a42c67ee9787f0336b8a2f40d27e0217c488c56c Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 1 Jun 2017 20:54:42 +0300 Subject: [PATCH 1/4] Cancel beatmap random selection --- osu.Game/Screens/Select/BeatmapCarousel.cs | 42 ++++++++++++++++++++-- osu.Game/Screens/Select/Footer.cs | 4 ++- osu.Game/Screens/Select/FooterButton.cs | 16 +++++++-- osu.Game/Screens/Select/PlaySongSelect.cs | 2 +- osu.Game/Screens/Select/SongSelect.cs | 9 ++++- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 26820fc388..07f6a7e5fd 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -77,8 +77,9 @@ namespace osu.Game.Screens.Select private readonly List panels = new List(); - private BeatmapGroup selectedGroup; + private readonly Stack randomSelectedBeatmaps = new Stack(); + private BeatmapGroup selectedGroup; private BeatmapPanel selectedPanel; public BeatmapCarousel() @@ -172,14 +173,17 @@ namespace osu.Game.Screens.Select public void SelectRandom() { - IEnumerable visibleGroups = groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); + randomSelectedBeatmaps.Push(selectedGroup); + + var visibleGroups = getVisibleGroups(); if (!visibleGroups.Any()) return; BeatmapGroup group; + if (randomType == SelectionRandomType.RandomPermutation) { - IEnumerable notSeenGroups = visibleGroups.Except(seenGroups); + var notSeenGroups = visibleGroups.Except(seenGroups); if (!notSeenGroups.Any()) { seenGroups.Clear(); @@ -197,6 +201,38 @@ namespace osu.Game.Screens.Select selectGroup(group, panel); } + public void CancelRandom() + { + if (!randomSelectedBeatmaps.Any()) + return; + + var visibleGroups = getVisibleGroups(); + if (!visibleGroups.Any()) + return; + + // we can avoid selecting deleted beatmaps or beatmaps selected in another gamemode + while (true) + { + if (!randomSelectedBeatmaps.Any()) break; + + if (!visibleGroups.Contains(randomSelectedBeatmaps.FirstOrDefault())) + { + randomSelectedBeatmaps.Pop(); + } + else + { + BeatmapGroup beatmapGroup = randomSelectedBeatmaps.Pop(); + selectGroup(beatmapGroup, beatmapGroup.SelectedPanel); + break; + } + } + } + + private IEnumerable getVisibleGroups() + { + return groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); + } + private FilterCriteria criteria = new FilterCriteria(); private ScheduledDelegate filterTask; diff --git a/osu.Game/Screens/Select/Footer.cs b/osu.Game/Screens/Select/Footer.cs index 32e09a5f28..0aa86f4d0d 100644 --- a/osu.Game/Screens/Select/Footer.cs +++ b/osu.Game/Screens/Select/Footer.cs @@ -38,12 +38,13 @@ namespace osu.Game.Screens.Select /// Text on the button. /// Colour of the button. /// Hotkey of the button. + /// Forbid you to use hotkey with shift pressed. /// Action the button does. /// /// Higher depth to be put on the left, and lower to be put on the right. /// Notice this is different to ! /// - public void AddButton(string text, Color4 colour, Action action, Key? hotkey = null, float depth = 0) + public void AddButton(string text, Color4 colour, Action action, Key? hotkey = null, bool excludePressWithShift = false, float depth = 0) { var button = new FooterButton { @@ -54,6 +55,7 @@ namespace osu.Game.Screens.Select SelectedColour = colour, DeselectedColour = colour.Opacity(0.5f), Hotkey = hotkey, + ExcludePressWithShift = excludePressWithShift, }; button.Hovered = () => updateModeLight(button); diff --git a/osu.Game/Screens/Select/FooterButton.cs b/osu.Game/Screens/Select/FooterButton.cs index 58df409ca1..98a0b41543 100644 --- a/osu.Game/Screens/Select/FooterButton.cs +++ b/osu.Game/Screens/Select/FooterButton.cs @@ -84,6 +84,7 @@ namespace osu.Game.Screens.Select public Action Hovered; public Action HoverLost; public Key? Hotkey; + public bool ExcludePressWithShift; protected override bool OnHover(InputState state) { @@ -124,8 +125,19 @@ namespace osu.Game.Screens.Select { if (!args.Repeat && args.Key == Hotkey) { - OnClick(state); - return true; + if (ExcludePressWithShift) + { + if (!state.Keyboard.ShiftPressed) + { + OnClick(state); + return true; + } + } + else + { + OnClick(state); + return true; + } } return base.OnKeyDown(state, args); diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index f96fbb87cb..0903184b40 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -42,7 +42,7 @@ namespace osu.Game.Screens.Select [BackgroundDependencyLoader] private void load(OsuColour colours) { - Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1, float.MaxValue); + Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1, false, float.MaxValue); BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null, Key.Number1); BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null, Key.Number2); diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 41fa53e8a3..1451d2e4fd 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -158,7 +158,7 @@ namespace osu.Game.Screens.Select { if (Footer != null) { - Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2); + Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2, true); Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3); BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue); @@ -381,6 +381,13 @@ namespace osu.Game.Screens.Select return true; } break; + case Key.F2: + if (state.Keyboard.ShiftPressed) + { + carousel.CancelRandom(); + return true; + } + break; } return base.OnKeyDown(state, args); From 78500eec21b8039ef5b5959a885c26dca55738ef Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 5 Jun 2017 12:24:28 +0300 Subject: [PATCH 2/4] Applied suggested changes --- osu.Game/Screens/Select/BeatmapCarousel.cs | 19 ++++++------------- osu.Game/Screens/Select/Footer.cs | 4 +--- osu.Game/Screens/Select/FooterButton.cs | 16 ++-------------- osu.Game/Screens/Select/PlaySongSelect.cs | 2 +- osu.Game/Screens/Select/SongSelect.cs | 19 +++++++++---------- 5 files changed, 19 insertions(+), 41 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 07f6a7e5fd..88c57853df 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -171,7 +171,7 @@ namespace osu.Game.Screens.Select } while (index != startIndex); } - public void SelectRandom() + public void SelectNextRandom() { randomSelectedBeatmaps.Push(selectedGroup); @@ -201,7 +201,7 @@ namespace osu.Game.Screens.Select selectGroup(group, panel); } - public void CancelRandom() + public void SelectPreviousRandom() { if (!randomSelectedBeatmaps.Any()) return; @@ -210,19 +210,12 @@ namespace osu.Game.Screens.Select if (!visibleGroups.Any()) return; - // we can avoid selecting deleted beatmaps or beatmaps selected in another gamemode - while (true) + while (randomSelectedBeatmaps.Any()) { - if (!randomSelectedBeatmaps.Any()) break; - - if (!visibleGroups.Contains(randomSelectedBeatmaps.FirstOrDefault())) + var group = randomSelectedBeatmaps.Pop(); + if (visibleGroups.Contains(group)) { - randomSelectedBeatmaps.Pop(); - } - else - { - BeatmapGroup beatmapGroup = randomSelectedBeatmaps.Pop(); - selectGroup(beatmapGroup, beatmapGroup.SelectedPanel); + selectGroup(group, group.SelectedPanel); break; } } diff --git a/osu.Game/Screens/Select/Footer.cs b/osu.Game/Screens/Select/Footer.cs index 0aa86f4d0d..32e09a5f28 100644 --- a/osu.Game/Screens/Select/Footer.cs +++ b/osu.Game/Screens/Select/Footer.cs @@ -38,13 +38,12 @@ namespace osu.Game.Screens.Select /// Text on the button. /// Colour of the button. /// Hotkey of the button. - /// Forbid you to use hotkey with shift pressed. /// Action the button does. /// /// Higher depth to be put on the left, and lower to be put on the right. /// Notice this is different to ! /// - public void AddButton(string text, Color4 colour, Action action, Key? hotkey = null, bool excludePressWithShift = false, float depth = 0) + public void AddButton(string text, Color4 colour, Action action, Key? hotkey = null, float depth = 0) { var button = new FooterButton { @@ -55,7 +54,6 @@ namespace osu.Game.Screens.Select SelectedColour = colour, DeselectedColour = colour.Opacity(0.5f), Hotkey = hotkey, - ExcludePressWithShift = excludePressWithShift, }; button.Hovered = () => updateModeLight(button); diff --git a/osu.Game/Screens/Select/FooterButton.cs b/osu.Game/Screens/Select/FooterButton.cs index 98a0b41543..58df409ca1 100644 --- a/osu.Game/Screens/Select/FooterButton.cs +++ b/osu.Game/Screens/Select/FooterButton.cs @@ -84,7 +84,6 @@ namespace osu.Game.Screens.Select public Action Hovered; public Action HoverLost; public Key? Hotkey; - public bool ExcludePressWithShift; protected override bool OnHover(InputState state) { @@ -125,19 +124,8 @@ namespace osu.Game.Screens.Select { if (!args.Repeat && args.Key == Hotkey) { - if (ExcludePressWithShift) - { - if (!state.Keyboard.ShiftPressed) - { - OnClick(state); - return true; - } - } - else - { - OnClick(state); - return true; - } + OnClick(state); + return true; } return base.OnKeyDown(state, args); diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 0903184b40..f96fbb87cb 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -42,7 +42,7 @@ namespace osu.Game.Screens.Select [BackgroundDependencyLoader] private void load(OsuColour colours) { - Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1, false, float.MaxValue); + Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1, float.MaxValue); BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null, Key.Number1); BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null, Key.Number2); diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 1451d2e4fd..5e6eaadff5 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -154,11 +154,11 @@ namespace osu.Game.Screens.Select } [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) { - Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2, true); + Footer.AddButton(@"random", colours.Green, () => triggerRandom(input), Key.F2); Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3); BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue); @@ -209,7 +209,13 @@ namespace osu.Game.Screens.Select 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(); @@ -381,13 +387,6 @@ namespace osu.Game.Screens.Select return true; } break; - case Key.F2: - if (state.Keyboard.ShiftPressed) - { - carousel.CancelRandom(); - return true; - } - break; } return base.OnKeyDown(state, args); From e552c39444c3439f2120d9ba1e5289f71c812902 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Sun, 11 Jun 2017 22:04:35 +0300 Subject: [PATCH 3/4] change function to a property --- osu.Game/Screens/Select/BeatmapCarousel.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index a268096435..05fb4c48bf 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -171,6 +171,8 @@ namespace osu.Game.Screens.Select } while (index != startIndex); } + private IEnumerable getVisibleGroups() => groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); + public void SelectNextRandom() { randomSelectedBeatmaps.Push(selectedGroup); @@ -221,11 +223,6 @@ namespace osu.Game.Screens.Select } } - private IEnumerable getVisibleGroups() - { - return groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden); - } - private FilterCriteria criteria = new FilterCriteria(); private ScheduledDelegate filterTask; From 5117baae66e0707a2d861f733b420879727ad1ea Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 15 Jun 2017 06:37:20 +0300 Subject: [PATCH 4/4] Make random works with panels too --- osu.Game/Screens/Select/BeatmapCarousel.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 05fb4c48bf..f9064c4963 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Select private readonly List panels = new List(); - private readonly Stack randomSelectedBeatmaps = new Stack(); + private readonly Stack> randomSelectedBeatmaps = new Stack>(); private BeatmapGroup selectedGroup; private BeatmapPanel selectedPanel; @@ -175,7 +175,7 @@ namespace osu.Game.Screens.Select public void SelectNextRandom() { - randomSelectedBeatmaps.Push(selectedGroup); + randomSelectedBeatmaps.Push(new KeyValuePair(selectedGroup, selectedGroup.SelectedPanel)); var visibleGroups = getVisibleGroups(); if (!visibleGroups.Any()) @@ -214,10 +214,11 @@ namespace osu.Game.Screens.Select while (randomSelectedBeatmaps.Any()) { - var group = randomSelectedBeatmaps.Pop(); + var beatmapCoordinates = randomSelectedBeatmaps.Pop(); + var group = beatmapCoordinates.Key; if (visibleGroups.Contains(group)) { - selectGroup(group, group.SelectedPanel); + selectGroup(group, beatmapCoordinates.Value); break; } }