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