diff --git a/osu.Game.Rulesets.Osu/Objects/Slider.cs b/osu.Game.Rulesets.Osu/Objects/Slider.cs index 95fb6d9d48..77f8ec6cc8 100644 --- a/osu.Game.Rulesets.Osu/Objects/Slider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Slider.cs @@ -116,8 +116,7 @@ namespace osu.Game.Rulesets.Osu.Objects public Slider() { - SamplesBindable.ItemsAdded += _ => updateNestedSamples(); - SamplesBindable.ItemsRemoved += _ => updateNestedSamples(); + SamplesBindable.CollectionChanged += (_, __) => updateNestedSamples(); Path.Version.ValueChanged += _ => updateNestedPositions(); } diff --git a/osu.Game.Tests/Visual/Online/TestSceneLeaderboardModSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneLeaderboardModSelector.cs index e0e5a088ce..7327e80d06 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneLeaderboardModSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneLeaderboardModSelector.cs @@ -4,6 +4,8 @@ using osu.Game.Overlays.BeatmapSet; using System; using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; using osu.Framework.Graphics; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Mania; @@ -15,6 +17,7 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Bindables; using osu.Game.Graphics.Sprites; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; namespace osu.Game.Tests.Visual.Online { @@ -44,27 +47,31 @@ namespace osu.Game.Tests.Visual.Online Ruleset = { BindTarget = ruleset } }); - modSelector.SelectedMods.ItemsAdded += mods => + modSelector.SelectedMods.CollectionChanged += (_, args) => { - mods.ForEach(mod => selectedMods.Add(new OsuSpriteText + switch (args.Action) { - Text = mod.Acronym, - })); - }; - - modSelector.SelectedMods.ItemsRemoved += mods => - { - mods.ForEach(mod => - { - foreach (var selected in selectedMods) - { - if (selected.Text == mod.Acronym) + case NotifyCollectionChangedAction.Add: + args.NewItems.Cast().ForEach(mod => selectedMods.Add(new OsuSpriteText { - selectedMods.Remove(selected); - break; - } - } - }); + Text = mod.Acronym, + })); + break; + + case NotifyCollectionChangedAction.Remove: + args.OldItems.Cast().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); diff --git a/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs index 32cf6bbcc8..5598910824 100644 --- a/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // 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.Bindables; 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.ItemsRemoved += items => items.ForEach(i => flow.RemoveAll(d => d.Model == i)); + Storage.CollectionChanged += (_, args) => + { + switch (args.Action) + { + case NotifyCollectionChangedAction.Add: + args.NewItems.Cast().ForEach(i => flow.Add(CreateDrawable(i))); + break; + + case NotifyCollectionChangedAction.Remove: + args.OldItems.Cast().ForEach(i => flow.RemoveAll(d => d.Model == i)); + break; + } + }; foreach (var model in Storage) flow.Add(CreateDrawable(model)); diff --git a/osu.Game.Tournament/Screens/Ladder/Components/LadderEditorSettings.cs b/osu.Game.Tournament/Screens/Ladder/Components/LadderEditorSettings.cs index 0864d25a2f..8ab083ddaf 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/LadderEditorSettings.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/LadderEditorSettings.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -90,8 +91,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components foreach (var r in rounds.Prepend(new TournamentRound())) add(r); - rounds.ItemsRemoved += items => items.ForEach(i => Control.RemoveDropdownItem(i)); - rounds.ItemsAdded += items => items.ForEach(add); + rounds.CollectionChanged += (_, args) => + { + switch (args.Action) + { + case NotifyCollectionChangedAction.Add: + args.NewItems.Cast().ForEach(add); + break; + + case NotifyCollectionChangedAction.Remove: + args.OldItems.Cast().ForEach(i => Control.RemoveDropdownItem(i)); + break; + } + }; } private readonly List refBindables = new List(); @@ -122,8 +134,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components foreach (var t in teams.Prepend(new TournamentTeam())) add(t); - teams.ItemsRemoved += items => items.ForEach(i => Control.RemoveDropdownItem(i)); - teams.ItemsAdded += items => items.ForEach(add); + teams.CollectionChanged += (_, args) => + { + switch (args.Action) + { + case NotifyCollectionChangedAction.Add: + args.NewItems.Cast().ForEach(add); + break; + + case NotifyCollectionChangedAction.Remove: + args.OldItems.Cast().ForEach(i => Control.RemoveDropdownItem(i)); + break; + } + }; } private readonly List refBindables = new List(); diff --git a/osu.Game.Tournament/Screens/Ladder/LadderScreen.cs b/osu.Game.Tournament/Screens/Ladder/LadderScreen.cs index 66e68a0f37..8ea366e1b4 100644 --- a/osu.Game.Tournament/Screens/Ladder/LadderScreen.cs +++ b/osu.Game.Tournament/Screens/Ladder/LadderScreen.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // 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.Caching; @@ -68,22 +69,24 @@ namespace osu.Game.Tournament.Screens.Ladder foreach (var match in LadderInfo.Matches) addMatch(match); - LadderInfo.Rounds.ItemsAdded += _ => layout.Invalidate(); - LadderInfo.Rounds.ItemsRemoved += _ => layout.Invalidate(); - - LadderInfo.Matches.ItemsAdded += matches => + LadderInfo.Rounds.CollectionChanged += (_, __) => layout.Invalidate(); + LadderInfo.Matches.CollectionChanged += (_, args) => { - foreach (var p in matches) - addMatch(p); - layout.Invalidate(); - }; - - LadderInfo.Matches.ItemsRemoved += matches => - { - foreach (var p in matches) + switch (args.Action) { - foreach (var d in MatchesContainer.Where(d => d.Match == p)) - d.Expire(); + case NotifyCollectionChangedAction.Add: + foreach (var p in args.NewItems.Cast()) + addMatch(p); + break; + + case NotifyCollectionChangedAction.Remove: + foreach (var p in args.NewItems.Cast()) + { + foreach (var d in MatchesContainer.Where(d => d.Match == p)) + d.Expire(); + } + + break; } layout.Invalidate(); diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 8560232209..2d8bd10b13 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -191,8 +191,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores scope.BindValueChanged(_ => getScores()); ruleset.BindValueChanged(_ => getScores()); - modSelector.SelectedMods.ItemsAdded += _ => getScores(); - modSelector.SelectedMods.ItemsRemoved += _ => getScores(); + modSelector.SelectedMods.CollectionChanged += (_, __) => getScores(); Beatmap.BindValueChanged(onBeatmapChanged); user.BindValueChanged(onUserChanged, true); diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index d3a0b3450f..6f20bcf595 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -125,8 +125,7 @@ namespace osu.Game.Rulesets.Objects.Drawables } samplesBindable = HitObject.SamplesBindable.GetBoundCopy(); - samplesBindable.ItemsAdded += _ => loadSamples(); - samplesBindable.ItemsRemoved += _ => loadSamples(); + samplesBindable.CollectionChanged += (_, __) => loadSamples(); updateState(ArmedState.Idle, true); onDefaultsApplied(); diff --git a/osu.Game/Rulesets/Objects/SliderPath.cs b/osu.Game/Rulesets/Objects/SliderPath.cs index 62a5b6f0b5..ff5f1e3e1e 100644 --- a/osu.Game/Rulesets/Objects/SliderPath.cs +++ b/osu.Game/Rulesets/Objects/SliderPath.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using Newtonsoft.Json; using osu.Framework.Bindables; @@ -47,18 +48,20 @@ namespace osu.Game.Rulesets.Objects { ExpectedDistance.ValueChanged += _ => invalidate(); - ControlPoints.ItemsAdded += items => + ControlPoints.CollectionChanged += (_, args) => { - foreach (var c in items) - c.Changed += invalidate; + switch (args.Action) + { + case NotifyCollectionChangedAction.Add: + foreach (var c in args.NewItems.Cast()) + c.Changed += invalidate; + break; - invalidate(); - }; - - ControlPoints.ItemsRemoved += items => - { - foreach (var c in items) - c.Changed -= invalidate; + case NotifyCollectionChangedAction.Remove: + foreach (var c in args.NewItems.Cast()) + c.Changed -= invalidate; + break; + } invalidate(); }; diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 417d32ca4f..c81c6059cc 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; @@ -70,18 +71,20 @@ namespace osu.Game.Screens.Edit.Compose.Components AddBlueprintFor(obj); selectedHitObjects.BindTo(beatmap.SelectedHitObjects); - selectedHitObjects.ItemsAdded += objects => + selectedHitObjects.CollectionChanged += (selectedObjects, args) => { - foreach (var o in objects) - SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Select(); + switch (args.Action) + { + case NotifyCollectionChangedAction.Add: + foreach (var o in args.NewItems) + SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Select(); + break; - SelectionChanged?.Invoke(selectedHitObjects); - }; - - selectedHitObjects.ItemsRemoved += objects => - { - foreach (var o in objects) - SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Deselect(); + case NotifyCollectionChangedAction.Remove: + foreach (var o in args.OldItems) + SelectionBlueprints.FirstOrDefault(b => b.HitObject == o)?.Deselect(); + break; + } SelectionChanged?.Invoke(selectedHitObjects); }; diff --git a/osu.Game/Screens/Multi/Components/BeatmapTitle.cs b/osu.Game/Screens/Multi/Components/BeatmapTitle.cs index baf11dfe0d..9e7a59d7d2 100644 --- a/osu.Game/Screens/Multi/Components/BeatmapTitle.cs +++ b/osu.Game/Screens/Multi/Components/BeatmapTitle.cs @@ -26,8 +26,7 @@ namespace osu.Game.Screens.Multi.Components [BackgroundDependencyLoader] private void load() { - Playlist.ItemsAdded += _ => updateText(); - Playlist.ItemsRemoved += _ => updateText(); + Playlist.CollectionChanged += (_, __) => updateText(); updateText(); } diff --git a/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs b/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs index a1334101b8..ce3b612262 100644 --- a/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs +++ b/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs @@ -51,8 +51,7 @@ namespace osu.Game.Screens.Multi.Components } }; - Playlist.ItemsAdded += _ => updateInfo(); - Playlist.ItemsRemoved += _ => updateInfo(); + Playlist.CollectionChanged += (_, __) => updateInfo(); updateInfo(); } diff --git a/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs b/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs index 258541bbd6..0015feb26a 100644 --- a/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs +++ b/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs @@ -48,8 +48,7 @@ namespace osu.Game.Screens.Multi.Components Type.BindValueChanged(type => gameTypeContainer.Child = new DrawableGameType(type.NewValue) { Size = new Vector2(height) }, true); - Playlist.ItemsAdded += _ => updateBeatmap(); - Playlist.ItemsRemoved += _ => updateBeatmap(); + Playlist.CollectionChanged += (_, __) => updateBeatmap(); updateBeatmap(); } diff --git a/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs b/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs index 5e2f2e530a..2240e55e2f 100644 --- a/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs +++ b/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs @@ -23,8 +23,7 @@ namespace osu.Game.Screens.Multi.Components { InternalChild = sprite = CreateBackgroundSprite(); - Playlist.ItemsAdded += _ => updateBeatmap(); - Playlist.ItemsRemoved += _ => updateBeatmap(); + Playlist.CollectionChanged += (_, __) => updateBeatmap(); updateBeatmap(); } diff --git a/osu.Game/Screens/Multi/DrawableRoomPlaylist.cs b/osu.Game/Screens/Multi/DrawableRoomPlaylist.cs index b139c61166..9a3fcb1cdc 100644 --- a/osu.Game/Screens/Multi/DrawableRoomPlaylist.cs +++ b/osu.Game/Screens/Multi/DrawableRoomPlaylist.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Specialized; using osu.Framework.Bindables; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; @@ -29,10 +30,15 @@ namespace osu.Game.Screens.Multi base.LoadComplete(); // Scheduled since items are removed and re-added upon rearrangement - Items.ItemsRemoved += items => Schedule(() => + Items.CollectionChanged += (_, args) => Schedule(() => { - if (!Items.Contains(SelectedItem.Value)) - SelectedItem.Value = null; + switch (args.Action) + { + case NotifyCollectionChangedAction.Remove: + if (args.OldItems.Contains(SelectedItem)) + SelectedItem.Value = null; + break; + } }); } diff --git a/osu.Game/Screens/Multi/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/Multi/DrawableRoomPlaylistItem.cs index 75c751aa61..ca85aec4e4 100644 --- a/osu.Game/Screens/Multi/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/Multi/DrawableRoomPlaylistItem.cs @@ -84,8 +84,7 @@ namespace osu.Game.Screens.Multi beatmap.BindValueChanged(_ => scheduleRefresh()); ruleset.BindValueChanged(_ => scheduleRefresh()); - requiredMods.ItemsAdded += _ => scheduleRefresh(); - requiredMods.ItemsRemoved += _ => scheduleRefresh(); + requiredMods.CollectionChanged += (_, __) => scheduleRefresh(); refresh(); }