1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 20:07:25 +08:00

Add audio feedback to song select 'random'

This commit is contained in:
Jamie Taylor 2022-01-28 13:27:12 +09:00
parent d1158acb82
commit f59828e2d9
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
2 changed files with 46 additions and 4 deletions

View File

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Caching; using osu.Framework.Caching;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -151,6 +153,10 @@ namespace osu.Game.Screens.Select
private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100); private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100);
private Sample spinSample;
private int visibleSetsCount;
public BeatmapCarousel() public BeatmapCarousel()
{ {
root = new CarouselRoot(this); root = new CarouselRoot(this);
@ -169,8 +175,10 @@ namespace osu.Game.Screens.Select
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config) private void load(OsuConfigManager config, AudioManager audio)
{ {
spinSample = audio.Samples.Get("SongSelect/random-spin");
config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm); config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm);
config.BindWith(OsuSetting.SongSelectRightMouseScroll, RightClickScrollingEnabled); config.BindWith(OsuSetting.SongSelectRightMouseScroll, RightClickScrollingEnabled);
@ -419,6 +427,9 @@ namespace osu.Game.Screens.Select
return false; return false;
var visibleSets = beatmapSets.Where(s => !s.Filtered.Value).ToList(); var visibleSets = beatmapSets.Where(s => !s.Filtered.Value).ToList();
visibleSetsCount = visibleSets.Count;
if (!visibleSets.Any()) if (!visibleSets.Any())
return false; return false;
@ -450,6 +461,9 @@ namespace osu.Game.Screens.Select
else else
set = visibleSets.ElementAt(RNG.Next(visibleSets.Count)); set = visibleSets.ElementAt(RNG.Next(visibleSets.Count));
if (selectedBeatmapSet != null)
playSpinSample(distanceBetween(set, selectedBeatmapSet));
select(set); select(set);
return true; return true;
} }
@ -464,12 +478,25 @@ namespace osu.Game.Screens.Select
{ {
if (RandomAlgorithm.Value == RandomSelectAlgorithm.RandomPermutation) if (RandomAlgorithm.Value == RandomSelectAlgorithm.RandomPermutation)
previouslyVisitedRandomSets.Remove(selectedBeatmapSet); previouslyVisitedRandomSets.Remove(selectedBeatmapSet);
if (selectedBeatmapSet != null)
playSpinSample(distanceBetween(beatmap, selectedBeatmapSet));
select(beatmap); select(beatmap);
break; break;
} }
} }
} }
private double distanceBetween(CarouselItem item1, CarouselItem item2) => Math.Ceiling(Math.Abs(item1.CarouselYPosition - item2.CarouselYPosition) / DrawableCarouselItem.MAX_HEIGHT);
private void playSpinSample(double distance)
{
var chan = spinSample.GetChannel();
chan.Frequency.Value = 1f + Math.Min(1f, distance / visibleSetsCount);
chan.Play();
}
private void select(CarouselItem item) private void select(CarouselItem item)
{ {
if (!AllowSelection) if (!AllowSelection)

View File

@ -100,6 +100,7 @@ namespace osu.Game.Screens.Select
private Sample sampleChangeDifficulty; private Sample sampleChangeDifficulty;
private Sample sampleChangeBeatmap; private Sample sampleChangeBeatmap;
private Sample sampleRandomBeatmap;
private Container carouselContainer; private Container carouselContainer;
@ -109,6 +110,8 @@ namespace osu.Game.Screens.Select
private double audioFeedbackLastPlaybackTime; private double audioFeedbackLastPlaybackTime;
private bool randomClicked;
[Resolved] [Resolved]
private MusicController music { get; set; } private MusicController music { get; set; }
@ -288,6 +291,7 @@ namespace osu.Game.Screens.Select
sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty"); sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty");
sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand"); sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand");
sampleRandomBeatmap = audio.Samples.Get(@"SongSelect/select-random");
SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection"); SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection");
if (dialogOverlay != null) if (dialogOverlay != null)
@ -315,8 +319,16 @@ namespace osu.Game.Screens.Select
(new FooterButtonMods { Current = Mods }, ModSelect), (new FooterButtonMods { Current = Mods }, ModSelect),
(new FooterButtonRandom (new FooterButtonRandom
{ {
NextRandom = () => Carousel.SelectNextRandom(), NextRandom = () =>
PreviousRandom = Carousel.SelectPreviousRandom {
randomClicked = true;
Carousel.SelectNextRandom();
},
PreviousRandom = () =>
{
randomClicked = true;
Carousel.SelectPreviousRandom();
}
}, null), }, null),
(new FooterButtonOptions(), BeatmapOptions) (new FooterButtonOptions(), BeatmapOptions)
}; };
@ -486,7 +498,9 @@ namespace osu.Game.Screens.Select
{ {
if (beatmap != null && beatmapInfoPrevious != null && Time.Current - audioFeedbackLastPlaybackTime >= 50) if (beatmap != null && beatmapInfoPrevious != null && Time.Current - audioFeedbackLastPlaybackTime >= 50)
{ {
if (beatmap.BeatmapSet?.ID == beatmapInfoPrevious.BeatmapSet?.ID) if (randomClicked)
sampleRandomBeatmap.Play();
else if (beatmap.BeatmapSet?.ID == beatmapInfoPrevious.BeatmapSet?.ID)
sampleChangeDifficulty.Play(); sampleChangeDifficulty.Play();
else else
sampleChangeBeatmap.Play(); sampleChangeBeatmap.Play();
@ -494,6 +508,7 @@ namespace osu.Game.Screens.Select
audioFeedbackLastPlaybackTime = Time.Current; audioFeedbackLastPlaybackTime = Time.Current;
} }
randomClicked = false;
beatmapInfoPrevious = beatmap; beatmapInfoPrevious = beatmap;
} }