// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Extensions; using osu.Framework.Input.Events; using osuTK.Input; namespace osu.Game.Graphics.UserInterface { /// /// Adds hover and click sounds to a drawable. /// Does not draw anything. /// public class HoverClickSounds : HoverSounds { private SampleChannel sampleClick; private readonly MouseButton[] buttons; /// /// a container which plays sounds on hover and click for any specified s. /// /// Set of click samples to play. /// /// Array of button codes which should trigger the click sound. /// If this optional parameter is omitted or set to null, the click sound will only be played on left click. /// public HoverClickSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal, MouseButton[] buttons = null) : base(sampleSet) { this.buttons = buttons ?? new[] { MouseButton.Left }; } protected override bool OnClick(ClickEvent e) { if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition)) sampleClick?.Play(); return base.OnClick(e); } [BackgroundDependencyLoader] private void load(AudioManager audio) { sampleClick = audio.Samples.Get($@"UI/generic-select{SampleSet.GetDescription()}"); } } }