mirror of
https://github.com/ppy/osu.git
synced 2026-06-09 01:43:39 +08:00
@@ -1,13 +1,10 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Utils;
|
||||
@@ -21,10 +18,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public partial class HoverClickSounds : HoverSounds
|
||||
{
|
||||
public Bindable<bool> Enabled = new Bindable<bool>(true);
|
||||
|
||||
private Sample sampleClick;
|
||||
private Sample sampleClickDisabled;
|
||||
private Sample? sampleClick;
|
||||
private Sample? sampleClickDisabled;
|
||||
|
||||
private readonly MouseButton[] buttons;
|
||||
|
||||
@@ -36,7 +31,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// Array of button codes which should trigger the click sound.
|
||||
/// If this optional parameter is omitted or set to <code>null</code>, the click sound will only be played on left click.
|
||||
/// </param>
|
||||
public HoverClickSounds(HoverSampleSet sampleSet = HoverSampleSet.Default, MouseButton[] buttons = null)
|
||||
public HoverClickSounds(HoverSampleSet sampleSet = HoverSampleSet.Default, MouseButton[]? buttons = null)
|
||||
: base(sampleSet)
|
||||
{
|
||||
this.buttons = buttons ?? new[] { MouseButton.Left };
|
||||
@@ -60,14 +55,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
public override void PlayHoverSample()
|
||||
{
|
||||
if (!Enabled.Value)
|
||||
return;
|
||||
|
||||
base.PlayHoverSample();
|
||||
}
|
||||
|
||||
public void PlayClickSample()
|
||||
{
|
||||
var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Utils;
|
||||
@@ -18,6 +19,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public partial class HoverSounds : HoverSampleDebounceComponent
|
||||
{
|
||||
public readonly Bindable<bool> Enabled = new Bindable<bool>(true);
|
||||
|
||||
private Sample sampleHover;
|
||||
|
||||
protected readonly HoverSampleSet SampleSet;
|
||||
@@ -37,6 +40,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
public override void PlayHoverSample()
|
||||
{
|
||||
if (!Enabled.Value)
|
||||
return;
|
||||
|
||||
sampleHover.Frequency.Value = 0.98 + RNG.NextDouble(0.04);
|
||||
sampleHover.Play();
|
||||
}
|
||||
|
||||
@@ -88,10 +88,6 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
Children = new Drawable[]
|
||||
{
|
||||
background = new FormControlBackground(),
|
||||
new HoverClickSounds(HoverSampleSet.Button)
|
||||
{
|
||||
Enabled = { BindTarget = Enabled },
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
|
||||
@@ -7,6 +7,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@@ -52,6 +53,8 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
|
||||
private readonly Box box;
|
||||
|
||||
private readonly HoverSounds sounds;
|
||||
|
||||
public FormControlBackground()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
@@ -69,6 +72,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
Colour = Color4.White,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
sounds = new HoverSounds(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -87,6 +91,8 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
|
||||
private void updateStyling()
|
||||
{
|
||||
sounds.Enabled.Value = !styleDisabled;
|
||||
|
||||
ColourInfo colour = colourProvider.Background4.Darken(0.1f);
|
||||
ColourInfo borderColour = colourProvider.Light4;
|
||||
|
||||
|
||||
@@ -203,11 +203,6 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
AddInternal(new HoverClickSounds
|
||||
{
|
||||
Enabled = { BindTarget = Enabled },
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
||||
@@ -451,7 +451,6 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
private Box leftBox = null!;
|
||||
private Box rightBox = null!;
|
||||
private InnerSliderNub nub = null!;
|
||||
private HoverClickSounds sounds = null!;
|
||||
public const float NUB_WIDTH = 10;
|
||||
|
||||
[Resolved]
|
||||
@@ -496,7 +495,6 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
ResetToDefault = ResetToDefault,
|
||||
}
|
||||
},
|
||||
sounds = new HoverClickSounds()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -558,7 +556,6 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
sounds.Enabled.Value = !Current.Disabled;
|
||||
rightBox.Colour = colourProvider.Background5;
|
||||
|
||||
Color4 leftColour = colourProvider.Light4;
|
||||
|
||||
Reference in New Issue
Block a user