mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Merge branch 'master' into non-concurrent-sample-playback
This commit is contained in:
@ -5,12 +5,10 @@ using System.ComponentModel;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Framework.Utils;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -18,19 +16,12 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// Adds hover sounds to a drawable.
|
||||
/// Does not draw anything.
|
||||
/// </summary>
|
||||
public class HoverSounds : CompositeDrawable
|
||||
public class HoverSounds : HoverSampleDebounceComponent
|
||||
{
|
||||
private Sample sampleHover;
|
||||
|
||||
/// <summary>
|
||||
/// Length of debounce for hover sound playback, in milliseconds.
|
||||
/// </summary>
|
||||
public double HoverDebounceTime { get; } = 20;
|
||||
|
||||
protected readonly HoverSampleSet SampleSet;
|
||||
|
||||
private Bindable<double?> lastPlaybackTime;
|
||||
|
||||
public HoverSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal)
|
||||
{
|
||||
SampleSet = sampleSet;
|
||||
@ -40,22 +31,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio, SessionStatics statics)
|
||||
{
|
||||
lastPlaybackTime = statics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime);
|
||||
|
||||
sampleHover = audio.Samples.Get($@"UI/generic-hover{SampleSet.GetDescription()}");
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
public override void PlayHoverSample()
|
||||
{
|
||||
bool enoughTimePassedSinceLastPlayback = !lastPlaybackTime.Value.HasValue || Time.Current - lastPlaybackTime.Value >= HoverDebounceTime;
|
||||
|
||||
if (enoughTimePassedSinceLastPlayback)
|
||||
{
|
||||
sampleHover?.Play();
|
||||
lastPlaybackTime.Value = Time.Current;
|
||||
}
|
||||
|
||||
return base.OnHover(e);
|
||||
sampleHover.Frequency.Value = 0.96 + RNG.NextDouble(0.08);
|
||||
sampleHover.Play();
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +50,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Normal,
|
||||
|
||||
[Description("-softer")]
|
||||
Soft
|
||||
Soft,
|
||||
|
||||
[Description("-toolbar")]
|
||||
Toolbar
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user