1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-03 02:31:25 +08:00

Add sounds

This commit is contained in:
Dan Balasescu
2025-09-24 19:47:13 +09:00
Unverified
parent 3176006510
commit 3c37fb11be
3 changed files with 38 additions and 19 deletions
@@ -42,18 +42,20 @@ namespace osu.Game.Graphics.UserInterface
this.buttons = buttons ?? new[] { MouseButton.Left };
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select")
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select");
sampleClickDisabled = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select-disabled")
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select-disabled");
}
protected override bool OnClick(ClickEvent e)
{
if (buttons.Contains(e.Button))
{
var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();
if (channel != null)
{
channel.Frequency.Value = 0.99 + RNG.NextDouble(0.02);
channel.Play();
}
}
PlayClickSample();
return base.OnClick(e);
}
@@ -66,14 +68,15 @@ namespace osu.Game.Graphics.UserInterface
base.PlayHoverSample();
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
public void PlayClickSample()
{
sampleClick = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select")
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select");
var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();
sampleClickDisabled = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select-disabled")
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select-disabled");
if (channel != null)
{
channel.Frequency.Value = 0.99 + RNG.NextDouble(0.02);
channel.Play();
}
}
}
}
@@ -27,6 +27,7 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking
public readonly Bindable<MatchmakingPool?> SelectedPool = new Bindable<MatchmakingPool?>();
private FillFlowContainer<SelectorButton> poolFlow = null!;
private HoverClickSounds clickSounds = null!;
public MatchmakingPoolSelector()
{
@@ -36,11 +37,19 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking
[BackgroundDependencyLoader]
private void load()
{
InternalChild = poolFlow = new FillFlowContainer<SelectorButton>
InternalChildren = new Drawable[]
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(3)
poolFlow = new FillFlowContainer<SelectorButton>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(3)
},
clickSounds = new HoverClickSounds(HoverSampleSet.TabSelect)
{
// Click samples are played manually
Alpha = 0
}
};
}
@@ -61,6 +70,8 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking
if (e.Key != Key.Left && e.Key != Key.Right)
return false;
clickSounds.PlayClickSample();
if (SelectedPool.Value == null)
{
SelectedPool.Value = AvailablePools.Value[0];
@@ -458,6 +458,8 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Screens
private partial class SelectionButton : ShearedButton, IKeyBindingHandler<GlobalAction>
{
private HoverClickSounds clickSounds = null!;
public SelectionButton(float? width = null, float height = DEFAULT_HEIGHT)
: base(width, height)
{
@@ -471,6 +473,7 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Screens
if (e.Repeat)
return true;
clickSounds.PlayClickSample();
Action();
return true;
}
@@ -478,6 +481,8 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Screens
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => clickSounds = (HoverClickSounds)base.CreateHoverSounds(sampleSet);
}
}
}