diff --git a/osu.Game.Tournament/Screens/Ladder/DrawableTournamentGrouping.cs b/osu.Game.Tournament/Screens/Ladder/DrawableTournamentGrouping.cs new file mode 100644 index 0000000000..28e1183b27 --- /dev/null +++ b/osu.Game.Tournament/Screens/Ladder/DrawableTournamentGrouping.cs @@ -0,0 +1,39 @@ +// 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.Framework.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Tournament.Screens.Ladder.Components; + +namespace osu.Game.Tournament.Screens.Ladder +{ + public class DrawableTournamentGrouping : CompositeDrawable + { + public DrawableTournamentGrouping(TournamentGrouping grouping) + { + AutoSizeAxes = Axes.Both; + InternalChild = new FillFlowContainer + { + Direction = FillDirection.Vertical, + AutoSizeAxes = Axes.Both, + Children = new Drawable[] + { + new OsuSpriteText + { + Text = grouping.Description.ToUpper(), + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre + }, + new OsuSpriteText + { + Text = grouping.Name.ToUpper(), + Font = "Exo2.0-Bold", + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre + }, + } + }; + } + } +} diff --git a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs index 8939e72be2..95b2a0a8d1 100644 --- a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs +++ b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using osu.Framework.Allocation; +using osu.Framework.Caching; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -12,7 +14,6 @@ using osu.Framework.Input.States; using osu.Game.Graphics.UserInterface; using osu.Game.Tournament.Components; using osu.Game.Tournament.Screens.Ladder.Components; -using OpenTK; using SixLabors.Primitives; namespace osu.Game.Tournament.Screens.Ladder @@ -30,6 +31,7 @@ namespace osu.Game.Tournament.Screens.Ladder public readonly List Teams; private readonly Container pairingsContainer; private readonly Container paths; + private readonly Container headings; [Cached] private readonly LadderEditorInfo editorInfo = new LadderEditorInfo(); @@ -52,6 +54,7 @@ namespace osu.Game.Tournament.Screens.Ladder Children = new Drawable[] { paths = new Container { RelativeSizeAxes = Axes.Both }, + headings = new Container() { RelativeSizeAxes = Axes.Both }, pairingsContainer = new Container { RelativeSizeAxes = Axes.Both }, } }, @@ -81,6 +84,9 @@ namespace osu.Game.Tournament.Screens.Ladder foreach (var group in info.Groupings) foreach (var id in group.Pairings) info.Pairings.Single(p => p.ID == id).Grouping.Value = group; + + // todo: fix this + Scheduler.AddDelayed(() => layout.Invalidate(), 100, true); } public LadderInfo CreateInfo() @@ -121,11 +127,20 @@ namespace osu.Game.Tournament.Screens.Ladder } } + private Cached layout = new Cached(); + protected override void Update() { base.Update(); + if (!layout.IsValid) + updateLayout(); + } + + private void updateLayout() + { paths.Clear(); + headings.Clear(); int id = 1; foreach (var pairing in pairingsContainer.OrderBy(d => d.Y).ThenBy(d => d.X)) @@ -143,6 +158,22 @@ namespace osu.Game.Tournament.Screens.Ladder paths.Add(new ProgressionPath(pairing, dest)); } } + + foreach (var group in editorInfo.Groupings) + { + var topPairing = pairingsContainer.Where(p => p.Pairing.Grouping.Value == group).OrderBy(p => p.Y).FirstOrDefault(); + + if (topPairing == null) continue; + + headings.Add(new DrawableTournamentGrouping(group) + { + Position = headings.ToLocalSpace((topPairing.ScreenSpaceDrawQuad.TopLeft + topPairing.ScreenSpaceDrawQuad.TopRight) / 2), + Margin = new MarginPadding { Bottom = 10 }, + Origin = Anchor.BottomCentre, + }); + } + + layout.Validate(); } public void RequestJoin(MatchPairing pairing) => AddInternal(new JoinRequestHandler(pairingsContainer, pairing)); @@ -201,17 +232,4 @@ namespace osu.Game.Tournament.Screens.Ladder public void Remove(MatchPairing pairing) => pairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove(); } - - public class ScrollableContainer : Container - { - protected override bool OnDragStart(InputState state) => true; - - public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true; - - protected override bool OnDrag(InputState state) - { - Position += state.Mouse.Delta; - return base.OnDrag(state); - } - } } diff --git a/osu.Game.Tournament/Screens/Ladder/ScrollableContainer.cs b/osu.Game.Tournament/Screens/Ladder/ScrollableContainer.cs new file mode 100644 index 0000000000..bb4f2e58a9 --- /dev/null +++ b/osu.Game.Tournament/Screens/Ladder/ScrollableContainer.cs @@ -0,0 +1,22 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Containers; +using osu.Framework.Input.States; +using OpenTK; + +namespace osu.Game.Tournament.Screens.Ladder +{ + public class ScrollableContainer : Container + { + protected override bool OnDragStart(InputState state) => true; + + public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true; + + protected override bool OnDrag(InputState state) + { + Position += state.Mouse.Delta; + return base.OnDrag(state); + } + } +}