2020-03-04 11:05:23 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-04 11:05:23 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2022-12-16 19:18:02 +08:00
|
|
|
using System.Diagnostics;
|
2020-03-04 11:05:23 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2020-08-01 15:11:34 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
2020-03-04 11:05:23 +08:00
|
|
|
using osu.Game.Tournament.Models;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder.Components
|
|
|
|
{
|
2020-08-01 15:11:34 +08:00
|
|
|
public partial class SettingsTeamDropdown : SettingsDropdown<TournamentTeam>
|
2020-03-04 11:05:23 +08:00
|
|
|
{
|
|
|
|
public SettingsTeamDropdown(BindableList<TournamentTeam> teams)
|
|
|
|
{
|
|
|
|
foreach (var t in teams.Prepend(new TournamentTeam()))
|
|
|
|
add(t);
|
|
|
|
|
|
|
|
teams.CollectionChanged += (_, args) =>
|
|
|
|
{
|
|
|
|
switch (args.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2022-12-16 19:18:02 +08:00
|
|
|
Debug.Assert(args.NewItems != null);
|
|
|
|
|
2020-03-04 11:05:23 +08:00
|
|
|
args.NewItems.Cast<TournamentTeam>().ForEach(add);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2022-12-16 19:18:02 +08:00
|
|
|
Debug.Assert(args.OldItems != null);
|
|
|
|
|
2020-03-04 11:05:23 +08:00
|
|
|
args.OldItems.Cast<TournamentTeam>().ForEach(i => Control.RemoveDropdownItem(i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly List<IUnbindable> refBindables = new List<IUnbindable>();
|
|
|
|
|
|
|
|
private T boundReference<T>(T obj)
|
|
|
|
where T : IBindable
|
|
|
|
{
|
|
|
|
obj = (T)obj.GetBoundCopy();
|
|
|
|
refBindables.Add(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void add(TournamentTeam team)
|
|
|
|
{
|
|
|
|
Control.AddDropdownItem(team);
|
|
|
|
boundReference(team.FullName).BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
Control.RemoveDropdownItem(team);
|
|
|
|
Control.AddDropdownItem(team);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|