mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:57:52 +08:00
Add audio feedback to SwitchButton
checkbox
This commit is contained in:
parent
92cac0b74e
commit
37816ebc41
@ -4,6 +4,8 @@
|
||||
#nullable enable
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -31,6 +33,9 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
private Color4 enabledColour;
|
||||
private Color4 disabledColour;
|
||||
|
||||
private Sample? sampleChecked;
|
||||
private Sample? sampleUnchecked;
|
||||
|
||||
public SwitchButton()
|
||||
{
|
||||
Size = new Vector2(45, 20);
|
||||
@ -70,13 +75,16 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OverlayColourProvider? colourProvider, OsuColour colours)
|
||||
private void load(OverlayColourProvider? colourProvider, OsuColour colours, AudioManager audio)
|
||||
{
|
||||
enabledColour = colourProvider?.Highlight1 ?? colours.BlueDark;
|
||||
disabledColour = colourProvider?.Background3 ?? colours.Gray3;
|
||||
|
||||
switchContainer.Colour = enabledColour;
|
||||
fill.Colour = disabledColour;
|
||||
|
||||
sampleChecked = audio.Samples.Get(@"UI/check-on");
|
||||
sampleUnchecked = audio.Samples.Get(@"UI/check-off");
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -107,6 +115,16 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
protected override void OnUserChange(bool value)
|
||||
{
|
||||
base.OnUserChange(value);
|
||||
|
||||
if (value)
|
||||
sampleChecked?.Play();
|
||||
else
|
||||
sampleUnchecked?.Play();
|
||||
}
|
||||
|
||||
private void updateBorder()
|
||||
{
|
||||
circularContainer.TransformBorderTo((Current.Value ? enabledColour : disabledColour).Lighten(IsHovered ? 0.3f : 0));
|
||||
|
Loading…
Reference in New Issue
Block a user