From a0d64c1b13f779488dbfb4a7d952b0e07bbfbfa8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 7 Nov 2018 01:20:32 +0900 Subject: [PATCH] Add ability to select current match --- osu.Game.Tournament.Tests/LadderTestCase.cs | 1 - .../Ladder/Components => }/LadderInfo.cs | 8 ++++- .../Ladder/Components/DrawableMatchPairing.cs | 25 ++++++++++++++- .../Ladder/Components/DrawableMatchTeam.cs | 9 +++++- .../Screens/Ladder/Components/MatchPairing.cs | 5 +++ .../Screens/Ladder/LadderManager.cs | 13 ++++++++ .../Screens/TeamIntro/TeamIntroScreen.cs | 32 ++++++++++++------- .../Screens/TournamentSceneManager.cs | 1 - osu.Game.Tournament/TournamentGame.cs | 9 +++++- osu.Game.Tournament/TournamentGameBase.cs | 9 ++---- 10 files changed, 88 insertions(+), 24 deletions(-) rename osu.Game.Tournament/{Screens/Ladder/Components => }/LadderInfo.cs (70%) diff --git a/osu.Game.Tournament.Tests/LadderTestCase.cs b/osu.Game.Tournament.Tests/LadderTestCase.cs index b296956d42..acc96930ee 100644 --- a/osu.Game.Tournament.Tests/LadderTestCase.cs +++ b/osu.Game.Tournament.Tests/LadderTestCase.cs @@ -3,7 +3,6 @@ using osu.Framework.Allocation; using osu.Game.Tests.Visual; -using osu.Game.Tournament.Screens.Ladder.Components; namespace osu.Game.Tournament.Tests { diff --git a/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs b/osu.Game.Tournament/LadderInfo.cs similarity index 70% rename from osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs rename to osu.Game.Tournament/LadderInfo.cs index 567cdb0daa..c433987491 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs +++ b/osu.Game.Tournament/LadderInfo.cs @@ -2,9 +2,12 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using Newtonsoft.Json; +using osu.Framework.Configuration; using osu.Game.Tournament.Components; +using osu.Game.Tournament.Screens.Ladder.Components; -namespace osu.Game.Tournament.Screens.Ladder.Components +namespace osu.Game.Tournament { public class LadderInfo { @@ -12,5 +15,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components public List Progressions = new List(); public List Groupings = new List(); public List Teams = new List(); + + [JsonIgnore] + public Bindable CurrentMatch = new Bindable(); } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs index 81b3223ea7..5d0837c542 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs @@ -20,6 +20,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components public readonly MatchPairing Pairing; private readonly FillFlowContainer flow; private readonly Drawable selectionBox; + private readonly Drawable currentMatchSelectionBox; private Bindable globalSelection; [Resolved(CanBeNull = true)] @@ -49,6 +50,18 @@ namespace osu.Game.Tournament.Screens.Ladder.Components Colour = Color4.YellowGreen, Child = new Box { RelativeSizeAxes = Axes.Both } }, + currentMatchSelectionBox = new Container + { + CornerRadius = 5, + Masking = true, + Scale = new Vector2(1.05f), + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Alpha = 0, + Colour = Color4.OrangeRed, + Child = new Box { RelativeSizeAxes = Axes.Both } + }, flow = new FillFlowContainer { AutoSizeAxes = Axes.Both, @@ -65,10 +78,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components pairing.Progression.BindValueChanged(_ => updateProgression()); pairing.LosersProgression.BindValueChanged(_ => updateProgression()); pairing.Losers.BindValueChanged(_ => updateTeams()); + pairing.Current.BindValueChanged(_ => updateCurrentMatch(), true); updateTeams(); } + private void updateCurrentMatch() + { + if (Pairing.Current.Value) + currentMatchSelectionBox.Show(); + else + currentMatchSelectionBox.Hide(); + } + private bool selected; public bool Selected @@ -144,7 +166,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components var instaWinAmount = Pairing.Grouping.Value.BestOf / 2; - Pairing.Completed.Value = Pairing.Grouping.Value.BestOf > 0 && (Pairing.Team1Score + Pairing.Team2Score >= Pairing.Grouping.Value.BestOf || Pairing.Team1Score > instaWinAmount || Pairing.Team2Score > instaWinAmount); + Pairing.Completed.Value = Pairing.Grouping.Value.BestOf > 0 + && (Pairing.Team1Score + Pairing.Team2Score >= Pairing.Grouping.Value.BestOf || Pairing.Team1Score > instaWinAmount || Pairing.Team2Score > instaWinAmount); } protected override void LoadComplete() diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs index 70ddb6b664..804680ba28 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs @@ -126,10 +126,16 @@ namespace osu.Game.Tournament.Screens.Ladder.Components } //TODO: use OnClick instead once we have per-button clicks. - protected override bool OnMouseUp(MouseUpEvent e) + protected override bool OnClick(ClickEvent e) { if (Team == null || editorInfo.EditingEnabled) return false; + if (!pairing.Current.Value) + { + manager.SetCurrent(pairing); + return true; + } + if (e.Button == MouseButton.Left) { if (score.Value == null) @@ -176,6 +182,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components return new MenuItem[] { + new OsuMenuItem("Set as current", MenuItemType.Standard, () => manager.SetCurrent(pairing)), new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing, false)), new OsuMenuItem("Join with (loser)", MenuItemType.Standard, () => manager.RequestJoin(pairing, true)), 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 5dc2009c4d..aa0c3229c9 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs @@ -43,6 +43,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components [JsonIgnore] public readonly Bindable LosersProgression = new Bindable(); + /// + /// Should not be set directly. Use LadderInfo.CurrentMatch.Value = this instead. + /// + public readonly Bindable Current = new Bindable(); + public readonly Bindable Date = new Bindable(); public Point Position; diff --git a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs index 2ad296dd77..f348eff571 100644 --- a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs +++ b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs @@ -23,6 +23,7 @@ using SixLabors.Primitives; namespace osu.Game.Tournament.Screens.Ladder { + [Cached] public class LadderManager : CompositeDrawable, IHasContextMenu { public readonly List Teams; @@ -30,6 +31,8 @@ namespace osu.Game.Tournament.Screens.Ladder private readonly Container paths; private readonly Container headings; + private readonly LadderInfo info; + private readonly ScrollableContainer scrollContent; [Cached] @@ -37,6 +40,7 @@ namespace osu.Game.Tournament.Screens.Ladder public LadderManager(LadderInfo info) { + this.info = info; editorInfo.Teams = Teams = info.Teams; editorInfo.Groupings = info.Groupings; @@ -255,5 +259,14 @@ namespace osu.Game.Tournament.Screens.Ladder } public void Remove(MatchPairing pairing) => pairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove(); + + public void SetCurrent(MatchPairing pairing) + { + if (info.CurrentMatch.Value != null) + info.CurrentMatch.Value.Current.Value = false; + + info.CurrentMatch.Value = pairing; + info.CurrentMatch.Value.Current.Value = true; + } } } diff --git a/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs b/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs index 522af5f6c9..d515312dd0 100644 --- a/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs +++ b/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs @@ -3,7 +3,6 @@ using System; using osu.Framework.Allocation; -using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Video; @@ -20,33 +19,42 @@ namespace osu.Game.Tournament.Screens.TeamIntro { public class TeamIntroScreen : OsuScreen { - private VideoSprite background; + private Container mainContainer; [Resolved] - private Bindable currentMatch { get; set; } + private LadderInfo ladderInfo { get; set; } [BackgroundDependencyLoader] private void load(Storage storage) { RelativeSizeAxes = Axes.Both; - background = new VideoSprite(storage.GetStream(@"BG Team - Both OWC.m4v")) + InternalChildren = new Drawable[] { - RelativeSizeAxes = Axes.Both, - Loop = true, + new VideoSprite(storage.GetStream(@"BG Team - Both OWC.m4v")) + { + RelativeSizeAxes = Axes.Both, + Loop = true, + }, + mainContainer = new Container + { + RelativeSizeAxes = Axes.Both, + } }; - currentMatch.BindValueChanged(matchChanged, true); + ladderInfo.CurrentMatch.BindValueChanged(matchChanged, true); } private void matchChanged(MatchPairing pairing) { if (pairing == null) - return; - - InternalChildren = new Drawable[] { - background, + mainContainer.Clear(); + return; + } + + mainContainer.Children = new Drawable[] + { new TeamWithPlayers(pairing.Team1, true) { RelativeSizeAxes = Axes.Both, @@ -148,6 +156,8 @@ namespace osu.Game.Tournament.Screens.TeamIntro AutoSizeAxes = Axes.Both, Spacing = new Vector2(0, 5), Padding = new MarginPadding(20), + + Anchor = !left ? Anchor.CentreRight : Anchor.CentreLeft, Origin = !left ? Anchor.CentreRight : Anchor.CentreLeft, RelativePositionAxes = Axes.Both, diff --git a/osu.Game.Tournament/Screens/TournamentSceneManager.cs b/osu.Game.Tournament/Screens/TournamentSceneManager.cs index 303e15aa8d..91d389b63d 100644 --- a/osu.Game.Tournament/Screens/TournamentSceneManager.cs +++ b/osu.Game.Tournament/Screens/TournamentSceneManager.cs @@ -13,7 +13,6 @@ using osu.Game.Screens; using osu.Game.Tournament.Screens.Drawings; using osu.Game.Tournament.Screens.Gameplay; using osu.Game.Tournament.Screens.Ladder; -using osu.Game.Tournament.Screens.Ladder.Components; using osu.Game.Tournament.Screens.MapPool; using osu.Game.Tournament.Screens.Showcase; using osu.Game.Tournament.Screens.TeamIntro; diff --git a/osu.Game.Tournament/TournamentGame.cs b/osu.Game.Tournament/TournamentGame.cs index b4bdf250b6..f970700fc5 100644 --- a/osu.Game.Tournament/TournamentGame.cs +++ b/osu.Game.Tournament/TournamentGame.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Graphics; +using osu.Game.Graphics.Cursor; using osu.Game.Tournament.Screens; namespace osu.Game.Tournament @@ -10,7 +12,12 @@ namespace osu.Game.Tournament protected override void LoadComplete() { base.LoadComplete(); - Add(new TournamentSceneManager()); + + Add(new OsuContextMenuContainer + { + RelativeSizeAxes = Axes.Both, + Child = new TournamentSceneManager() + }); MenuCursorContainer.Cursor.Alpha = 0; } diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs index 6eb1feaf6d..2ae6c60067 100644 --- a/osu.Game.Tournament/TournamentGameBase.cs +++ b/osu.Game.Tournament/TournamentGameBase.cs @@ -15,7 +15,6 @@ using osu.Game.Beatmaps; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API.Requests; using osu.Game.Rulesets; -using osu.Game.Tournament.Screens.Ladder.Components; namespace osu.Game.Tournament { @@ -31,9 +30,6 @@ namespace osu.Game.Tournament [Cached] private readonly Bindable ruleset = new Bindable(); - [Cached] - private readonly Bindable currentMatch = new Bindable(); - private Bindable windowSize; protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) @@ -95,6 +91,8 @@ namespace osu.Game.Tournament foreach (var id in group.Pairings) Ladder.Pairings.Single(p => p.ID == id).Grouping.Value = group; + Ladder.CurrentMatch.Value = Ladder.Pairings.FirstOrDefault(p => p.Current.Value); + foreach (var g in Ladder.Groupings) foreach (var b in g.Beatmaps) if (b.BeatmapInfo == null) @@ -106,9 +104,6 @@ namespace osu.Game.Tournament addedInfo = true; } - //todo: temp - currentMatch.Value = Ladder.Pairings.FirstOrDefault(); - if (addedInfo) SaveChanges();