1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-08 02:15:08 +08:00

Update with framework-side bindable list changes

This commit is contained in:
smoogipoo 2020-02-17 15:06:14 +09:00
parent 6fd5667ff4
commit 958c891d15
15 changed files with 127 additions and 77 deletions

View File

@ -116,8 +116,7 @@ namespace osu.Game.Rulesets.Osu.Objects
public Slider() public Slider()
{ {
SamplesBindable.ItemsAdded += _ => updateNestedSamples(); SamplesBindable.CollectionChanged += (_, __) => updateNestedSamples();
SamplesBindable.ItemsRemoved += _ => updateNestedSamples();
Path.Version.ValueChanged += _ => updateNestedPositions(); Path.Version.ValueChanged += _ => updateNestedPositions();
} }

View File

@ -4,6 +4,8 @@
using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania;
@ -15,6 +17,7 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -44,27 +47,31 @@ namespace osu.Game.Tests.Visual.Online
Ruleset = { BindTarget = ruleset } Ruleset = { BindTarget = ruleset }
}); });
modSelector.SelectedMods.ItemsAdded += mods => modSelector.SelectedMods.CollectionChanged += (_, args) =>
{ {
mods.ForEach(mod => selectedMods.Add(new OsuSpriteText switch (args.Action)
{ {
Text = mod.Acronym, case NotifyCollectionChangedAction.Add:
})); args.NewItems.Cast<Mod>().ForEach(mod => selectedMods.Add(new OsuSpriteText
};
modSelector.SelectedMods.ItemsRemoved += mods =>
{
mods.ForEach(mod =>
{
foreach (var selected in selectedMods)
{
if (selected.Text == mod.Acronym)
{ {
selectedMods.Remove(selected); Text = mod.Acronym,
break; }));
} break;
}
}); case NotifyCollectionChangedAction.Remove:
args.OldItems.Cast<Mod>().ForEach(mod =>
{
foreach (var selected in selectedMods)
{
if (selected.Text == mod.Acronym)
{
selectedMods.Remove(selected);
break;
}
}
});
break;
}
}; };
AddStep("osu ruleset", () => ruleset.Value = new OsuRuleset().RulesetInfo); AddStep("osu ruleset", () => ruleset.Value = new OsuRuleset().RulesetInfo);

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Specialized;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
@ -71,8 +73,19 @@ namespace osu.Game.Tournament.Screens.Editors
} }
}); });
Storage.ItemsAdded += items => items.ForEach(i => flow.Add(CreateDrawable(i))); Storage.CollectionChanged += (_, args) =>
Storage.ItemsRemoved += items => items.ForEach(i => flow.RemoveAll(d => d.Model == i)); {
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
args.NewItems.Cast<TModel>().ForEach(i => flow.Add(CreateDrawable(i)));
break;
case NotifyCollectionChangedAction.Remove:
args.OldItems.Cast<TModel>().ForEach(i => flow.RemoveAll(d => d.Model == i));
break;
}
};
foreach (var model in Storage) foreach (var model in Storage)
flow.Add(CreateDrawable(model)); flow.Add(CreateDrawable(model));

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -90,8 +91,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
foreach (var r in rounds.Prepend(new TournamentRound())) foreach (var r in rounds.Prepend(new TournamentRound()))
add(r); add(r);
rounds.ItemsRemoved += items => items.ForEach(i => Control.RemoveDropdownItem(i)); rounds.CollectionChanged += (_, args) =>
rounds.ItemsAdded += items => items.ForEach(add); {
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
args.NewItems.Cast<TournamentRound>().ForEach(add);
break;
case NotifyCollectionChangedAction.Remove:
args.OldItems.Cast<TournamentRound>().ForEach(i => Control.RemoveDropdownItem(i));
break;
}
};
} }
private readonly List<IUnbindable> refBindables = new List<IUnbindable>(); private readonly List<IUnbindable> refBindables = new List<IUnbindable>();
@ -122,8 +134,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
foreach (var t in teams.Prepend(new TournamentTeam())) foreach (var t in teams.Prepend(new TournamentTeam()))
add(t); add(t);
teams.ItemsRemoved += items => items.ForEach(i => Control.RemoveDropdownItem(i)); teams.CollectionChanged += (_, args) =>
teams.ItemsAdded += items => items.ForEach(add); {
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
args.NewItems.Cast<TournamentTeam>().ForEach(add);
break;
case NotifyCollectionChangedAction.Remove:
args.OldItems.Cast<TournamentTeam>().ForEach(i => Control.RemoveDropdownItem(i));
break;
}
};
} }
private readonly List<IUnbindable> refBindables = new List<IUnbindable>(); private readonly List<IUnbindable> refBindables = new List<IUnbindable>();

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Caching; using osu.Framework.Caching;
@ -68,22 +69,24 @@ namespace osu.Game.Tournament.Screens.Ladder
foreach (var match in LadderInfo.Matches) foreach (var match in LadderInfo.Matches)
addMatch(match); addMatch(match);
LadderInfo.Rounds.ItemsAdded += _ => layout.Invalidate(); LadderInfo.Rounds.CollectionChanged += (_, __) => layout.Invalidate();
LadderInfo.Rounds.ItemsRemoved += _ => layout.Invalidate(); LadderInfo.Matches.CollectionChanged += (_, args) =>
LadderInfo.Matches.ItemsAdded += matches =>
{ {
foreach (var p in matches) switch (args.Action)
addMatch(p);
layout.Invalidate();
};
LadderInfo.Matches.ItemsRemoved += matches =>
{
foreach (var p in matches)
{ {
foreach (var d in MatchesContainer.Where(d => d.Match == p)) case NotifyCollectionChangedAction.Add:
d.Expire(); foreach (var p in args.NewItems.Cast<TournamentMatch>())
addMatch(p);
break;
case NotifyCollectionChangedAction.Remove:
foreach (var p in args.NewItems.Cast<TournamentMatch>())
{
foreach (var d in MatchesContainer.Where(d => d.Match == p))
d.Expire();
}
break;
} }
layout.Invalidate(); layout.Invalidate();

View File

@ -191,8 +191,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
scope.BindValueChanged(_ => getScores()); scope.BindValueChanged(_ => getScores());
ruleset.BindValueChanged(_ => getScores()); ruleset.BindValueChanged(_ => getScores());
modSelector.SelectedMods.ItemsAdded += _ => getScores(); modSelector.SelectedMods.CollectionChanged += (_, __) => getScores();
modSelector.SelectedMods.ItemsRemoved += _ => getScores();
Beatmap.BindValueChanged(onBeatmapChanged); Beatmap.BindValueChanged(onBeatmapChanged);
user.BindValueChanged(onUserChanged, true); user.BindValueChanged(onUserChanged, true);

View File

@ -125,8 +125,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
} }
samplesBindable = HitObject.SamplesBindable.GetBoundCopy(); samplesBindable = HitObject.SamplesBindable.GetBoundCopy();
samplesBindable.ItemsAdded += _ => loadSamples(); samplesBindable.CollectionChanged += (_, __) => loadSamples();
samplesBindable.ItemsRemoved += _ => loadSamples();
updateState(ArmedState.Idle, true); updateState(ArmedState.Idle, true);
onDefaultsApplied(); onDefaultsApplied();

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -47,18 +48,20 @@ namespace osu.Game.Rulesets.Objects
{ {
ExpectedDistance.ValueChanged += _ => invalidate(); ExpectedDistance.ValueChanged += _ => invalidate();
ControlPoints.ItemsAdded += items => ControlPoints.CollectionChanged += (_, args) =>
{ {
foreach (var c in items) switch (args.Action)
c.Changed += invalidate; {
case NotifyCollectionChangedAction.Add:
foreach (var c in args.NewItems.Cast<PathControlPoint>())
c.Changed += invalidate;
break;
invalidate(); case NotifyCollectionChangedAction.Remove:
}; foreach (var c in args.NewItems.Cast<PathControlPoint>())
c.Changed -= invalidate;
ControlPoints.ItemsRemoved += items => break;
{ }
foreach (var c in items)
c.Changed -= invalidate;
invalidate(); invalidate();
}; };

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -70,18 +71,20 @@ namespace osu.Game.Screens.Edit.Compose.Components
AddBlueprintFor(obj); AddBlueprintFor(obj);
selectedHitObjects.BindTo(beatmap.SelectedHitObjects); selectedHitObjects.BindTo(beatmap.SelectedHitObjects);
selectedHitObjects.ItemsAdded += objects => selectedHitObjects.CollectionChanged += (selectedObjects, args) =>
{ {
foreach (var o in objects) switch (args.Action)
SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Select(); {
case NotifyCollectionChangedAction.Add:
foreach (var o in args.NewItems)
SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Select();
break;
SelectionChanged?.Invoke(selectedHitObjects); case NotifyCollectionChangedAction.Remove:
}; foreach (var o in args.OldItems)
SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Deselect();
selectedHitObjects.ItemsRemoved += objects => break;
{ }
foreach (var o in objects)
SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Deselect();
SelectionChanged?.Invoke(selectedHitObjects); SelectionChanged?.Invoke(selectedHitObjects);
}; };

View File

@ -26,8 +26,7 @@ namespace osu.Game.Screens.Multi.Components
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Playlist.ItemsAdded += _ => updateText(); Playlist.CollectionChanged += (_, __) => updateText();
Playlist.ItemsRemoved += _ => updateText();
updateText(); updateText();
} }

