1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-22 15:52:55 +08:00

Fix potential unsafe ordering of binds

This commit is contained in:
smoogipoo 2020-04-14 15:07:32 +09:00
parent 9619fb9f6a
commit 7d2d0785fd

View File

@ -26,7 +26,8 @@ namespace osu.Game.Screens.Play.HUD
private const int fade_time = 400; private const int fade_time = 400;
private Bindable<bool> enabled; private readonly Bindable<bool> enabled = new Bindable<bool>();
private Bindable<bool> configEnabled;
/// <summary> /// <summary>
/// The threshold under which the current player life should be considered low and the layer should start fading in. /// The threshold under which the current player life should be considered low and the layer should start fading in.
@ -36,6 +37,7 @@ namespace osu.Game.Screens.Play.HUD
private const float gradient_size = 0.3f; private const float gradient_size = 0.3f;
private readonly Container boxes; private readonly Container boxes;
private HealthProcessor healthProcessor;
public FailingLayer() public FailingLayer()
{ {
@ -73,16 +75,29 @@ namespace osu.Game.Screens.Play.HUD
{ {
boxes.Colour = color.Red; boxes.Colour = color.Red;
enabled = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow); configEnabled = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow);
enabled.BindValueChanged(e => this.FadeTo(e.NewValue ? 1 : 0, fade_time, Easing.OutQuint), true); enabled.BindValueChanged(e => this.FadeTo(e.NewValue ? 1 : 0, fade_time, Easing.OutQuint), true);
updateBindings();
} }
public override void BindHealthProcessor(HealthProcessor processor) public override void BindHealthProcessor(HealthProcessor processor)
{ {
base.BindHealthProcessor(processor); base.BindHealthProcessor(processor);
// don't display ever if the ruleset is not using a draining health display. healthProcessor = processor;
if (!(processor is DrainingHealthProcessor)) updateBindings();
}
private void updateBindings()
{
if (configEnabled == null || healthProcessor == null)
return;
// Don't display ever if the ruleset is not using a draining health display.
if (healthProcessor is DrainingHealthProcessor)
enabled.BindTo(configEnabled);
else
{ {
enabled.UnbindBindings(); enabled.UnbindBindings();
enabled.Value = false; enabled.Value = false;