1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 06:37:19 +08:00

Use SkinnableSound to ensure samples track active skin

This commit is contained in:
Dean Herbert 2025-03-09 23:47:29 +09:00
parent 50131ee5d0
commit 0a6c212153
No known key found for this signature in database
2 changed files with 10 additions and 29 deletions

View File

@ -3,7 +3,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Utils;
@ -21,18 +20,14 @@ namespace osu.Game.Screens.Menu
[Resolved]
private GameHost host { get; set; } = null!;
[Resolved]
private ISkinSource skin { get; set; } = null!;
private ISample? sample;
private SampleChannel? sampleChannel;
private SkinnableSound? sample;
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Both;
Children = new[]
Children = new Drawable[]
{
leftFountain = new StarFountain
{
@ -46,9 +41,8 @@ namespace osu.Game.Screens.Menu
Origin = Anchor.BottomRight,
X = -250,
},
sample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot"))
};
sample = skin.GetSample(new SampleInfo(@"Gameplay/fountain-shoot"));
}
private bool isTriggered;
@ -89,13 +83,9 @@ namespace osu.Game.Screens.Menu
break;
}
// Don't play SFX when game is in background
if (!host.IsActive.Value) return;
// Track sample channel to avoid overlapping playback
sampleChannel?.Stop();
sampleChannel = sample?.GetChannel();
sampleChannel?.Play();
// Don't play SFX when game is in background as it can be a bit noisy.
if (host.IsActive.Value)
sample?.Play();
}
}
}

View File

@ -3,7 +3,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
@ -22,11 +21,7 @@ namespace osu.Game.Screens.Play
private Bindable<bool> kiaiStarFountains = null!;
[Resolved]
private ISkinSource skin { get; set; } = null!;
private ISample? sample;
private SampleChannel? sampleChannel;
private SkinnableSound? sample;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
@ -35,7 +30,7 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both;
Children = new[]
Children = new Drawable[]
{
leftFountain = new GameplayStarFountain
{
@ -49,9 +44,8 @@ namespace osu.Game.Screens.Play
Origin = Anchor.BottomRight,
X = -75,
},
sample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot"))
};
sample = skin.GetSample(new SampleInfo(@"Gameplay/fountain-shoot"));
}
private bool isTriggered;
@ -78,10 +72,7 @@ namespace osu.Game.Screens.Play
leftFountain.Shoot(1);
rightFountain.Shoot(-1);
// Track sample channel to avoid overlapping playback
sampleChannel?.Stop();
sampleChannel = sample?.GetChannel();
sampleChannel?.Play();
sample?.Play();
}
public partial class GameplayStarFountain : StarFountain