Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions osu.Game/Screens/SelectV2/BeatmapCarousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,12 @@ public bool NextRandom()
return false;
}

Scheduler.Add(() =>
// CurrentSelectionItem won't be valid until UpdateAfterChildren.
// We probably want to fix this at some point since a few places are working-around this quirk.
ScheduleAfterChildren(() =>
{
if (selectionBefore != null && CurrentSelectionItem != null)
playSpinSample(distanceBetween(selectionBefore, CurrentSelectionItem), carouselItems.Count);
playSpinSample(visiblePanelCountBetweenItems(selectionBefore, CurrentSelectionItem));
});

return true;
Expand Down Expand Up @@ -769,12 +771,12 @@ private bool nextRandomSet()
return true;
}

public void PreviousRandom()
public bool PreviousRandom()
{
var carouselItems = GetCarouselItems();

if (carouselItems?.Any() != true)
return;
return false;

while (randomHistory.Any())
{
Expand All @@ -784,33 +786,35 @@ public void PreviousRandom()
var previousBeatmapItem = carouselItems.FirstOrDefault(i => i.Model is BeatmapInfo b && b.Equals(previousBeatmap));

if (previousBeatmapItem == null)
return;
return false;

if (CurrentSelection is BeatmapInfo beatmapInfo)
{
if (randomAlgorithm.Value == RandomSelectAlgorithm.RandomPermutation)
previouslyVisitedRandomBeatmaps.Remove(beatmapInfo);

if (CurrentSelectionItem == null)
playSpinSample(0, carouselItems.Count);
playSpinSample(0);
else
playSpinSample(distanceBetween(previousBeatmapItem, CurrentSelectionItem), carouselItems.Count);
playSpinSample(visiblePanelCountBetweenItems(previousBeatmapItem, CurrentSelectionItem));
}

RequestSelection(previousBeatmap);
break;
return true;
}

return false;
}

private double distanceBetween(CarouselItem item1, CarouselItem item2) => Math.Ceiling(Math.Abs(item1.CarouselYPosition - item2.CarouselYPosition) / PanelBeatmapSet.HEIGHT);
private double visiblePanelCountBetweenItems(CarouselItem item1, CarouselItem item2) => Math.Ceiling(Math.Abs(item1.CarouselYPosition - item2.CarouselYPosition) / PanelBeatmapSet.HEIGHT);

private void playSpinSample(double distance, int count)
private void playSpinSample(double distance)
{
var chan = spinSample?.GetChannel();

if (chan != null)
{
chan.Frequency.Value = 1f + Math.Min(1f, distance / count);
chan.Frequency.Value = 1f + Math.Clamp(distance / 200, 0, 1);
chan.Play();
}

Expand Down
20 changes: 17 additions & 3 deletions osu.Game/Screens/SelectV2/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -103,6 +105,8 @@ public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBind

public override bool ShowFooter => true;

private Sample? errorSample;

[Resolved]
private OsuGameBase? game { get; set; }

Expand All @@ -128,8 +132,10 @@ public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBind
private IDialogOverlay? dialogOverlay { get; set; }

[BackgroundDependencyLoader]
private void load()
private void load(AudioManager audio)
{
errorSample = audio.Samples.Get(@"UI/generic-error");

AddRangeInternal(new Drawable[]
{
new GlobalScrollAdjustsVolume(),
Expand Down Expand Up @@ -286,8 +292,16 @@ private void load()
},
new FooterButtonRandom
{
NextRandom = () => carousel.NextRandom(),
PreviousRandom = () => carousel.PreviousRandom()
NextRandom = () =>
{
if (!carousel.NextRandom())
errorSample?.Play();
},
PreviousRandom = () =>
{
if (!carousel.PreviousRandom())
errorSample?.Play();
}
},
new FooterButtonOptions
{
Expand Down