// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics.UserInterface; using osu.Framework.Bindables; using osu.Framework.Allocation; namespace osu.Game.Rulesets { public abstract class RulesetSelector : TabControl { protected RulesetStore AvaliableRulesets; protected readonly Bindable GlobalRuleset = new Bindable(); protected override Dropdown CreateDropdown() => null; /// /// Whether we want to change a global ruleset when local one is changed. /// protected virtual bool AllowGlobalRulesetChange => true; /// /// Whether we want to change a local ruleset when global one is changed. /// /// protected virtual bool AllowLocalRulesetChange => true; [BackgroundDependencyLoader] private void load(RulesetStore rulesets, Bindable parentRuleset) { AvaliableRulesets = rulesets; GlobalRuleset.BindTo(parentRuleset); foreach (var r in rulesets.AvailableRulesets) { AddItem(r); } GlobalRuleset.BindValueChanged(globalRulesetChanged); Current.BindValueChanged(OnLocalRulesetChanged); } private void globalRulesetChanged(ValueChangedEvent e) { if (AllowLocalRulesetChange) { OnGlobalRulesetChanged(e); } } protected virtual void OnGlobalRulesetChanged(ValueChangedEvent e) { Current.Value = e.NewValue; } protected virtual void OnLocalRulesetChanged(ValueChangedEvent e) { if (!GlobalRuleset.Disabled && AllowGlobalRulesetChange) { GlobalRuleset.Value = e.NewValue; } } } }