Update grouping dropdown after new groupings are added

This commit is contained in:
Dean Herbert 2019-06-14 17:56:47 +09:00
parent d4ff9dc833
commit eb86d43d19
3 changed files with 17 additions and 7 deletions

View File

@ -13,7 +13,7 @@ public class LadderInfo
{
public List<MatchPairing> Pairings = new List<MatchPairing>();
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
public List<TournamentGrouping> Groupings = new List<TournamentGrouping>();
public BindableList<TournamentGrouping> Groupings = new BindableList<TournamentGrouping>();
public List<TournamentTeam> Teams = new List<TournamentTeam>();
[JsonIgnore]

View File

@ -68,7 +68,7 @@ private void load()
protected override void LoadComplete()
{
base.LoadComplete();
Scheduler.AddDelayed(() => LadderInfo.Groupings = items.Children.Select(c => c.Grouping).ToList(), 500, true);
Scheduler.AddDelayed(updateGroupings, 500, true);
}
private void addNew()
@ -80,12 +80,14 @@ private void addNew()
Value = DateTimeOffset.UtcNow
}
}, updateGroupings));
updateGroupings();
}
private void updateGroupings()
{
LadderInfo.Groupings = items.Children.Select(c => c.Grouping).ToList();
LadderInfo.Groupings.Clear();
LadderInfo.Groupings.AddRange(items.Children.Select(c => c.Grouping));
}
public class GroupingRow : CompositeDrawable

View File

@ -39,8 +39,6 @@ private void load()
{
var teamEntries = ladderInfo.Teams;
var groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
Children = new Drawable[]
{
new Container
@ -77,8 +75,7 @@ private void load()
textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
groupingDropdown = new SettingsDropdown<TournamentGrouping>
{
Bindable = new Bindable<TournamentGrouping> { Default = groupingOptions.First() },
Items = groupingOptions
Bindable = new Bindable<TournamentGrouping>(),
},
losersCheckbox = new PlayerCheckbox
{
@ -91,6 +88,17 @@ private void load()
}
};
var groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
void updateDropdownItems()
{
groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
groupingDropdown.Items = groupingOptions;
}
ladderInfo.Groupings.ItemsRemoved += _ => updateDropdownItems();
ladderInfo.Groupings.ItemsAdded += _ => updateDropdownItems();
editorInfo.Selected.ValueChanged += selection =>
{
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym;