1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Merge pull request #16675 from nekodex/songselect-random-sfx

Add audio feedback to song select 'random'
This commit is contained in:
Dean Herbert 2022-02-03 19:20:07 +09:00 committed by GitHub
commit dbf2a1149c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 5 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;
@ -106,7 +108,7 @@ namespace osu.Game.Screens.Select
set
{
loadedTestBeatmaps = true;
loadBeatmapSets(value);
Schedule(() => loadBeatmapSets(value));
}
}
@ -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 randomSelectionPending;
[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 = () =>
{
randomSelectionPending = true;
Carousel.SelectNextRandom();
},
PreviousRandom = () =>
{
randomSelectionPending = 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 (randomSelectionPending)
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;
}
randomSelectionPending = false;
beatmapInfoPrevious = beatmap;
}