1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 17:27:24 +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()
{
SamplesBindable.ItemsAdded += _ => updateNestedSamples();
SamplesBindable.ItemsRemoved += _ => updateNestedSamples();
SamplesBindable.CollectionChanged += (_, __) => updateNestedSamples();
Path.Version.ValueChanged += _ => updateNestedPositions();
}

View File

@ -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<Mod>().ForEach(mod => selectedMods.Add(new OsuSpriteText
{
selectedMods.Remove(selected);
break;
}
}
});
Text = mod.Acronym,
}));
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);

View File

@ -1,6 +1,8 @@
// 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.
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<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)
flow.Add(CreateDrawable(model));

View File

@ -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<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>();
@ -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<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>();

View File

@ -1,6 +1,7 @@
// 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.
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<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();

View File

@ -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);

View File

@ -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();

View File

@ -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<PathControlPoint>())
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<PathControlPoint>())
c.Changed -= invalidate;
break;
}
invalidate();
};

View File

@ -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);
};

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
// 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.
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;
}
});
}

View File

@ -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();
}