mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 15:03:16 +08:00
Use BindableList for selected mods
This commit is contained in:
parent
e3d8e29cdd
commit
93954c8da0
@ -13,6 +13,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
@ -26,10 +27,10 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
public TestSceneLeaderboardModSelector()
|
public TestSceneLeaderboardModSelector()
|
||||||
{
|
{
|
||||||
LeaderboardModSelector modSelector;
|
LeaderboardModSelector modSelector;
|
||||||
FillFlowContainer selectedMods;
|
FillFlowContainer<SpriteText> selectedMods;
|
||||||
Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||||
|
|
||||||
Add(selectedMods = new FillFlowContainer
|
Add(selectedMods = new FillFlowContainer<SpriteText>
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopLeft,
|
Anchor = Anchor.TopLeft,
|
||||||
Origin = Anchor.TopLeft,
|
Origin = Anchor.TopLeft,
|
||||||
@ -42,16 +43,28 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
Ruleset = { BindTarget = ruleset }
|
Ruleset = { BindTarget = ruleset }
|
||||||
});
|
});
|
||||||
|
|
||||||
modSelector.SelectedMods.BindValueChanged(mods =>
|
modSelector.SelectedMods.ItemsAdded += mods =>
|
||||||
{
|
{
|
||||||
selectedMods.Clear();
|
mods.ForEach(mod => selectedMods.Add(new SpriteText
|
||||||
|
{
|
||||||
|
Text = mod.Acronym,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
foreach (var mod in mods.NewValue)
|
modSelector.SelectedMods.ItemsRemoved += mods =>
|
||||||
selectedMods.Add(new SpriteText
|
{
|
||||||
|
mods.ForEach(mod =>
|
||||||
|
{
|
||||||
|
foreach (var selected in selectedMods)
|
||||||
{
|
{
|
||||||
Text = mod.Acronym,
|
if (selected.Text == mod.Acronym)
|
||||||
});
|
{
|
||||||
});
|
selectedMods.Remove(selected);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
AddStep("osu ruleset", () => ruleset.Value = new OsuRuleset().RulesetInfo);
|
AddStep("osu ruleset", () => ruleset.Value = new OsuRuleset().RulesetInfo);
|
||||||
AddStep("mania ruleset", () => ruleset.Value = new ManiaRuleset().RulesetInfo);
|
AddStep("mania ruleset", () => ruleset.Value = new ManiaRuleset().RulesetInfo);
|
||||||
|
@ -5,7 +5,6 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
@ -21,7 +20,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
{
|
{
|
||||||
public class LeaderboardModSelector : CompositeDrawable
|
public class LeaderboardModSelector : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>();
|
public readonly BindableList<Mod> SelectedMods = new BindableList<Mod>();
|
||||||
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
||||||
|
|
||||||
private readonly FillFlowContainer<ModButton> modsContainer;
|
private readonly FillFlowContainer<ModButton> modsContainer;
|
||||||
@ -47,8 +46,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
|
|
||||||
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
|
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
|
||||||
{
|
{
|
||||||
SelectedMods.Value = new List<Mod>();
|
SelectedMods.Clear();
|
||||||
|
|
||||||
modsContainer.Clear();
|
modsContainer.Clear();
|
||||||
|
|
||||||
if (ruleset.NewValue == null)
|
if (ruleset.NewValue == null)
|
||||||
@ -67,22 +65,18 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
|
|
||||||
private void selectionChanged(Mod mod, bool selected)
|
private void selectionChanged(Mod mod, bool selected)
|
||||||
{
|
{
|
||||||
var mods = SelectedMods.Value.ToList();
|
|
||||||
|
|
||||||
if (selected)
|
if (selected)
|
||||||
mods.Add(mod);
|
SelectedMods.Add(mod);
|
||||||
else
|
else
|
||||||
mods.Remove(mod);
|
SelectedMods.Remove(mod);
|
||||||
|
|
||||||
SelectedMods.Value = mods;
|
if (!SelectedMods.Any() && !IsHovered)
|
||||||
|
|
||||||
if (!mods.Any() && !IsHovered)
|
|
||||||
highlightAll();
|
highlightAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
if (!SelectedMods.Value.Any())
|
if (!SelectedMods.Any())
|
||||||
modsContainer.ForEach(button =>
|
modsContainer.ForEach(button =>
|
||||||
{
|
{
|
||||||
if (!button.IsHovered)
|
if (!button.IsHovered)
|
||||||
@ -96,7 +90,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
{
|
{
|
||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
|
|
||||||
if (!SelectedMods.Value.Any())
|
if (!SelectedMods.Any())
|
||||||
highlightAll();
|
highlightAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user