1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Implement sample choking/muting for ButtonSystem samples

This commit is contained in:
Jamie Taylor 2023-11-08 22:18:33 +09:00
parent f0a1df06ac
commit f69c2ea39b
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
4 changed files with 26 additions and 2 deletions

View File

@ -199,6 +199,7 @@ namespace osu.Game.Screens.Menu
{
if (State == ButtonSystemState.Initial)
{
StopSamplePlayback();
logo?.TriggerClick();
return true;
}
@ -264,12 +265,14 @@ namespace osu.Game.Screens.Menu
State = ButtonSystemState.Initial;
// Samples are explicitly played here in response to user interaction and not when transitioning due to idle.
StopSamplePlayback();
sampleBackToLogo?.Play();
sampleLogoSwoosh?.Play();
return true;
case ButtonSystemState.Play:
StopSamplePlayback();
backButton.TriggerClick();
return true;
@ -278,6 +281,13 @@ namespace osu.Game.Screens.Menu
}
}
public void StopSamplePlayback()
{
buttonsPlay.ForEach(button => button.StopSamplePlayback());
buttonsTopLevel.ForEach(button => button.StopSamplePlayback());
logo?.StopSamplePlayback();
}
private bool onOsuLogo()
{
switch (state)

View File

@ -297,6 +297,8 @@ namespace osu.Game.Screens.Menu
{
base.OnResuming(e);
// Ensures any playing `ButtonSystem` samples are stopped when returning to MainMenu (as to not overlap with the 'back' sample)
Buttons.StopSamplePlayback();
reappearSampleSwoosh?.Play();
ApplyToBackground(b => (b as BackgroundScreenDefault)?.Next());

View File

@ -51,6 +51,7 @@ namespace osu.Game.Screens.Menu
private readonly Action clickAction;
private Sample sampleClick;
private Sample sampleHover;
private SampleChannel sampleChannel;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => box.ReceivePositionalInputAt(screenSpacePos);
@ -225,7 +226,8 @@ namespace osu.Game.Screens.Menu
private void trigger()
{
sampleClick?.Play();
sampleChannel = sampleClick?.GetChannel();
sampleChannel?.Play();
clickAction?.Invoke();
@ -237,6 +239,8 @@ namespace osu.Game.Screens.Menu
public override bool HandleNonPositionalInput => state == ButtonState.Expanded;
public override bool HandlePositionalInput => state != ButtonState.Exploded && box.Scale.X >= 0.8f;
public void StopSamplePlayback() => sampleChannel?.Stop();
protected override void Update()
{
iconText.Alpha = Math.Clamp((box.Scale.X - 0.5f) / 0.3f, 0, 1);

View File

@ -52,6 +52,8 @@ namespace osu.Game.Screens.Menu
private readonly IntroSequence intro;
private Sample sampleClick;
private SampleChannel sampleClickChannel;
private Sample sampleBeat;
private Sample sampleDownbeat;
@ -391,7 +393,11 @@ namespace osu.Game.Screens.Menu
flashLayer.FadeOut(1500, Easing.OutExpo);
if (Action?.Invoke() == true)
sampleClick.Play();
{
StopSamplePlayback();
sampleClickChannel = sampleClick.GetChannel();
sampleClickChannel.Play();
}
return true;
}
@ -440,6 +446,8 @@ namespace osu.Game.Screens.Menu
private Container currentProxyTarget;
private Drawable proxy;
public void StopSamplePlayback() => sampleClickChannel?.Stop();
public Drawable ProxyToContainer(Container c)
{
if (currentProxyTarget != null)