From eabcef3e12723631810c0b6c12b42d261fc5f200 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 11 Nov 2018 10:13:17 +0900 Subject: [PATCH] Add schedule screen --- osu.Game.Tournament.Tests/TestCaseSchedule.cs | 25 +++ .../Ladder/Components/DrawableMatchPairing.cs | 6 +- .../Ladder/Components/DrawableMatchTeam.cs | 17 +- .../Screens/Ladder/LadderManager.cs | 13 +- .../Screens/Schedule/ScheduleScreen.cs | 167 ++++++++++++++++++ .../Screens/TournamentSceneManager.cs | 4 + osu.Game.Tournament/TournamentGameBase.cs | 4 + osu.Game/OsuGameBase.cs | 2 +- 8 files changed, 221 insertions(+), 17 deletions(-) create mode 100644 osu.Game.Tournament.Tests/TestCaseSchedule.cs create mode 100644 osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs diff --git a/osu.Game.Tournament.Tests/TestCaseSchedule.cs b/osu.Game.Tournament.Tests/TestCaseSchedule.cs new file mode 100644 index 0000000000..a12586cb27 --- /dev/null +++ b/osu.Game.Tournament.Tests/TestCaseSchedule.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Game.Tests.Visual; +using osu.Game.Tournament.Screens.Schedule; + +namespace osu.Game.Tournament.Tests +{ + public class TestCaseSchedule : OsuTestCase + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(ScheduleScreen) + }; + + [BackgroundDependencyLoader] + private void load() + { + Add(new ScheduleScreen()); + } + } +} diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs index 5d0837c542..def53ce510 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs @@ -18,7 +18,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components public class DrawableMatchPairing : CompositeDrawable { public readonly MatchPairing Pairing; - private readonly FillFlowContainer flow; + protected readonly FillFlowContainer Flow; private readonly Drawable selectionBox; private readonly Drawable currentMatchSelectionBox; private Bindable globalSelection; @@ -62,7 +62,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components Colour = Color4.OrangeRed, Child = new Box { RelativeSizeAxes = Axes.Both } }, - flow = new FillFlowContainer + Flow = new FillFlowContainer { AutoSizeAxes = Axes.Both, Direction = FillDirection.Vertical, @@ -195,7 +195,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components if (Pairing.Team1.Value == null || Pairing.Team2.Value == null) Pairing.CancelMatchStart(); - flow.Children = new[] + Flow.Children = new[] { new DrawableMatchTeam(Pairing.Team1, Pairing, Pairing.Losers), new DrawableMatchTeam(Pairing.Team2, Pairing, Pairing.Losers) diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs index 804680ba28..7ff15ef434 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs @@ -36,6 +36,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components private readonly Func isWinner; private LadderManager manager; + [Resolved] + private LadderInfo ladderInfo { get; set; } + + private void setCurrent() + { + //todo: tournamentgamebase? + if (ladderInfo.CurrentMatch.Value != null) + ladderInfo.CurrentMatch.Value.Current.Value = false; + + ladderInfo.CurrentMatch.Value = pairing; + ladderInfo.CurrentMatch.Value.Current.Value = true; + } + [Resolved(CanBeNull = true)] private LadderEditorInfo editorInfo { get; set; } @@ -132,7 +145,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components if (!pairing.Current.Value) { - manager.SetCurrent(pairing); + setCurrent(); return true; } @@ -182,7 +195,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components return new MenuItem[] { - new OsuMenuItem("Set as current", MenuItemType.Standard, () => manager.SetCurrent(pairing)), + new OsuMenuItem("Set as current", MenuItemType.Standard, setCurrent), 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/LadderManager.cs b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs index 4c9700462f..2b1a1bad85 100644 --- a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs +++ b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs @@ -31,8 +31,8 @@ namespace osu.Game.Tournament.Screens.Ladder private ScrollableContainer scrollContent; - [Cached] - private LadderEditorInfo editorInfo = new LadderEditorInfo(); + [Resolved] + private LadderEditorInfo editorInfo { get; set;} [Resolved] private LadderInfo ladderInfo { get; set; } @@ -185,15 +185,6 @@ namespace osu.Game.Tournament.Screens.Ladder public void Remove(MatchPairing pairing) => pairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove(); - public void SetCurrent(MatchPairing pairing) - { - if (ladderInfo.CurrentMatch.Value != null) - ladderInfo.CurrentMatch.Value.Current.Value = false; - - ladderInfo.CurrentMatch.Value = pairing; - ladderInfo.CurrentMatch.Value.Current.Value = true; - } - private class JoinRequestHandler : CompositeDrawable { private readonly Container pairingsContainer; diff --git a/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs b/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs new file mode 100644 index 0000000000..a0c36cd6c0 --- /dev/null +++ b/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs @@ -0,0 +1,167 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Video; +using osu.Framework.Platform; +using osu.Game.Graphics.Sprites; +using osu.Game.Tournament.Screens.Ladder.Components; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Tournament.Screens.Schedule +{ + public class ScheduleScreen : TournamentScreen, IProvideVideo + { + private readonly Bindable currentMatch = new Bindable(); + private Container mainContainer; + private LadderInfo ladder; + + [BackgroundDependencyLoader] + private void load(LadderInfo ladder, Storage storage) + { + this.ladder = ladder; + + RelativeSizeAxes = Axes.Both; + + InternalChildren = new Drawable[] + { + new VideoSprite(storage.GetStream(@"BG Side Logo - OWC.m4v")) + { + RelativeSizeAxes = Axes.Both, + Loop = true, + }, + mainContainer = new Container + { + RelativeSizeAxes = Axes.Both, + } + }; + + currentMatch.BindValueChanged(matchChanged); + currentMatch.BindTo(ladder.CurrentMatch); + } + + private void matchChanged(MatchPairing pairing) + { + if (pairing == null) + { + mainContainer.Clear(); + return; + } + + mainContainer.Child = new FillFlowContainer + { + RelativeSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + new Container + { + RelativeSizeAxes = Axes.Both, + Height = 0.65f, + Child = new FillFlowContainer + { + RelativeSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Children = new Drawable[] + { + new ScheduleContainer("recent matches") + { + RelativeSizeAxes = Axes.Both, + Width = 0.4f, + ChildrenEnumerable = ladder.Pairings + .Where(p => p.Completed.Value) + .OrderByDescending(p => p.Date.Value) + .Take(8) + .Select(p => new SchedulePairing(p)) + }, + new ScheduleContainer("match overview") + { + RelativeSizeAxes = Axes.Both, + Width = 0.6f, + ChildrenEnumerable = ladder.Pairings + .Where(p => !p.Completed.Value) + .OrderBy(p => p.Date.Value) + .Take(8) + .Select(p => new SchedulePairing(p)) + }, + } + } + }, + new ScheduleContainer("current match") + { + RelativeSizeAxes = Axes.Both, + Height = 0.25f, + Children = new Drawable[] + { + new OsuSpriteText + { + Margin = new MarginPadding { Left = -10, Bottom = 10, Top = -5 }, + Spacing = new Vector2(10, 0), + Text = currentMatch.Value.Grouping.Value.Name.Value, + Colour = Color4.Black, + TextSize = 20 + }, + new SchedulePairing(currentMatch), + new OsuSpriteText + { + Text = "Start Time " + pairing.Date.Value.ToUniversalTime().ToString("HH:mm UTC"), + Colour = Color4.Black, + TextSize = 20 + }, + } + } + } + }; + } + + public class SchedulePairing : DrawableMatchPairing + { + public SchedulePairing(MatchPairing pairing) + : base(pairing) + { + Flow.Direction = FillDirection.Horizontal; + } + } + + public class ScheduleContainer : Container + { + protected override Container Content => content; + + private readonly FillFlowContainer content; + + public ScheduleContainer(string title) + { + Padding = new MarginPadding { Left = 30, Top = 30 }; + InternalChildren = new Drawable[] + { + new OsuSpriteText + { + X = 30, + Text = title, + Colour = Color4.Black, + Spacing = new Vector2(10, 0), + TextSize = 30 + }, + content = new FillFlowContainer + { + Direction = FillDirection.Vertical, + RelativeSizeAxes = Axes.Both, + Margin = new MarginPadding(40) + }, + new Circle + { + Colour = new Color4(233, 187, 79, 255), + Width = 5, + RelativeSizeAxes = Axes.Y, + } + }; + } + } + } +} diff --git a/osu.Game.Tournament/Screens/TournamentSceneManager.cs b/osu.Game.Tournament/Screens/TournamentSceneManager.cs index 20af4c29be..c349e48fa2 100644 --- a/osu.Game.Tournament/Screens/TournamentSceneManager.cs +++ b/osu.Game.Tournament/Screens/TournamentSceneManager.cs @@ -13,6 +13,7 @@ using osu.Game.Tournament.Screens.Drawings; using osu.Game.Tournament.Screens.Gameplay; using osu.Game.Tournament.Screens.Ladder; using osu.Game.Tournament.Screens.MapPool; +using osu.Game.Tournament.Screens.Schedule; using osu.Game.Tournament.Screens.Showcase; using osu.Game.Tournament.Screens.TeamIntro; using OpenTK; @@ -22,6 +23,7 @@ namespace osu.Game.Tournament.Screens { public class TournamentSceneManager : OsuScreen { + private ScheduleScreen schedule; private LadderManager bracket; private MapPoolScreen mapPool; private GameplayScreen gameplay; @@ -56,6 +58,7 @@ namespace osu.Game.Tournament.Screens new OsuButton { RelativeSizeAxes = Axes.X, Text = "Drawings", Action = () => setScreen(drawings) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "Showcase", Action = () => setScreen(showcase) }, new Container { RelativeSizeAxes = Axes.X, Height = 50 }, + new OsuButton { RelativeSizeAxes = Axes.X, Text = "Schedule", Action = () => setScreen(schedule) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "Bracket", Action = () => setScreen(bracket) }, new Container { RelativeSizeAxes = Axes.X, Height = 50 }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "TeamIntro", Action = () => setScreen(teamIntro) }, @@ -88,6 +91,7 @@ namespace osu.Game.Tournament.Screens RelativeSizeAxes = Axes.Both, Children = new Drawable[] { + schedule = new ScheduleScreen(), bracket = new LadderManager(), showcase = new ShowcaseScreen(), mapPool = new MapPoolScreen(), diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs index 70868d398e..938d79929d 100644 --- a/osu.Game.Tournament/TournamentGameBase.cs +++ b/osu.Game.Tournament/TournamentGameBase.cs @@ -19,6 +19,7 @@ using osu.Game.Online.API.Requests; using osu.Game.Rulesets; using osu.Game.Tournament.Components; using osu.Game.Tournament.IPC; +using osu.Game.Tournament.Screens.Ladder.Components; namespace osu.Game.Tournament { @@ -34,6 +35,9 @@ namespace osu.Game.Tournament [Cached] private readonly Bindable ruleset = new Bindable(); + [Cached] + private LadderEditorInfo editorInfo = new LadderEditorInfo(); + private Bindable windowSize; private FileBasedIPC ipc; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index c7f787cff1..971bc10ecd 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -297,7 +297,7 @@ namespace osu.Game } public override bool EnableDrag => true; // allow right-mouse dragging for absolute scroll in scroll containers. - public override bool EnableClick => false; + public override bool EnableClick => true; public override bool ChangeFocusOnClick => false; } }