mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 00:07:20 +08:00
Simplify LadderEditorSettings implementation by using bindables directly
This commit is contained in:
parent
58136360e0
commit
be4cc8c6e1
@ -1,17 +1,13 @@
|
|||||||
// 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;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
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;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
using osu.Game.Screens.Play.PlayerSettings;
|
using osu.Game.Screens.Play.PlayerSettings;
|
||||||
using osu.Game.Tournament.Components;
|
using osu.Game.Tournament.Components;
|
||||||
@ -24,11 +20,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
|
|
||||||
protected override string Title => @"ladder";
|
protected override string Title => @"ladder";
|
||||||
|
|
||||||
private OsuTextBox textboxTeam1;
|
|
||||||
private OsuTextBox textboxTeam2;
|
|
||||||
private SettingsDropdown<TournamentGrouping> groupingDropdown;
|
private SettingsDropdown<TournamentGrouping> groupingDropdown;
|
||||||
private PlayerCheckbox losersCheckbox;
|
private PlayerCheckbox losersCheckbox;
|
||||||
private DateTextBox dateTimeBox;
|
private DateTextBox dateTimeBox;
|
||||||
|
private SettingsTeamDropdown team1Dropdown;
|
||||||
|
private SettingsTeamDropdown team2Dropdown;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private LadderEditorInfo editorInfo { get; set; }
|
private LadderEditorInfo editorInfo { get; set; }
|
||||||
@ -39,100 +35,33 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
var teamEntries = ladderInfo.Teams;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
team1Dropdown = new SettingsTeamDropdown(ladderInfo.Teams) { LabelText = "Team 1" },
|
||||||
{
|
team2Dropdown = new SettingsTeamDropdown(ladderInfo.Teams) { LabelText = "Team 2" },
|
||||||
RelativeSizeAxes = Axes.X,
|
groupingDropdown = new SettingsGroupingDropdown(ladderInfo.Groupings) { LabelText = "Grouping" },
|
||||||
AutoSizeAxes = Axes.Y,
|
losersCheckbox = new PlayerCheckbox { LabelText = "Losers Bracket" },
|
||||||
Padding = new MarginPadding { Horizontal = padding },
|
dateTimeBox = new DateTextBox { LabelText = "Match Time" },
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Text = "Team1",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
textboxTeam1 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
|
|
||||||
new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Padding = new MarginPadding { Horizontal = padding },
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Text = "Team2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
|
|
||||||
groupingDropdown = new SettingsGroupingDropdown(ladderInfo.Groupings),
|
|
||||||
losersCheckbox = new PlayerCheckbox
|
|
||||||
{
|
|
||||||
LabelText = "Losers Bracket",
|
|
||||||
Bindable = new Bindable<bool>()
|
|
||||||
},
|
|
||||||
dateTimeBox = new DateTextBox
|
|
||||||
{
|
|
||||||
Bindable = new Bindable<DateTimeOffset>()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
editorInfo.Selected.ValueChanged += selection =>
|
editorInfo.Selected.ValueChanged += selection =>
|
||||||
{
|
{
|
||||||
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym.Value;
|
groupingDropdown.Bindable = selection.NewValue?.Grouping;
|
||||||
textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym.Value;
|
losersCheckbox.Bindable = selection.NewValue?.Losers;
|
||||||
groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value;
|
dateTimeBox.Bindable = selection.NewValue?.Date;
|
||||||
losersCheckbox.Current.Value = selection.NewValue?.Losers.Value ?? false;
|
|
||||||
dateTimeBox.Bindable.Value = selection.NewValue?.Date.Value ?? DateTimeOffset.UtcNow;
|
|
||||||
};
|
|
||||||
|
|
||||||
textboxTeam1.OnCommit = (val, newText) =>
|
team1Dropdown.Bindable = selection.NewValue?.Team1;
|
||||||
{
|
team2Dropdown.Bindable = selection.NewValue?.Team2;
|
||||||
if (newText && editorInfo.Selected.Value != null)
|
|
||||||
editorInfo.Selected.Value.Team1.Value = teamEntries.FirstOrDefault(t => t.Acronym.Value == val.Text);
|
|
||||||
};
|
|
||||||
|
|
||||||
textboxTeam2.OnCommit = (val, newText) =>
|
|
||||||
{
|
|
||||||
if (newText && editorInfo.Selected.Value != null)
|
|
||||||
editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym.Value == val.Text);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
groupingDropdown.Bindable.ValueChanged += grouping =>
|
groupingDropdown.Bindable.ValueChanged += grouping =>
|
||||||
{
|
{
|
||||||
if (editorInfo.Selected.Value != null)
|
if (editorInfo.Selected.Value?.Date.Value < grouping.NewValue?.StartDate.Value)
|
||||||
{
|
{
|
||||||
editorInfo.Selected.Value.Grouping.Value = grouping.NewValue;
|
editorInfo.Selected.Value.Date.Value = grouping.NewValue.StartDate.Value;
|
||||||
|
editorInfo.Selected.TriggerChange();
|
||||||
if (editorInfo.Selected.Value.Date.Value < grouping.NewValue.StartDate.Value)
|
|
||||||
{
|
|
||||||
editorInfo.Selected.Value.Date.Value = grouping.NewValue.StartDate.Value;
|
|
||||||
editorInfo.Selected.TriggerChange();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
losersCheckbox.Current.ValueChanged += losers =>
|
|
||||||
{
|
|
||||||
if (editorInfo.Selected.Value != null)
|
|
||||||
editorInfo.Selected.Value.Losers.Value = losers.NewValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
dateTimeBox.Bindable.ValueChanged += date =>
|
|
||||||
{
|
|
||||||
if (editorInfo.Selected.Value != null)
|
|
||||||
editorInfo.Selected.Value.Date.Value = date.NewValue;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -183,5 +112,37 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SettingsTeamDropdown : SettingsDropdown<TournamentTeam>
|
||||||
|
{
|
||||||
|
public SettingsTeamDropdown(BindableList<TournamentTeam> teams)
|
||||||
|
{
|
||||||
|
foreach (var g in teams.Prepend(new TournamentTeam()))
|
||||||
|
add(g);
|
||||||
|
|
||||||
|
teams.ItemsRemoved += items => items.ForEach(i => Control.RemoveDropdownItem(i));
|
||||||
|
teams.ItemsAdded += items => items.ForEach(add);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user