1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 14:42:57 +08:00
osu-lazer/osu.Game/Graphics/Containers/OsuRearrangeableListContainer.cs

72 lines
2.2 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#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
{
public abstract class OsuRearrangeableListContainer<TModel> : RearrangeableListContainer<TModel>
{
/// <summary>
/// Whether any item is currently being dragged. Used to hide other items' drag handles.
/// </summary>
2020-09-08 15:36:36 +08:00
protected readonly BindableBool DragActive = new BindableBool();
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 =>
{
2020-09-08 15:36:36 +08:00
d.DragActive.BindTo(DragActive);
});
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;
}
}
}