1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:02:55 +08:00

Simplify bindables usage

This commit is contained in:
Andrei Zavatski 2019-06-18 01:11:05 +03:00
parent c95e3da3ec
commit 413c2158e2
2 changed files with 11 additions and 22 deletions

View File

@ -22,10 +22,10 @@ namespace osu.Game.Overlays.Toolbar
private const float padding = 10;
private readonly Drawable modeButtonLine;
public override bool HandleNonPositionalInput => !GlobalRuleset.Disabled && base.HandleNonPositionalInput;
public override bool HandlePositionalInput => !GlobalRuleset.Disabled && base.HandlePositionalInput;
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput;
public override bool HandlePositionalInput => !Current.Disabled && base.HandlePositionalInput;
public override bool PropagatePositionalInputSubTree => !GlobalRuleset.Disabled && base.PropagatePositionalInputSubTree;
public override bool PropagatePositionalInputSubTree => !Current.Disabled && base.PropagatePositionalInputSubTree;
private void disabledChanged(bool isDisabled) => this.FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
@ -62,7 +62,7 @@ namespace osu.Game.Overlays.Toolbar
}
});
GlobalRuleset.DisabledChanged += disabledChanged;
Current.DisabledChanged += disabledChanged;
}
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
@ -92,9 +92,9 @@ namespace osu.Game.Overlays.Toolbar
private readonly Cached activeMode = new Cached();
protected override void OnLocalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
protected override void OnRulesetChanged(ValueChangedEvent<RulesetInfo> e)
{
base.OnLocalRulesetChanged(e);
base.OnRulesetChanged(e);
activeMode.Invalidate();
}

View File

@ -8,29 +8,18 @@ namespace osu.Game.Rulesets
{
public abstract class BindableRulesetSelector : RulesetSelector
{
protected readonly Bindable<RulesetInfo> GlobalRuleset = new Bindable<RulesetInfo>();
[BackgroundDependencyLoader]
private void load(Bindable<RulesetInfo> parentRuleset)
{
GlobalRuleset.BindTo(parentRuleset);
GlobalRuleset.BindValueChanged(globalRulesetChanged);
Current.BindValueChanged(OnLocalRulesetChanged);
Current.BindTo(parentRuleset);
Current.BindValueChanged(OnRulesetChanged);
}
private void globalRulesetChanged(ValueChangedEvent<RulesetInfo> e) => OnGlobalRulesetChanged(e);
protected virtual void OnGlobalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
protected virtual void OnRulesetChanged(ValueChangedEvent<RulesetInfo> e)
{
Current.Value = e.NewValue;
}
protected virtual void OnLocalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
{
if (!GlobalRuleset.Disabled)
if (Current.Disabled)
{
GlobalRuleset.Value = e.NewValue;
return;
}
}
}