2019-03-04 12:24:19 +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.
|
2018-09-22 04:52:25 +08:00
|
|
|
|
2019-06-14 18:16:20 +08:00
|
|
|
using System.Collections.Generic;
|
2020-02-17 14:06:14 +08:00
|
|
|
using System.Collections.Specialized;
|
2022-12-16 19:18:02 +08:00
|
|
|
using System.Diagnostics;
|
2018-09-22 04:52:25 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 12:40:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-06-14 19:30:09 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2018-09-22 04:52:25 +08:00
|
|
|
using osu.Framework.Graphics;
|
2023-07-20 18:28:23 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-16 19:30:12 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-09-24 22:30:37 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
2018-09-22 04:52:25 +08:00
|
|
|
using osu.Game.Screens.Play.PlayerSettings;
|
2018-11-17 13:05:22 +08:00
|
|
|
using osu.Game.Tournament.Components;
|
2019-06-18 13:51:48 +08:00
|
|
|
using osu.Game.Tournament.Models;
|
2023-07-20 18:28:23 +08:00
|
|
|
using osuTK;
|
2018-09-22 04:52:25 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder.Components
|
|
|
|
{
|
2023-07-20 18:28:23 +08:00
|
|
|
public partial class LadderEditorSettings : CompositeDrawable
|
2018-09-22 04:52:25 +08:00
|
|
|
{
|
2023-07-25 19:50:55 +08:00
|
|
|
private SettingsDropdown<TournamentRound?> roundDropdown = null!;
|
|
|
|
private PlayerCheckbox losersCheckbox = null!;
|
|
|
|
private DateTextBox dateTimeBox = null!;
|
|
|
|
private SettingsTeamDropdown team1Dropdown = null!;
|
|
|
|
private SettingsTeamDropdown team2Dropdown = null!;
|
2018-09-22 04:52:25 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2023-07-25 19:50:55 +08:00
|
|
|
private LadderEditorInfo editorInfo { get; set; } = null!;
|
2018-09-22 04:52:25 +08:00
|
|
|
|
2018-11-09 16:39:46 +08:00
|
|
|
[Resolved]
|
2023-07-25 19:50:55 +08:00
|
|
|
private LadderInfo ladderInfo { get; set; } = null!;
|
2018-11-09 16:39:46 +08:00
|
|
|
|
2018-09-22 04:52:25 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2023-07-20 18:28:23 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
2018-09-22 04:52:25 +08:00
|
|
|
{
|
2023-07-20 18:28:23 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
team1Dropdown = new SettingsTeamDropdown(ladderInfo.Teams) { LabelText = "Team 1" },
|
|
|
|
team2Dropdown = new SettingsTeamDropdown(ladderInfo.Teams) { LabelText = "Team 2" },
|
|
|
|
roundDropdown = new SettingsRoundDropdown(ladderInfo.Rounds) { LabelText = "Round" },
|
|
|
|
losersCheckbox = new PlayerCheckbox { LabelText = "Losers Bracket" },
|
|
|
|
dateTimeBox = new DateTextBox { LabelText = "Match Time" },
|
|
|
|
},
|
2018-09-22 04:52:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
editorInfo.Selected.ValueChanged += selection =>
|
|
|
|
{
|
2022-07-13 17:32:47 +08:00
|
|
|
// ensure any ongoing edits are committed out to the *current* selection before changing to a new one.
|
|
|
|
GetContainingInputManager().TriggerFocusContention(null);
|
|
|
|
|
2023-07-24 19:44:50 +08:00
|
|
|
// Required to avoid cyclic failure in BindableWithCurrent (TriggerChange called during the Current_Set process).
|
|
|
|
// Arguable a framework issue but since we haven't hit it anywhere else a local workaround seems best.
|
|
|
|
roundDropdown.Current.ValueChanged -= roundDropdownChanged;
|
2018-09-22 04:52:25 +08:00
|
|
|
|
2023-07-24 19:44:50 +08:00
|
|
|
roundDropdown.Current = selection.NewValue.Round;
|
|
|
|
losersCheckbox.Current = selection.NewValue.Losers;
|
|
|
|
dateTimeBox.Current = selection.NewValue.Date;
|
|
|
|
|
|
|
|
team1Dropdown.Current = selection.NewValue.Team1;
|
|
|
|
team2Dropdown.Current = selection.NewValue.Team2;
|
|
|
|
|
|
|
|
roundDropdown.Current.ValueChanged += roundDropdownChanged;
|
2018-09-22 04:52:25 +08:00
|
|
|
};
|
2023-07-24 19:44:50 +08:00
|
|
|
}
|
2018-09-22 04:52:25 +08:00
|
|
|
|
2023-07-25 19:50:55 +08:00
|
|
|
private void roundDropdownChanged(ValueChangedEvent<TournamentRound?> round)
|
2023-07-24 19:44:50 +08:00
|
|
|
{
|
|
|
|
if (editorInfo.Selected.Value?.Date.Value < round.NewValue?.StartDate.Value)
|
2018-09-24 22:30:37 +08:00
|
|
|
{
|
2023-07-24 19:44:50 +08:00
|
|
|
editorInfo.Selected.Value.Date.Value = round.NewValue.StartDate.Value;
|
|
|
|
editorInfo.Selected.TriggerChange();
|
|
|
|
}
|
2018-11-17 11:14:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
this.FadeIn();
|
2018-09-22 04:52:25 +08:00
|
|
|
}
|
2018-11-16 19:30:12 +08:00
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
}
|
2019-06-14 19:30:09 +08:00
|
|
|
|
2023-07-25 19:50:55 +08:00
|
|
|
private partial class SettingsRoundDropdown : SettingsDropdown<TournamentRound?>
|
2019-06-14 19:30:09 +08:00
|
|
|
{
|
2019-06-18 13:44:15 +08:00
|
|
|
public SettingsRoundDropdown(BindableList<TournamentRound> rounds)
|
2019-06-14 19:30:09 +08:00
|
|
|
{
|
2023-07-25 19:50:55 +08:00
|
|
|
Current = new Bindable<TournamentRound?>();
|
2019-06-14 19:30:09 +08:00
|
|
|
|
2019-06-18 13:44:15 +08:00
|
|
|
foreach (var r in rounds.Prepend(new TournamentRound()))
|
|
|
|
add(r);
|
2019-06-14 19:30:09 +08:00
|
|
|
|
2020-02-17 14:06:14 +08:00
|
|
|
rounds.CollectionChanged += (_, args) =>
|
|
|
|
{
|
|
|
|
switch (args.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2022-12-16 19:18:02 +08:00
|
|
|
Debug.Assert(args.NewItems != null);
|
|
|
|
|
2020-02-17 14:06:14 +08:00
|
|
|
args.NewItems.Cast<TournamentRound>().ForEach(add);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2022-12-16 19:18:02 +08:00
|
|
|
Debug.Assert(args.OldItems != null);
|
|
|
|
|
2020-02-17 14:06:14 +08:00
|
|
|
args.OldItems.Cast<TournamentRound>().ForEach(i => Control.RemoveDropdownItem(i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2019-06-14 19:30:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-06-18 13:44:15 +08:00
|
|
|
private void add(TournamentRound round)
|
2019-06-14 19:30:09 +08:00
|
|
|
{
|
2019-06-18 13:44:15 +08:00
|
|
|
Control.AddDropdownItem(round);
|
|
|
|
boundReference(round.Name).BindValueChanged(_ =>
|
2019-06-14 19:30:09 +08:00
|
|
|
{
|
2019-06-18 13:44:15 +08:00
|
|
|
Control.RemoveDropdownItem(round);
|
|
|
|
Control.AddDropdownItem(round);
|
2019-06-14 19:30:09 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-09-22 04:52:25 +08:00
|
|
|
}
|
|
|
|
}
|