2019-03-04 04:24:19 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2020-02-17 06:06:14 +00:00
|
|
|
using System.Collections.Specialized;
|
2018-11-16 11:14:34 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Caching;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Lines;
|
2018-11-17 05:59:37 +00:00
|
|
|
using osu.Framework.Platform;
|
2018-11-16 11:14:34 +00:00
|
|
|
using osu.Game.Graphics;
|
2019-06-17 12:07:30 +00:00
|
|
|
using osu.Game.Tournament.Components;
|
2019-06-18 05:51:48 +00:00
|
|
|
using osu.Game.Tournament.Models;
|
|
|
|
using osu.Game.Tournament.Screens.Editors;
|
2018-11-16 11:14:34 +00:00
|
|
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
2018-11-22 01:25:30 +00:00
|
|
|
using osuTK.Graphics;
|
2018-11-16 11:14:34 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder
|
|
|
|
{
|
2018-11-17 05:59:37 +00:00
|
|
|
public class LadderScreen : TournamentScreen, IProvideVideo
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
protected Container<DrawableTournamentMatch> MatchesContainer;
|
2018-11-16 11:14:34 +00:00
|
|
|
private Container<Path> paths;
|
|
|
|
private Container headings;
|
|
|
|
|
2019-06-13 07:11:15 +00:00
|
|
|
protected LadderDragContainer ScrollContent;
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2019-06-13 08:04:57 +00:00
|
|
|
protected Container Content;
|
|
|
|
|
2018-11-16 11:14:34 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2018-11-17 05:59:37 +00:00
|
|
|
private void load(OsuColour colours, Storage storage)
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2020-03-11 01:18:41 +00:00
|
|
|
normalPathColour = Color4Extensions.FromHex("#66D1FF");
|
|
|
|
losersPathColour = Color4Extensions.FromHex("#FFC700");
|
2018-11-16 11:14:34 +00:00
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2019-06-13 08:04:57 +00:00
|
|
|
InternalChild = Content = new Container
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-03-06 09:38:29 +00:00
|
|
|
new TourneyVideo("ladder")
|
2018-11-17 05:59:37 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Loop = true,
|
|
|
|
},
|
2020-03-12 04:29:09 +00:00
|
|
|
new DrawableTournamentHeaderText
|
2020-03-06 16:37:15 +00:00
|
|
|
{
|
|
|
|
Y = 100,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
2019-06-13 07:11:15 +00:00
|
|
|
ScrollContent = new LadderDragContainer
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
paths = new Container<Path> { RelativeSizeAxes = Axes.Both },
|
|
|
|
headings = new Container { RelativeSizeAxes = Axes.Both },
|
2019-06-18 05:57:05 +00:00
|
|
|
MatchesContainer = new Container<DrawableTournamentMatch> { RelativeSizeAxes = Axes.Both },
|
2018-11-16 11:14:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-18 05:57:05 +00:00
|
|
|
void addMatch(TournamentMatch match) =>
|
|
|
|
MatchesContainer.Add(new DrawableTournamentMatch(match, this is LadderEditorScreen)
|
2019-06-14 10:16:20 +00:00
|
|
|
{
|
|
|
|
Changed = () => layout.Invalidate()
|
|
|
|
});
|
|
|
|
|
2019-06-18 05:57:05 +00:00
|
|
|
foreach (var match in LadderInfo.Matches)
|
|
|
|
addMatch(match);
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2020-02-17 06:06:14 +00:00
|
|
|
LadderInfo.Rounds.CollectionChanged += (_, __) => layout.Invalidate();
|
|
|
|
LadderInfo.Matches.CollectionChanged += (_, args) =>
|
2019-06-14 10:16:20 +00:00
|
|
|
{
|
2020-02-17 06:06:14 +00:00
|
|
|
switch (args.Action)
|
2019-11-11 11:53:22 +00:00
|
|
|
{
|
2020-02-17 06:06:14 +00:00
|
|
|
case NotifyCollectionChangedAction.Add:
|
|
|
|
foreach (var p in args.NewItems.Cast<TournamentMatch>())
|
|
|
|
addMatch(p);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2020-03-04 03:37:42 +00:00
|
|
|
foreach (var p in args.OldItems.Cast<TournamentMatch>())
|
2020-02-17 06:06:14 +00:00
|
|
|
{
|
|
|
|
foreach (var d in MatchesContainer.Where(d => d.Match == p))
|
|
|
|
d.Expire();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2019-11-11 11:53:22 +00:00
|
|
|
}
|
2019-06-14 10:16:20 +00:00
|
|
|
|
|
|
|
layout.Invalidate();
|
|
|
|
};
|
2018-11-16 11:14:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 10:12:29 +00:00
|
|
|
private readonly Cached layout = new Cached();
|
2018-11-16 11:14:34 +00:00
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (!layout.IsValid)
|
|
|
|
UpdateLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 normalPathColour;
|
|
|
|
private Color4 losersPathColour;
|
|
|
|
|
2019-06-14 10:16:20 +00:00
|
|
|
protected virtual bool DrawLoserPaths => false;
|
|
|
|
|
2018-11-16 11:14:34 +00:00
|
|
|
protected virtual void UpdateLayout()
|
|
|
|
{
|
|
|
|
paths.Clear();
|
|
|
|
headings.Clear();
|
|
|
|
|
|
|
|
int id = 1;
|
2019-05-15 03:08:23 +00:00
|
|
|
|
2019-06-18 05:57:05 +00:00
|
|
|
foreach (var match in MatchesContainer.OrderBy(d => d.Y).ThenBy(d => d.X))
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
match.Match.ID = id++;
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2019-06-18 05:57:05 +00:00
|
|
|
if (match.Match.Progression.Value != null)
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
var dest = MatchesContainer.FirstOrDefault(p => p.Match == match.Match.Progression.Value);
|
2018-11-16 11:14:34 +00:00
|
|
|
|
|
|
|
if (dest == null)
|
|
|
|
// clean up outdated progressions.
|
2019-06-18 05:57:05 +00:00
|
|
|
match.Match.Progression.Value = null;
|
2018-11-16 11:14:34 +00:00
|
|
|
else
|
2019-06-18 05:57:05 +00:00
|
|
|
paths.Add(new ProgressionPath(match, dest) { Colour = match.Match.Losers.Value ? losersPathColour : normalPathColour });
|
2018-11-16 11:14:34 +00:00
|
|
|
}
|
2019-06-14 10:16:20 +00:00
|
|
|
|
|
|
|
if (DrawLoserPaths)
|
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
if (match.Match.LosersProgression.Value != null)
|
2019-06-14 10:16:20 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
var dest = MatchesContainer.FirstOrDefault(p => p.Match == match.Match.LosersProgression.Value);
|
2019-06-14 10:16:20 +00:00
|
|
|
|
|
|
|
if (dest == null)
|
|
|
|
// clean up outdated progressions.
|
2019-06-18 05:57:05 +00:00
|
|
|
match.Match.LosersProgression.Value = null;
|
2019-06-14 10:16:20 +00:00
|
|
|
else
|
2019-06-18 05:57:05 +00:00
|
|
|
paths.Add(new ProgressionPath(match, dest) { Colour = losersPathColour.Opacity(0.1f) });
|
2019-06-14 10:16:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-16 11:14:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 05:44:15 +00:00
|
|
|
foreach (var round in LadderInfo.Rounds)
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
var topMatch = MatchesContainer.Where(p => !p.Match.Losers.Value && p.Match.Round.Value == round).OrderBy(p => p.Y).FirstOrDefault();
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2019-06-18 05:57:05 +00:00
|
|
|
if (topMatch == null) continue;
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2019-06-18 05:44:15 +00:00
|
|
|
headings.Add(new DrawableTournamentRound(round)
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
Position = headings.ToLocalSpace((topMatch.ScreenSpaceDrawQuad.TopLeft + topMatch.ScreenSpaceDrawQuad.TopRight) / 2),
|
2018-11-16 11:14:34 +00:00
|
|
|
Margin = new MarginPadding { Bottom = 10 },
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-18 05:44:15 +00:00
|
|
|
foreach (var round in LadderInfo.Rounds)
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
var topMatch = MatchesContainer.Where(p => p.Match.Losers.Value && p.Match.Round.Value == round).OrderBy(p => p.Y).FirstOrDefault();
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2019-06-18 05:57:05 +00:00
|
|
|
if (topMatch == null) continue;
|
2018-11-16 11:14:34 +00:00
|
|
|
|
2019-06-18 05:44:15 +00:00
|
|
|
headings.Add(new DrawableTournamentRound(round, true)
|
2018-11-16 11:14:34 +00:00
|
|
|
{
|
2019-06-18 05:57:05 +00:00
|
|
|
Position = headings.ToLocalSpace((topMatch.ScreenSpaceDrawQuad.TopLeft + topMatch.ScreenSpaceDrawQuad.TopRight) / 2),
|
2018-11-16 11:14:34 +00:00
|
|
|
Margin = new MarginPadding { Bottom = 10 },
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.Validate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|