From 61ca79a8b2294eba4cd83be2a7b725912ae00dc6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 1 Dec 2018 15:32:11 +0900 Subject: [PATCH] Add conditional match support --- .../Components/ConditionalMatchPairing.cs | 12 +++++++++ .../Ladder/Components/DrawableMatchPairing.cs | 14 ++++++++++- .../Screens/Ladder/Components/MatchPairing.cs | 16 +++++++++++- .../Screens/Schedule/ScheduleScreen.cs | 25 +++++++++++++------ osu.Game.Tournament/TournamentGameBase.cs | 7 ++++++ 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 osu.Game.Tournament/Screens/Ladder/Components/ConditionalMatchPairing.cs diff --git a/osu.Game.Tournament/Screens/Ladder/Components/ConditionalMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/ConditionalMatchPairing.cs new file mode 100644 index 0000000000..bff661bcf4 --- /dev/null +++ b/osu.Game.Tournament/Screens/Ladder/Components/ConditionalMatchPairing.cs @@ -0,0 +1,12 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Tournament.Screens.Ladder.Components +{ + /// + /// A pairing that may not necessarily occur. + /// + public class ConditionalMatchPairing : MatchPairing + { + } +} diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs index e727e740f9..db942c6e4c 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs @@ -199,6 +199,18 @@ namespace osu.Game.Tournament.Screens.Ladder.Components if (Pairing.Team1.Value == null || Pairing.Team2.Value == null) Pairing.CancelMatchStart(); + if (Pairing.ConditionalPairings.Count > 0) + { + foreach (var conditional in Pairing.ConditionalPairings) + { + var team1Match = conditional.Acronyms.Contains(Pairing.Team1Acronym); + var team2Match = conditional.Acronyms.Contains(Pairing.Team2Acronym); + + if (team1Match && team2Match) + Pairing.Date.Value = conditional.Date; + } + } + Flow.Children = new[] { new DrawableMatchTeam(Pairing.Team1, Pairing, Pairing.Losers), @@ -226,7 +238,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components protected override bool OnClick(ClickEvent e) { - if (editorInfo == null) + if (editorInfo == null || Pairing is ConditionalMatchPairing) return false; Selected = true; diff --git a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs index 003f41cfa9..8461cf4ae1 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using Newtonsoft.Json; using osu.Framework.Configuration; @@ -17,6 +18,17 @@ namespace osu.Game.Tournament.Screens.Ladder.Components { public int ID; + public List Acronyms + { + get + { + List acronyms = new List(); + if (Team1Acronym != null) acronyms.Add(Team1Acronym); + if (Team2Acronym != null) acronyms.Add(Team2Acronym); + return acronyms; + } + } + [JsonIgnore] public readonly Bindable Team1 = new Bindable(); @@ -53,6 +65,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components public readonly Bindable Date = new Bindable(); + public readonly BindableCollection ConditionalPairings = new BindableCollection(); + public readonly Bindable Position = new Bindable(); public MatchPairing() @@ -74,7 +88,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components [JsonIgnore] public TournamentTeam Loser => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team2.Value : Team1.Value; - public int PointsToWin => Grouping.Value.BestOf / 2 + 1; + public int PointsToWin => Grouping.Value == null ? 0 : Grouping.Value.BestOf / 2 + 1; /// /// Remove scores from the match, in case of a false click or false start. diff --git a/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs b/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs index 37577ec3b0..f3f3667db1 100644 --- a/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs +++ b/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs @@ -56,6 +56,13 @@ namespace osu.Game.Tournament.Screens.Schedule return; } + var upcoming = ladder.Pairings.Where(p => !p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4); + var conditionals = ladder.Pairings.Where(p => !p.Completed.Value && (p.Team1.Value == null || p.Team2.Value == null) && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) + .SelectMany(m => m.ConditionalPairings.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a)))); + + upcoming = upcoming.Concat(conditionals); + upcoming = upcoming.OrderBy(p => p.Date.Value).Take(12); + mainContainer.Child = new FillFlowContainer { RelativeSizeAxes = Axes.Both, @@ -77,7 +84,8 @@ namespace osu.Game.Tournament.Screens.Schedule RelativeSizeAxes = Axes.Both, Width = 0.4f, ChildrenEnumerable = ladder.Pairings - .Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) + .Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null + && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) .OrderByDescending(p => p.Date.Value) .Take(8) .Select(p => new SchedulePairing(p)) @@ -86,11 +94,7 @@ namespace osu.Game.Tournament.Screens.Schedule { RelativeSizeAxes = Axes.Both, Width = 0.6f, - ChildrenEnumerable = ladder.Pairings - .Where(p => !p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) - .OrderBy(p => p.Date.Value) - .Take(8) - .Select(p => new SchedulePairing(p)) + ChildrenEnumerable = upcoming.Select(p => new SchedulePairing(p)) }, } } @@ -129,6 +133,11 @@ namespace osu.Game.Tournament.Screens.Schedule { Flow.Direction = FillDirection.Horizontal; + bool conditional = pairing is ConditionalMatchPairing; + + if (conditional) + Colour = OsuColour.Gray(0.5f); + if (showTimestamp) { AddInternal(new DrawableDate(Pairing.Date.Value) @@ -136,6 +145,7 @@ namespace osu.Game.Tournament.Screens.Schedule Anchor = Anchor.TopRight, Origin = Anchor.TopLeft, Colour = Color4.Black, + Alpha = conditional ? 0.6f : 1, Margin = new MarginPadding { Horizontal = 10, Vertical = 5 }, }); AddInternal(new OsuSpriteText @@ -143,8 +153,9 @@ namespace osu.Game.Tournament.Screens.Schedule Anchor = Anchor.BottomRight, Origin = Anchor.BottomLeft, Colour = Color4.Black, + Alpha = conditional ? 0.6f : 1, Margin = new MarginPadding { Horizontal = 10, Vertical = 5 }, - Text = pairing.Date.Value.ToUniversalTime().ToString("HH:mm UTC") + Text = pairing.Date.Value.ToUniversalTime().ToString("HH:mm UTC") + (conditional ? " (conditional)" : "") }); } } diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs index e37b7cf8d6..4938533a9e 100644 --- a/osu.Game.Tournament/TournamentGameBase.cs +++ b/osu.Game.Tournament/TournamentGameBase.cs @@ -78,6 +78,13 @@ namespace osu.Game.Tournament { pairing.Team1.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == pairing.Team1Acronym); pairing.Team2.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == pairing.Team2Acronym); + + foreach (var conditional in pairing.ConditionalPairings) + { + conditional.Team1.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == conditional.Team1Acronym); + conditional.Team2.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == conditional.Team2Acronym); + conditional.Grouping.Value = pairing.Grouping.Value; + } } // assign progressions