1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +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.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Graphics;
@ -151,6 +153,10 @@ namespace osu.Game.Screens.Select
private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100);
private Sample spinSample;
private int visibleSetsCount;
public BeatmapCarousel()
{
root = new CarouselRoot(this);
@ -169,8 +175,10 @@ namespace osu.Game.Screens.Select
}
[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.SongSelectRightMouseScroll, RightClickScrollingEnabled);
@ -419,6 +427,9 @@ namespace osu.Game.Screens.Select
return false;
var visibleSets = beatmapSets.Where(s => !s.Filtered.Value).ToList();
visibleSetsCount = visibleSets.Count;
if (!visibleSets.Any())
return false;
@ -450,6 +461,9 @@ namespace osu.Game.Screens.Select
else
set = visibleSets.ElementAt(RNG.Next(visibleSets.Count));
if (selectedBeatmapSet != null)
playSpinSample(distanceBetween(set, selectedBeatmapSet));
select(set);
return true;
}
@ -464,12 +478,25 @@ namespace osu.Game.Screens.Select
{
if (RandomAlgorithm.Value == RandomSelectAlgorithm.RandomPermutation)
previouslyVisitedRandomSets.Remove(selectedBeatmapSet);
if (selectedBeatmapSet != null)
playSpinSample(distanceBetween(beatmap, selectedBeatmapSet));
select(beatmap);
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)
{
if (!AllowSelection)

View File

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