mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +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.Bindables;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -26,10 +27,10 @@ namespace osu.Game.Tests.Visual.Online
|
||||
public TestSceneLeaderboardModSelector()
|
||||
{
|
||||
LeaderboardModSelector modSelector;
|
||||
FillFlowContainer selectedMods;
|
||||
FillFlowContainer<SpriteText> selectedMods;
|
||||
Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||
|
||||
Add(selectedMods = new FillFlowContainer
|
||||
Add(selectedMods = new FillFlowContainer<SpriteText>
|
||||
{
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopLeft,
|
||||
@ -42,16 +43,28 @@ namespace osu.Game.Tests.Visual.Online
|
||||
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)
|
||||
selectedMods.Add(new SpriteText
|
||||
modSelector.SelectedMods.ItemsRemoved += mods =>
|
||||
{
|
||||
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("mania ruleset", () => ruleset.Value = new ManiaRuleset().RulesetInfo);
|
||||
|
@ -5,7 +5,6 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Framework.Bindables;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets;
|
||||
using osuTK;
|
||||
using osu.Game.Rulesets.UI;
|
||||
@ -21,7 +20,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
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>();
|
||||
|
||||
private readonly FillFlowContainer<ModButton> modsContainer;
|
||||
@ -47,8 +46,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
|
||||
{
|
||||
SelectedMods.Value = new List<Mod>();
|
||||
|
||||
SelectedMods.Clear();
|
||||
modsContainer.Clear();
|
||||
|
||||
if (ruleset.NewValue == null)
|
||||
@ -67,22 +65,18 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
private void selectionChanged(Mod mod, bool selected)
|
||||
{
|
||||
var mods = SelectedMods.Value.ToList();
|
||||
|
||||
if (selected)
|
||||
mods.Add(mod);
|
||||
SelectedMods.Add(mod);
|
||||
else
|
||||
mods.Remove(mod);
|
||||
SelectedMods.Remove(mod);
|
||||
|
||||
SelectedMods.Value = mods;
|
||||
|
||||
if (!mods.Any() && !IsHovered)
|
||||
if (!SelectedMods.Any() && !IsHovered)
|
||||
highlightAll();
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
if (!SelectedMods.Value.Any())
|
||||
if (!SelectedMods.Any())
|
||||
modsContainer.ForEach(button =>
|
||||
{
|
||||
if (!button.IsHovered)
|
||||
@ -96,7 +90,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
base.OnHoverLost(e);
|
||||
|
||||
if (!SelectedMods.Value.Any())
|
||||
if (!SelectedMods.Any())
|
||||
highlightAll();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user