1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 07:22:55 +08:00

Merge pull request #18818 from nekodex/rearrangeable-list-feedback

Add audio feedback for rearranging list items
This commit is contained in:
Dean Herbert 2022-06-23 23:30:55 +09:00 committed by GitHub
commit 730228ec2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 3 deletions

View File

@ -51,7 +51,7 @@
<Reference Include="Java.Interop" /> <Reference Include="Java.Interop" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.618.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2022.623.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.621.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2022.621.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">

View File

@ -3,9 +3,14 @@
#nullable disable #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.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
{ {
@ -18,11 +23,49 @@ namespace osu.Game.Graphics.Containers
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer(); 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 => protected sealed override RearrangeableListItem<TModel> CreateDrawable(TModel item) => CreateOsuDrawable(item).With(d =>
{ {
d.DragActive.BindTo(DragActive); d.DragActive.BindTo(DragActive);
}); });
protected abstract OsuRearrangeableListItem<TModel> CreateOsuDrawable(TModel item); protected abstract OsuRearrangeableListItem<TModel> CreateOsuDrawable(TModel item);
protected override void LoadComplete()
{
base.LoadComplete();
Items.CollectionChanged += (_, args) =>
{
if (args.Action == NotifyCollectionChangedAction.Move)
playSwapSample();
};
}
private void playSwapSample()
{
if (!DragActive.Value)
return;
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;
}
} }
} }

View File

@ -37,7 +37,7 @@
</PackageReference> </PackageReference>
<PackageReference Include="Realm" Version="10.14.0" /> <PackageReference Include="Realm" Version="10.14.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.621.0" /> <PackageReference Include="ppy.osu.Framework" Version="2022.621.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.618.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2022.623.0" />
<PackageReference Include="Sentry" Version="3.17.1" /> <PackageReference Include="Sentry" Version="3.17.1" />
<PackageReference Include="SharpCompress" Version="0.31.0" /> <PackageReference Include="SharpCompress" Version="0.31.0" />
<PackageReference Include="NUnit" Version="3.13.3" /> <PackageReference Include="NUnit" Version="3.13.3" />

View File

@ -62,7 +62,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2022.621.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2022.621.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.618.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2022.623.0" />
</ItemGroup> </ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net6.0) --> <!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net6.0) -->
<PropertyGroup> <PropertyGroup>