fix checkbox sounds not being used for certain checkboxes

This commit is contained in:
Jamie Taylor
2021-06-18 21:00:08 +09:00
parent d462394635
commit 953683044f
4 changed files with 38 additions and 5 deletions

View File

@ -4,6 +4,8 @@
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -43,6 +45,8 @@ namespace osu.Game.Graphics.UserInterface
}
private const float transition_length = 500;
private Sample sampleChecked;
private Sample sampleUnchecked;
public OsuTabControlCheckbox()
{
@ -77,8 +81,7 @@ namespace osu.Game.Graphics.UserInterface
Colour = Color4.White,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
},
new HoverClickSounds()
}
};
Current.ValueChanged += selected =>
@ -91,10 +94,13 @@ namespace osu.Game.Graphics.UserInterface
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, AudioManager audio)
{
if (accentColour == null)
AccentColour = colours.Blue;
sampleChecked = audio.Samples.Get(@"UI/check-on");
sampleUnchecked = audio.Samples.Get(@"UI/check-off");
}
protected override bool OnHover(HoverEvent e)
@ -111,6 +117,16 @@ namespace osu.Game.Graphics.UserInterface
base.OnHoverLost(e);
}
protected override void OnUserChange(bool value)
{
base.OnUserChange(value);
if (value)
sampleChecked?.Play();
else
sampleUnchecked?.Play();
}
private void updateFade()
{
box.FadeTo(Current.Value || IsHovered ? 1 : 0, transition_length, Easing.OutQuint);