mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Add audio feedback for rearranging list items
This commit is contained in:
parent
ac91c9de7d
commit
4a316fad2f
@ -3,9 +3,14 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Specialized;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Utils;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
@ -18,11 +23,44 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer();
|
||||
|
||||
private Sample sampleSwap;
|
||||
private double sampleLastPlaybackTime;
|
||||
|
||||
protected sealed override RearrangeableListItem<TModel> CreateDrawable(TModel item) => CreateOsuDrawable(item).With(d =>
|
||||
{
|
||||
d.DragActive.BindTo(DragActive);
|
||||
});
|
||||
|
||||
protected abstract OsuRearrangeableListItem<TModel> CreateOsuDrawable(TModel item);
|
||||
|
||||
protected OsuRearrangeableListContainer()
|
||||
{
|
||||
Items.CollectionChanged += (_, args) =>
|
||||
{
|
||||
if (args.Action == NotifyCollectionChangedAction.Move)
|
||||
playSwapSample();
|
||||
};
|
||||
}
|
||||
|
||||
private void playSwapSample()
|
||||
{
|
||||
if (Time.Current - sampleLastPlaybackTime <= 35)
|
||||
return;
|
||||
|
||||
var channel = sampleSwap?.GetChannel();
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
channel.Frequency.Value = 0.96 + RNG.NextDouble(0.08);
|
||||
channel.Play();
|
||||
sampleLastPlaybackTime = Time.Current;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
sampleSwap = audio.Samples.Get(@"UI/item-swap");
|
||||
sampleLastPlaybackTime = Time.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user