1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Make Ruleset a property

This commit is contained in:
Andrei Zavatski 2019-11-15 11:52:49 +03:00
parent b7efc276f1
commit 1218d41b50

View File

@ -21,7 +21,34 @@ namespace osu.Game.Overlays.BeatmapSet
public class LeaderboardModSelector : CompositeDrawable
{
public readonly BindableList<Mod> SelectedMods = new BindableList<Mod>();
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
private RulesetInfo ruleset;
public RulesetInfo Ruleset
{
get => ruleset;
set
{
if (ruleset == value)
{
DeselectAll();
return;
}
ruleset = value;
SelectedMods.Clear();
modsContainer.Clear();
if (ruleset == null)
return;
modsContainer.Add(new ModButton(new NoMod()));
modsContainer.AddRange(ruleset.CreateInstance().GetAllMods().Where(m => m.Ranked).Select(m => new ModButton(m)));
modsContainer.ForEach(button => button.OnSelectionChanged = selectionChanged);
}
}
private readonly FillFlowContainer<ModButton> modsContainer;
@ -38,26 +65,6 @@ namespace osu.Game.Overlays.BeatmapSet
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Ruleset.BindValueChanged(onRulesetChanged, true);
}
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
{
SelectedMods.Clear();
modsContainer.Clear();
if (ruleset.NewValue == null)
return;
modsContainer.Add(new ModButton(new NoMod()));
modsContainer.AddRange(ruleset.NewValue.CreateInstance().GetAllMods().Where(m => m.Ranked).Select(m => new ModButton(m)));
modsContainer.ForEach(button => button.OnSelectionChanged = selectionChanged);
}
private void selectionChanged(Mod mod, bool selected)
{
if (selected)