Fix checkbox sounds playing too often

This commit is contained in:
Dean Herbert 2019-08-15 14:09:30 +09:00
parent 58258188ce
commit f7a92487ef
1 changed files with 10 additions and 14 deletions

View File

@ -72,17 +72,11 @@ public OsuCheckbox()
Current.DisabledChanged += disabled => labelText.Alpha = Nub.Alpha = disabled ? 0.3f : 1;
}
protected override void LoadComplete()
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
base.LoadComplete();
Current.ValueChanged += enabled =>
{
if (enabled.NewValue)
sampleChecked?.Play();
else
sampleUnchecked?.Play();
};
sampleChecked = audio.Samples.Get(@"UI/check-on");
sampleUnchecked = audio.Samples.Get(@"UI/check-off");
}
protected override bool OnHover(HoverEvent e)
@ -99,11 +93,13 @@ protected override void OnHoverLost(HoverLostEvent e)
base.OnHoverLost(e);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
protected override void OnUserChange(bool value)
{
sampleChecked = audio.Samples.Get(@"UI/check-on");
sampleUnchecked = audio.Samples.Get(@"UI/check-off");
base.OnUserChange(value);
if (value)
sampleChecked?.Play();
else
sampleUnchecked?.Play();
}
}
}