1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:32:55 +08:00

Fix crashes in some cases

When we want to switch ruleset from outside of the selector, but it's
blocked (multiplayer is a good example)
This commit is contained in:
EVAST9919 2019-06-10 09:18:48 +03:00
parent ec8c09dd39
commit 27163c9996

View File

@ -23,6 +23,7 @@ namespace osu.Game.Overlays.Toolbar
private const float padding = 10; private const float padding = 10;
private readonly Drawable modeButtonLine; private readonly Drawable modeButtonLine;
private RulesetStore rulesets; private RulesetStore rulesets;
private readonly Bindable<RulesetInfo> globalRuleset = new Bindable<RulesetInfo>();
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput; public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput;
public override bool HandlePositionalInput => !Current.Disabled && base.HandlePositionalInput; public override bool HandlePositionalInput => !Current.Disabled && base.HandlePositionalInput;
@ -79,17 +80,20 @@ namespace osu.Game.Overlays.Toolbar
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset) private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
{ {
this.rulesets = rulesets; this.rulesets = rulesets;
globalRuleset.BindTo(parentRuleset);
foreach (var r in rulesets.AvailableRulesets) foreach (var r in rulesets.AvailableRulesets)
{ {
AddItem(r); AddItem(r);
} }
Current.BindTo(parentRuleset); globalRuleset.BindValueChanged(globalRulesetChanged);
Current.DisabledChanged += disabledChanged; globalRuleset.DisabledChanged += disabledChanged;
Current.BindValueChanged(rulesetChanged); Current.BindValueChanged(localRulesetChanged);
} }
private void globalRulesetChanged(ValueChangedEvent<RulesetInfo> e) => Current.Value = e.NewValue;
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
base.OnKeyDown(e); base.OnKeyDown(e);
@ -109,8 +113,13 @@ namespace osu.Game.Overlays.Toolbar
private readonly Cached activeMode = new Cached(); private readonly Cached activeMode = new Cached();
private void rulesetChanged(ValueChangedEvent<RulesetInfo> e) private void localRulesetChanged(ValueChangedEvent<RulesetInfo> e)
{ {
if (!globalRuleset.Disabled)
{
globalRuleset.Value = e.NewValue;
}
activeMode.Invalidate(); activeMode.Invalidate();
} }