diff --git a/osu.Game.Tournament.Tests/TestCaseLadderManager.cs b/osu.Game.Tournament.Tests/TestCaseLadderManager.cs index 9544a5c17e..b53660c703 100644 --- a/osu.Game.Tournament.Tests/TestCaseLadderManager.cs +++ b/osu.Game.Tournament.Tests/TestCaseLadderManager.cs @@ -6,6 +6,8 @@ using System.IO; using Newtonsoft.Json; using osu.Framework.Allocation; using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Game.Graphics.Cursor; using osu.Game.Tests.Visual; using osu.Game.Tournament.Components; using osu.Game.Tournament.Screens.Ladder; @@ -26,7 +28,11 @@ namespace osu.Game.Tournament.Tests var teams = JsonConvert.DeserializeObject>(File.ReadAllText(@"teams.json")); var ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject(File.ReadAllText(@"bracket.json")) : new LadderInfo(); - Child = manager = new LadderManager(ladder, teams); + Child = new OsuContextMenuContainer + { + RelativeSizeAxes = Axes.Both, + Child = manager = new LadderManager(ladder, teams) + }; } protected override void Dispose(bool isDisposing) diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs index 8f33cdcbbc..131959892c 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs @@ -119,5 +119,14 @@ namespace osu.Game.Tournament.Screens.Ladder.Components Pairing.Position = new Point((int)pos.X, (int)pos.Y); return true; } + + public void Remove() + { + if (Pairing.ProgressionSource.Value != null) + Pairing.ProgressionSource.Value.Progression.Value = null; + + Pairing.Progression.Value = null; + Expire(); + } } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs index fcfc87e5c3..e74545f073 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs @@ -15,6 +15,7 @@ using osu.Framework.Input.EventArgs; using osu.Framework.Input.States; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using osu.Game.Tournament.Components; using OpenTK; using OpenTK.Graphics; @@ -157,10 +158,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular"; } - public MenuItem[] ContextMenuItems => new[] + public MenuItem[] ContextMenuItems => new MenuItem[] { - new MenuItem("Populate team", () => team.Value = manager.Teams.Random()), - new MenuItem("Join with", () => manager.JoinRequest(pairing)), + new OsuMenuItem("Populate team", MenuItemType.Standard, () => team.Value = manager.Teams.Random()), + new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing)), + new OsuMenuItem("Remove", MenuItemType.Destructive, () => manager.Remove(pairing)), }; } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs index 47a94b854e..c0ca25e220 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs @@ -28,11 +28,26 @@ namespace osu.Game.Tournament.Screens.Ladder.Components [JsonIgnore] public readonly Bindable Progression = new Bindable(); + [JsonIgnore] + public readonly Bindable ProgressionSource = new Bindable(); + [JsonProperty] public Point Position; + private MatchPairing lastProgression; // todo: fix if we ever get LastValue inside Bindable<>. + public MatchPairing() { + Progression.ValueChanged += progression => + { + if (lastProgression != null) + lastProgression.ProgressionSource.Value = null; + + if (progression != null) + progression.ProgressionSource.Value = this; + + lastProgression = progression; + }; } public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) diff --git a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs index bf66447224..807b5f05a9 100644 --- a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs +++ b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs @@ -2,16 +2,18 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Lines; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.States; -using osu.Game.Graphics.Cursor; +using osu.Game.Graphics.UserInterface; using osu.Game.Tournament.Components; using osu.Game.Tournament.Screens.Ladder.Components; using SixLabors.Primitives; namespace osu.Game.Tournament.Screens.Ladder { - public class LadderManager : CompositeDrawable + public class LadderManager : CompositeDrawable, IHasContextMenu { public readonly List Teams; private readonly Container pairingsContainer; @@ -23,7 +25,7 @@ namespace osu.Game.Tournament.Screens.Ladder RelativeSizeAxes = Axes.Both; - InternalChild = new OsuContextMenuContainer + InternalChild = new Container { RelativeSizeAxes = Axes.Both, Children = new Drawable[] @@ -56,15 +58,14 @@ namespace osu.Game.Tournament.Screens.Ladder private void addPairing(MatchPairing pairing) => pairingsContainer.Add(new DrawableMatchPairing(pairing)); - protected override bool OnClick(InputState state) + public MenuItem[] ContextMenuItems => new MenuItem[] { - addPairing(new MatchPairing + new OsuMenuItem("Create new match", MenuItemType.Highlighted, () => { - Position = new Point((int)state.Mouse.Position.X, (int)state.Mouse.Position.Y) - }); - - return true; - } + var pos = ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position); + addPairing(new MatchPairing { Position = new Point((int)pos.X, (int)pos.Y) }); + }), + }; protected override void Update() { @@ -82,7 +83,7 @@ namespace osu.Game.Tournament.Screens.Ladder } } - public void JoinRequest(MatchPairing pairing) => AddInternal(new JoinRequestHandler(pairingsContainer, pairing)); + public void RequestJoin(MatchPairing pairing) => AddInternal(new JoinRequestHandler(pairingsContainer, pairing)); private class JoinRequestHandler : CompositeDrawable { @@ -126,7 +127,8 @@ namespace osu.Game.Tournament.Screens.Ladder if (found != null) { - Source.Progression.Value = found.Pairing; + if (found.Pairing != Source) + Source.Progression.Value = found.Pairing; Expire(); return true; } @@ -134,5 +136,7 @@ namespace osu.Game.Tournament.Screens.Ladder return false; } } + + public void Remove(MatchPairing pairing) => pairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove(); } }