mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Add debounce to notification sample playback logic
This commit is contained in:
parent
1d23ac0f2d
commit
473e15e8f3
@ -9,6 +9,7 @@ using osu.Game.Overlays.Notifications;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
@ -29,6 +30,9 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private FlowContainer<NotificationSection> sections;
|
private FlowContainer<NotificationSection> sections;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private AudioManager audio { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
@ -104,6 +108,8 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private bool processingPosts = true;
|
private bool processingPosts = true;
|
||||||
|
|
||||||
|
private double? lastSamplePlayback;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Post a new notification for display.
|
/// Post a new notification for display.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -126,6 +132,7 @@ namespace osu.Game.Overlays
|
|||||||
Show();
|
Show();
|
||||||
|
|
||||||
updateCounts();
|
updateCounts();
|
||||||
|
playDebouncedSample(notification.PopInSampleName);
|
||||||
});
|
});
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -154,7 +161,23 @@ namespace osu.Game.Overlays
|
|||||||
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notificationClosed() => updateCounts();
|
private void notificationClosed()
|
||||||
|
{
|
||||||
|
updateCounts();
|
||||||
|
|
||||||
|
// this debounce is currently shared between popin/popout sounds, which means one could potentially not play when the user is expecting it.
|
||||||
|
// popout is constant across all notification types, and should therefore be handled using playback concurrency instead, but seems broken at the moment.
|
||||||
|
playDebouncedSample("UI/overlay-pop-out");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playDebouncedSample(string sampleName)
|
||||||
|
{
|
||||||
|
if (lastSamplePlayback == null || Time.Current - lastSamplePlayback > 50)
|
||||||
|
{
|
||||||
|
audio.Samples.Get(sampleName)?.Play();
|
||||||
|
lastSamplePlayback = Time.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateCounts()
|
private void updateCounts()
|
||||||
{
|
{
|
||||||
|
@ -3,20 +3,18 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
|
||||||
using osu.Framework.Audio.Sample;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osuTK;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Notifications
|
namespace osu.Game.Overlays.Notifications
|
||||||
{
|
{
|
||||||
@ -42,10 +40,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual bool DisplayOnTop => true;
|
public virtual bool DisplayOnTop => true;
|
||||||
|
|
||||||
private Sample samplePopIn;
|
public virtual string PopInSampleName => "UI/notification-pop-in";
|
||||||
private Sample samplePopOut;
|
|
||||||
protected virtual string PopInSampleName => "UI/notification-pop-in";
|
|
||||||
protected virtual string PopOutSampleName => "UI/overlay-pop-out"; // TODO: replace with a unique sample?
|
|
||||||
|
|
||||||
protected NotificationLight Light;
|
protected NotificationLight Light;
|
||||||
private readonly CloseButton closeButton;
|
private readonly CloseButton closeButton;
|
||||||
@ -114,7 +109,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
closeButton = new CloseButton
|
closeButton = new CloseButton
|
||||||
{
|
{
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
Action = () => Close(),
|
Action = Close,
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Margin = new MarginPadding
|
Margin = new MarginPadding
|
||||||
@ -127,13 +122,6 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(AudioManager audio)
|
|
||||||
{
|
|
||||||
samplePopIn = audio.Samples.Get(PopInSampleName);
|
|
||||||
samplePopOut = audio.Samples.Get(PopOutSampleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
closeButton.FadeIn(75);
|
closeButton.FadeIn(75);
|
||||||
@ -158,8 +146,6 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
samplePopIn?.Play();
|
|
||||||
|
|
||||||
this.FadeInFromZero(200);
|
this.FadeInFromZero(200);
|
||||||
NotificationContent.MoveToX(DrawSize.X);
|
NotificationContent.MoveToX(DrawSize.X);
|
||||||
NotificationContent.MoveToX(0, 500, Easing.OutQuint);
|
NotificationContent.MoveToX(0, 500, Easing.OutQuint);
|
||||||
@ -167,15 +153,12 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
|
|
||||||
public bool WasClosed;
|
public bool WasClosed;
|
||||||
|
|
||||||
public virtual void Close(bool playSound = true)
|
public virtual void Close()
|
||||||
{
|
{
|
||||||
if (WasClosed) return;
|
if (WasClosed) return;
|
||||||
|
|
||||||
WasClosed = true;
|
WasClosed = true;
|
||||||
|
|
||||||
if (playSound)
|
|
||||||
samplePopOut?.Play();
|
|
||||||
|
|
||||||
Closed?.Invoke();
|
Closed?.Invoke();
|
||||||
this.FadeOut(100);
|
this.FadeOut(100);
|
||||||
Expire();
|
Expire();
|
||||||
|
@ -110,12 +110,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
|
|
||||||
private void clearAll()
|
private void clearAll()
|
||||||
{
|
{
|
||||||
bool first = true;
|
notifications.Children.ForEach(c => c.Close());
|
||||||
notifications.Children.ForEach(c =>
|
|
||||||
{
|
|
||||||
c.Close(first);
|
|
||||||
first = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
|
@ -150,12 +150,12 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
colourCancelled = colours.Red;
|
colourCancelled = colours.Red;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Close(bool playSound = true)
|
public override void Close()
|
||||||
{
|
{
|
||||||
switch (State)
|
switch (State)
|
||||||
{
|
{
|
||||||
case ProgressNotificationState.Cancelled:
|
case ProgressNotificationState.Cancelled:
|
||||||
base.Close(playSound);
|
base.Close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProgressNotificationState.Active:
|
case ProgressNotificationState.Active:
|
||||||
|
@ -7,7 +7,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
{
|
{
|
||||||
public class SimpleErrorNotification : SimpleNotification
|
public class SimpleErrorNotification : SimpleNotification
|
||||||
{
|
{
|
||||||
protected override string PopInSampleName => "UI/error-notification-pop-in";
|
public override string PopInSampleName => "UI/error-notification-pop-in";
|
||||||
|
|
||||||
public SimpleErrorNotification()
|
public SimpleErrorNotification()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user