View File

@ -51,8 +51,7 @@ namespace osu.Game.Screens.Multi.Components
} }
}; };
Playlist.ItemsAdded += _ => updateInfo(); Playlist.CollectionChanged += (_, __) => updateInfo();
Playlist.ItemsRemoved += _ => updateInfo();
updateInfo(); updateInfo();
} }

View File

@ -48,8 +48,7 @@ namespace osu.Game.Screens.Multi.Components
Type.BindValueChanged(type => gameTypeContainer.Child = new DrawableGameType(type.NewValue) { Size = new Vector2(height) }, true); Type.BindValueChanged(type => gameTypeContainer.Child = new DrawableGameType(type.NewValue) { Size = new Vector2(height) }, true);
Playlist.ItemsAdded += _ => updateBeatmap(); Playlist.CollectionChanged += (_, __) => updateBeatmap();
Playlist.ItemsRemoved += _ => updateBeatmap();
updateBeatmap(); updateBeatmap();
} }

View File

@ -23,8 +23,7 @@ namespace osu.Game.Screens.Multi.Components
{ {
InternalChild = sprite = CreateBackgroundSprite(); InternalChild = sprite = CreateBackgroundSprite();
Playlist.ItemsAdded += _ => updateBeatmap(); Playlist.CollectionChanged += (_, __) => updateBeatmap();
Playlist.ItemsRemoved += _ => updateBeatmap();
updateBeatmap(); updateBeatmap();
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Specialized;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -29,10 +30,15 @@ namespace osu.Game.Screens.Multi
base.LoadComplete(); base.LoadComplete();
// Scheduled since items are removed and re-added upon rearrangement // Scheduled since items are removed and re-added upon rearrangement
Items.ItemsRemoved += items => Schedule(() => Items.CollectionChanged += (_, args) => Schedule(() =>
{ {
if (!Items.Contains(SelectedItem.Value)) switch (args.Action)
SelectedItem.Value = null; {
case NotifyCollectionChangedAction.Remove:
if (args.OldItems.Contains(SelectedItem))
SelectedItem.Value = null;
break;
}
}); });
} }

View File

@ -84,8 +84,7 @@ namespace osu.Game.Screens.Multi
beatmap.BindValueChanged(_ => scheduleRefresh()); beatmap.BindValueChanged(_ => scheduleRefresh());
ruleset.BindValueChanged(_ => scheduleRefresh()); ruleset.BindValueChanged(_ => scheduleRefresh());
requiredMods.ItemsAdded += _ => scheduleRefresh(); requiredMods.CollectionChanged += (_, __) => scheduleRefresh();
requiredMods.ItemsRemoved += _ => scheduleRefresh();
refresh(); refresh();
} }