Add support for Notification sounds

This commit is contained in:
Jamie Taylor 2021-01-15 15:21:50 +09:00
parent 70924319e4
commit a1ae739a62
2 changed files with 29 additions and 2 deletions

View File

@ -3,6 +3,8 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
@ -40,6 +42,11 @@ namespace osu.Game.Overlays.Notifications
/// </summary>
public virtual bool DisplayOnTop => true;
private SampleChannel samplePopIn;
private SampleChannel 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;
private readonly CloseButton closeButton;
protected Container IconContent;
@ -120,6 +127,13 @@ 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)
{
closeButton.FadeIn(75);
@ -143,6 +157,9 @@ namespace osu.Game.Overlays.Notifications
protected override void LoadComplete()
{
base.LoadComplete();
samplePopIn?.Play();
this.FadeInFromZero(200);
NotificationContent.MoveToX(DrawSize.X);
NotificationContent.MoveToX(0, 500, Easing.OutQuint);
@ -150,12 +167,17 @@ namespace osu.Game.Overlays.Notifications
public bool WasClosed;
public virtual void Close()
public virtual void Close() => Close(true);
public virtual void Close(bool playSound)
{
if (WasClosed) return;
WasClosed = true;
if (playSound)
samplePopOut?.Play();
Closed?.Invoke();
this.FadeOut(100);
Expire();

View File

@ -109,7 +109,12 @@ namespace osu.Game.Overlays.Notifications
private void clearAll()
{
notifications.Children.ForEach(c => c.Close());
bool playSound = true;
notifications.Children.ForEach(c =>
{
c.Close(playSound);
playSound = false;
});
}
protected override void Update()